.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow-y: auto;
    max-height: 100vh;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding-right: 10px;
    position: relative;
    z-index: 1;
    padding-bottom: 20px;
    height: auto;
    max-height: 100vh;
    padding-top: 20px; /* Add this line */
}

.message-container {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    width: 100%; 
    max-width: 700px; /* max width of messages */
    padding-left: 40px;
    opacity: 0;
    transform: translateY(20px);
    animation: messageIn 0.3s ease forwards;
    margin: 0 auto;
}

.message-container:not(.chained) {
    padding-left: 0;
}

.message-container.chained {
    margin-top: -8px;
    animation-delay: 0.15s;
}

.message-container.received {
    align-self: flex-start;
}

.message {
    padding: 12px 16px;
    border-radius: 12px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    border-top-left-radius: 0;
}

.message.received {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-top-left-radius: 0;
}

.message-container.chained .message.received {
    border-top-left-radius: 12px;
}

.message-avatar {
    width: 32px;
    height: 32px;
    background: #666;
    border-radius: 6px;
    flex-shrink: 0;
    background-size: cover;
    background-position: center;
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message-sender {
    font-size: 14px;
    font-weight: 500;
    color: #ffffff;
}

.message-text {
    line-height: 1.5;
    color: #ffffff;
    margin-bottom: 12px;
}

.message-text:last-child {
    margin-bottom: 0;
}

.message-text h1,
.message-text h2,
.message-text h3,
.message-text h4,
.message-text h5,
.message-text h6 {
    margin: 16px 0 8px 0;
    color: #ffffff;
}

.message-text h1:first-child,
.message-text h2:first-child,
.message-text h3:first-child {
    margin-top: 0;
}

.message-text p {
    margin: 8px 0;
}

.message-text p:first-child {
    margin-top: 0;
}

.message-text p:last-child {
    margin-bottom: 0;
}

.message-text code {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    padding: 2px 4px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

.message-text pre {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
}

.message-text pre code {
    background: transparent;
    padding: 0;
    border-radius: 0;
}

.message-text ul,
.message-text ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message-text blockquote {
    border-left: 4px solid #60a5fa;
    margin: 8px 0;
    padding: 4px 12px;
    background: rgba(96, 165, 250, 0.1);
}

.message-text a {
    color: #60a5fa;
    text-decoration: none;
}

.message-text a:hover {
    text-decoration: underline;
}

.memory-container {
    background: rgba(96, 165, 250, 0.1);
    border: 1px solid #60a5fa;
    border-radius: 8px;
    padding: 12px;
    margin-top: 8px;
    display: flex;
    gap: 8px;
    align-items: center;
}

.memory-icon {
    width: 16px;
    height: 16px;
    color: #60a5fa;
}

.memory-text {
    color: #60a5fa;
    font-size: 14px;
}

.search-container {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    padding: 12px;
    margin-top: 12px;
}

.search-query {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #1e1e1e;
    border-radius: 4px;
    padding: 8px 12px;
}

.search-icon {
    width: 16px;
    height: 16px;
    color: #60a5fa;
}

.search-text {
    color: #fff;
    font-family: monospace;
    font-size: 13px;
}

.search-status {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #60a5fa;
    font-size: 13px;
    margin-top: 12px;
}

.refresh-icon {
    width: 14px;
    height: 14px;
    animation: spin 1s linear infinite;
}

.search-results {
    margin-top: 12px;
    color: #e0e0e0;
    font-size: 14px;
    line-height: 1.6;
}

/* Hide sources section */
.sources {
    display: none;
}

.source-button {
    background: #1e1e1e;
    border: 1px solid #3e3e3e;
    border-radius: 16px;
    padding: 6px 12px;
    font-size: 12px;
    color: #60a5fa;
    text-decoration: none;
    transition: all 0.2s ease;
}

.source-button:hover {
    background: #3e3e3e;
    border-color: #60a5fa;
}

.code-execution {
    background: #2e2e2e;
    border-radius: 8px;
    padding: 8px 12px;
    margin-top: 8px;
}

.execution-header {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #60a5fa;
    font-size: 14px;
    margin: 0;
}

.execution-status {
    display: flex;
    align-items: center;
    gap: 6px;
}

.execution-status::before {
    content: "</>";
    font-family: monospace;
    font-weight: 500;
}

.output {
    background: #1e1e1e;
    border-radius: 6px;
    padding: 12px;
    font-family: monospace;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    margin-top: 8px;
    color: #e0e0e0;
}

.output.error {
    color: #f87171;
}

.execution-header.success {
    color: #4ade80;
}

.execution-header.error {
    color: #f87171;
}

.loading-dots {
    display: inline-flex;
    gap: 4px;
    margin-left: 4px;
}

.loading-dots span {
    width: 4px;
    height: 4px;
    background: currentColor;
    border-radius: 50%;
    animation: dotPulse 1.4s infinite ease-in-out;
}

.loading-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.loading-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes spin {
    100% { transform: rotate(360deg); }
}

@keyframes dotPulse {
    0%, 80%, 100% { 
        transform: scale(0);
        opacity: 0.5;
    }
    40% { 
        transform: scale(1);
        opacity: 1;
    }
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #4a4a4a;
    border-radius: 4px;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
        filter: blur(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0);
    }
}

.loading-history {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    flex-direction: column;
    gap: 10px;
}

.loading-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid #f3f4f6;
    border-radius: 50%;
    border-top-color: #60a5fa;
    animation: spin 1s linear infinite;
}

.loading-text {
    color: #6b7280;
    font-size: 0.875rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 768px) {
    .message-container {
        max-width: 90%;
    }

    .search-container {
        max-width: 100%;
        overflow-x: auto;
    }

    .sources {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 8px;
    }

    .source-button {
        flex-shrink: 0;
    }
}