:root {
    --chat-bg: #f3f4f6;
    --chat-surface: #ffffff;
    --chat-primary: #4f46e5;
    --chat-primary-gradient: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
    --chat-bot-bg: #ffffff;
    --chat-user-text: #ffffff;
    --chat-text: #1f2937;
    --chat-muted: #6b7280;
    --chat-border: #e5e7eb;
    --chat-radius: 18px;
    --chat-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --primary-color: #4f46e5;
}

/* Base Layout overrides */
.chat-layout {
    background-color: var(--chat-bg);
    height: calc(100vh - 140px);
    border: 1px solid var(--chat-border);
}

/* Sidebar */
.chat-sidebar {
    background-color: var(--chat-surface);
    border-right: 1px solid var(--chat-border);
    width: 280px;
    flex-shrink: 0;
}

.session-item {
    border: none !important;
    border-radius: 12px !important;
    margin: 4px 8px;
    padding: 12px 16px !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.session-item:hover {
    background-color: rgba(99, 102, 241, 0.05);
    transform: translateX(4px);
}

.session-item.active {
    background-color: #eef2ff !important;
    color: var(--chat-primary) !important;
    box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.1);
}

.session-item.active .text-muted {
    color: #6366f1 !important;
    /* lighter indigo */
}


/* Main Chat Area */
.chat-main {
    background-color: var(--chat-bg);
    position: relative;
}

.chat-header {
    background-color: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--chat-border);
    z-index: 10;
}

/* Messages */
.message-row {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    align-items: flex-start;
    animation: fadeIn 0.3s ease-up;
}

.message-row.user {
    flex-direction: row-reverse;
}

.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.avatar-bot {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

.avatar-user {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    color: white;
}

.chat-bubble {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: var(--chat-radius);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    position: relative;
    line-height: 1.5;
    font-size: 0.95rem;
}

.bubble-bot {
    background-color: var(--chat-bot-bg);
    color: var(--chat-text);
    border-top-left-radius: 4px;
}

.bubble-user {
    background: var(--chat-primary-gradient);
    color: var(--chat-user-text);
    border-top-right-radius: 4px;
    box-shadow: 0 4px 6px rgba(79, 70, 229, 0.2);
}

/* Markdown Content Styling */
.chat-bubble p:last-child {
    margin-bottom: 0;
}

.chat-bubble ul,
.chat-bubble ol {
    margin-bottom: 0.5rem;
    padding-left: 1.2rem;
}

.chat-bubble code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 4px;
    border-radius: 4px;
    font-size: 0.9em;
}

.bubble-user code {
    color: white;
    background: rgba(255, 255, 255, 0.2);
}

.bubble-bot pre {
    background: #1f2937;
    color: #e5e7eb;
    padding: 10px;
    border-radius: 8px;
    overflow-x: auto;
}

/* Main Chat Area */
.chat-main {
    min-width: 0;
}

/* Wrapper for messages + welcome screen */
.chat-messages-wrapper {
    min-height: 0;
    overflow: hidden;
}

/* Scrollable area for messages */
.chat-scroll-area {
    overflow-y: auto;
    scroll-behavior: smooth;
    padding-bottom: 20px;
}

/* Input Area */
.chat-input-container {
    background: transparent;
    padding: 20px;
    position: relative;
    /* Changed from absolute to flow naturally in flex */
    background: transparent;
    z-index: 20;
    /* Gradient fade to cover scrolling text behind */
    background: linear-gradient(to bottom, rgba(243, 244, 246, 0) 0%, rgba(243, 244, 246, 1) 20%);
}

.chat-input-wrapper {
    background: var(--chat-surface);
    border: 1px solid var(--chat-border);
    border-radius: 24px;
    padding: 8px 8px 8px 16px;
    box-shadow: var(--chat-shadow);
    display: flex;
    align-items: flex-end;
    transition: box-shadow 0.2s, border-color 0.2s;
}

.chat-input-wrapper:focus-within {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    border-color: #c7d2fe;
}

.chat-input {
    border: none;
    background: transparent;
    width: 100%;
    resize: none;
    max-height: 120px;
    min-height: 24px;
    padding: 8px 0;
    outline: none;
    color: var(--chat-text);
    line-height: 1.5;
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--chat-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s, background-color 0.2s;
    margin-left: 8px;
}

.chat-send-btn:hover {
    background-color: #4338ca;
    transform: scale(1.05);
}

.chat-send-btn:disabled {
    background-color: #d1d5db;
    transform: none;
    cursor: not-allowed;
}

/* Welcome Screen */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--chat-muted);
}

.welcome-icon {
    font-size: 3rem;
    color: #d1d5db;
    margin-bottom: 1rem;
}

.suggestion-chip {
    background: white;
    border: 1px solid var(--chat-border);
    padding: 8px 16px;
    border-radius: 999px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    margin: 4px;
}

.suggestion-chip:hover {
    border-color: var(--chat-primary);
    color: var(--chat-primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Typing Indicator */
.typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--chat-bot-bg);
    border-radius: var(--chat-radius);
    border-top-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    width: fit-content;
}

.typing span {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

.typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {

    0%,
    60%,
    100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-4px);
    }
}

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

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

/* Mobile Tweaks */
@media (max-width: 768px) {
    .chat-bubble {
        max-width: 85%;
    }
}