:root {
    --primary-color: #2563eb;
    --secondary-color: #1e40af;
    --background-color: #f8fafc;
    --chat-bg: #ffffff;
    --sidebar-bg: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --selected-bg: #e0e7ff;
    --selected-border: #818cf8;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
    background: var(--background-color);
    color: var(--text-primary);
    line-height: 1.5;
}

/* Login Form */
.login-container {
    max-width: 400px;
    margin: 80px auto;
    padding: 2rem;
    background: var(--chat-bg);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.login-container h2 {
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    font-size: 1.5rem;
}

.login-container input[type="text"],
.login-container input[type="password"] {
    width: 100%;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.875rem;
}

/* Chat Layout */
.chat-container {
    display: flex;
    height: 100vh;
    background: var(--chat-bg);
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--sidebar-bg);
    padding: 1.25rem;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.sidebar button {
    width: 100%;
    padding: 0.875rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.1);
}

.sidebar button:hover {
    background: var(--secondary-color);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(37, 99, 235, 0.15);
}

.session-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1rem;
    margin: 0.25rem 0;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    position: relative;
}

.session-item.selected {
    background: var(--selected-bg);
    border-color: var(--selected-border);
    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.1);
}

.session-item.selected::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--selected-border);
    border-radius: 3px 0 0 3px;
}

.session-item:hover:not(.selected) {
    background: #f8fafc;
    border-color: var(--border-color);
    transform: translateX(2px);
}

.session-item span {
    flex: 1;
    font-size: 0.875rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-item .delete-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 0.5rem;
    opacity: 0;
    transition: all 0.2s ease;
}

.session-item:hover .delete-btn {
    opacity: 1;
}

.session-item .delete-btn:hover {
    background: #fee2e2;
    color: #dc2626;
    transform: none;
    box-shadow: none;
}

/* Add session groups */
.session-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.session-group-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    padding: 0 0.5rem;
    margin-top: 1rem;
}

/* Main Chat Area */
.main-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: calc(100% - 260px);
}

.chat-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header select {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.875rem;
}

.messages {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    font-size: 0.875rem;
}

.message.user {
    align-self: flex-end;
    background: var(--primary-color);
    color: white;
}

.message.bot {
    align-self: flex-start;
    background: var(--sidebar-bg);
    color: var(--text-primary);
}

/* Message Markdown Styles */
.message p {
    margin: 0 0 0.5rem;
}

.message p:last-child {
    margin-bottom: 0;
}

.message code {
    background: rgba(0, 0, 0, 0.1);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.9em;
}

.message pre {
    background: rgba(0, 0, 0, 0.1);
    padding: 0.5rem;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.5rem 0;
}

.message pre code {
    background: none;
    padding: 0;
}

.message a {
    color: inherit;
    text-decoration: underline;
}

.message ul, .message ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.message blockquote {
    border-left: 3px solid rgba(0, 0, 0, 0.2);
    margin: 0.5rem 0;
    padding-left: 1rem;
}

.message img {
    max-width: 100%;
    border-radius: 4px;
    margin: 0.5rem 0;
}

/* Adjust colors for user messages */
.message.user code {
    background: rgba(255, 255, 255, 0.2);
}

.message.user pre {
    background: rgba(255, 255, 255, 0.1);
}

.message.user blockquote {
    border-left-color: rgba(255, 255, 255, 0.3);
}

/* Input Area */
.input-area {
    padding: 1.25rem;
    border-top: 1px solid var(--border-color);
    background: white;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.message-input-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    margin-bottom: 0.75rem;
}

.input-area textarea {
    flex: 1;
    padding: 0.875rem 1.25rem;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 0.9375rem;
    line-height: 1.5;
    resize: none;
    min-height: 44px;
    max-height: 200px;
    transition: all 0.2s ease;
    font-family: inherit;
    background: var(--background-color);
}

.input-area textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    background: white;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.1);
}

.send-button {
    padding: 0.875rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 100px;
    height: 44px;
    align-self: flex-end;
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.1);
}

.send-button:hover {
    background: var(--secondary-color);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(37, 99, 235, 0.15);
}

/* File Upload Refinements */
.file-upload-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
}

.file-upload-container input[type="file"] {
    display: none;
}

.file-upload-container label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.file-upload-container label:hover {
    background: white;
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.upload-progress {
    flex: 1;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--primary-color);
    transition: width 0.3s ease;
}

.selected-file {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    padding: 0.375rem 0.75rem;
    background: var(--background-color);
    border-radius: 6px;
    max-width: fit-content;
}

/* Responsive Design */
@media (max-width: 768px) {
    .chat-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
    }
    
    .main-chat {
        max-width: 100%;
    }
}
