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

:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #252525;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-muted: #6b6b6b;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --border: #2a2a2a;
    --user-bubble: #6366f1;
    --assistant-bubble: #252525;
    --success: #22c55e;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

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

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

.sidebar-header {
    margin-bottom: 20px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.logo svg {
    color: var(--accent);
}

.new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 16px;
    background-color: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
    margin-bottom: 16px;
}

.new-chat-btn:hover {
    background-color: var(--accent-hover);
}

/* Conversation List */
.conversation-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
}

.conversation-list::-webkit-scrollbar {
    width: 4px;
}

.conversation-list::-webkit-scrollbar-track {
    background: transparent;
}

.conversation-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    width: 100%;
}

.conversation-item:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.conversation-item.active {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.conversation-item svg.chat-icon {
    flex-shrink: 0;
    opacity: 0.7;
}

.conversation-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.delete-btn {
    opacity: 0;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.conversation-item:hover .delete-btn {
    opacity: 1;
}

.delete-btn:hover {
    color: #ef4444;
    background-color: rgba(239, 68, 68, 0.1);
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 16px;
}

.clear-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

/* Main Chat Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    padding: 0 24px;
    min-height: 0;
}

/* Messages Area */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
    display: flex;
    flex-direction: column;
    gap: 24px;
    min-height: 0;
}

.messages::-webkit-scrollbar {
    width: 6px;
}

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

.messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

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

/* Welcome Message */
.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.welcome-icon {
    margin-bottom: 20px;
    color: var(--accent);
}

.welcome-message h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.welcome-message p {
    color: var(--text-muted);
}

/* Message Styles */
.message {
    display: flex;
    gap: 16px;
    animation: fadeIn 0.3s ease;
}

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

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

.message.user .message-avatar {
    background: linear-gradient(135deg, var(--accent) 0%, #8b5cf6 100%);
}

.message.assistant .message-avatar {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-role {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.message-text {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-secondary);
    word-wrap: break-word;
}

.message-text p {
    margin-bottom: 1em;
}

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

.message.user .message-text {
    color: var(--text-primary);
    white-space: pre-wrap;
}

/* Code blocks */
.code-block {
    margin: 12px 0;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    background-color: #1e1e1e;
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background-color: #2d2d2d;
    border-bottom: 1px solid var(--border);
}

.code-lang {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: lowercase;
}

.copy-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
}

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

.copy-btn.copied {
    color: var(--success);
}

.code-block pre {
    margin: 0;
    padding: 16px;
    overflow-x: auto;
    border: none;
    border-radius: 0;
}

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

.message-text pre code {
    background: none;
    padding: 0;
    font-size: 0.875rem;
    line-height: 1.5;
    color: #e6e6e6;
}

.message-text code {
    background-color: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Fira Code', 'Monaco', 'Consolas', monospace;
    font-size: 0.875em;
    color: #e06c75;
}

/* Math display */
.message-text .katex-display {
    margin: 16px 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px 0;
}

.message-text .katex {
    font-size: 1.1em;
}

.math-error {
    color: #ef4444;
    background-color: rgba(239, 68, 68, 0.1);
    padding: 8px;
    border-radius: 4px;
}

/* Lists */
.message-text ul, .message-text ol {
    margin: 12px 0;
    padding-left: 24px;
}

.message-text li {
    margin: 4px 0;
}

/* Blockquotes */
.message-text blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 16px;
    margin: 12px 0;
    color: var(--text-muted);
}

/* Tables */
.message-text table {
    border-collapse: collapse;
    width: 100%;
    margin: 12px 0;
}

.message-text th, .message-text td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}

.message-text th {
    background-color: var(--bg-tertiary);
}

/* Links */
.message-text a {
    color: var(--accent);
    text-decoration: none;
}

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

/* Horizontal rule */
.message-text hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 16px 0;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

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

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

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

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

/* Input Area */
.input-container {
    padding: 16px 0 24px;
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 8px 12px;
    transition: border-color 0.2s ease;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
}

#message-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.5;
    resize: none;
    max-height: 200px;
    min-height: 24px;
    height: 24px;
    outline: none;
    vertical-align: middle;
}

#message-input::placeholder {
    color: var(--text-muted);
}

.send-btn {
    width: 36px;
    height: 36px;
    background-color: var(--accent);
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    background-color: var(--accent-hover);
    transform: scale(1.05);
}

.send-btn:disabled {
    background-color: var(--bg-tertiary);
    color: var(--text-muted);
    cursor: not-allowed;
}

/* Responsive Design */
@media (max-width: 768px) {
    .sidebar {
        display: none;
    }

    .chat-container {
        padding: 0 16px;
    }

    .message {
        gap: 12px;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
    }
}
