:root {
    --primary: #2563eb;
    --warn: #f59e0b;
    --error: #ef4444;
    --dark: #1e293b;
    --light: #ffffff;
    --gray: #f1f5f9;
    --gray-border: #e2e8f0;
    --gray-background: #f8fafc;
    --text-secondary: #64748b;
    --sidebar-width: 250px;
    --sidebar-collapsed: 60px;
}

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

body {
    font-family: system-ui, -apple-system, sans-serif;
    background-color: var(--gray);
    color: var(--dark);
    min-height: 100vh;
}

.app-container {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    height: 100vh;
    transition: grid-template-columns 0.3s ease;
}

.app-container.collapsed {
    grid-template-columns: var(--sidebar-collapsed) 1fr;
}

/* Sidebar Styles */
.sidebar {
    background: var(--light);
    border-right: 1px solid var(--gray-border);
    overflow-x: hidden;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.sidebar-header {
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.collapsed .sidebar-header {
    padding: 16px 8px;
    justify-content: center;
}

.menu-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    color: var(--dark);
    transition: background 0.2s;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.menu-toggle:hover {
    background: var(--gray);
}

.sidebar-title {
    font-size: 24px;
    white-space: nowrap;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.collapsed .sidebar-title {
    opacity: 0;
    pointer-events: none;
    display: none;
}

.sidebar-divider {
    height: 1px;
    background: var(--gray-border);
    margin: 0 16px;
}

.collapsed .sidebar-divider {
    margin: 0 8px;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}


.section-title {
    font-size: 14px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
    white-space: nowrap;
    opacity: 1;
    transition: opacity 0.3s ease;
    padding: 0 16px;
    padding-top: 16px;
}

.collapsed .section-title {
    opacity: 0;
    display: none;
    padding: 0 8px;
}

.chat-list {
    opacity: 1;
    transition: opacity 0.3s ease;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0 16px;
}

.collapsed .chat-list {
    opacity: 0;
    display: none;
    padding: 0 8px;
}

/* Main Content */
.main-content {
    background: var(--gray-background);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Chat Container */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    margin: 0 auto;
}

/* Messages Area */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.welcome-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
}

.welcome-state h2 {
    font-size: 28px;
    color: var(--text-secondary);
    font-weight: 300;
    margin-bottom: 12px;
}

.welcome-state p {
    color: var(--text-secondary);
    font-size: 16px;
}

/* Messages List */
.messages-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px 0;
}

/* Message Styles */
.message {
    display: flex;
    flex-direction: column;
    max-width: 70%;
    animation: fadeIn 0.3s ease;
}

.user-message {
    align-self: flex-end;
    align-items: flex-end;
}

.ai-message {
    align-self: flex-start;
    align-items: flex-start;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    white-space: pre-wrap;
    line-height: 1.5;
}

.user-message .message-bubble {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-message .message-bubble {
    background: white;
    color: var(--dark);
    border: 1px solid var(--gray-border);
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
    padding: 0 4px;
}

/* Input Area */
.input-area {
    border-top: 1px solid var(--gray-border);
    background: white;
    padding: 16px 20px;
}

.input-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.message-input {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid var(--gray-border);
    border-radius: 24px;
    resize: none;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.5;
    outline: none;
    transition: border-color 0.2s;
    max-height: 120px;
    overflow-y: auto;
}

.message-input:focus {
    border-color: var(--primary);
}

.message-input:disabled {
    background: var(--gray);
    cursor: not-allowed;
}

.send-button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-button:hover:not(:disabled) {
    background: #1d4ed8;
    transform: scale(1.05);
}

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Loading Indicator */
.loading-indicator {
    display: flex;
    justify-content: center;
    padding: 20px;
}

.spinner {
    width: 30px;
    height: 30px;
    border: 3px solid var(--gray-border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

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

/* Sidebar Create Session Button */
.sidebar-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    width: calc(100% - 32px);
    margin: 8px 16px 16px 16px;
    justify-content: center;
}

.sidebar-btn:hover:not(:disabled) {
    background: #1d4ed8;
}

.sidebar-btn:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-icon {
    flex-shrink: 0;
}

.collapsed .sidebar-btn {
    width: 40px;
    padding: 10px;
    margin: 8px auto 16px auto;
}

.collapsed .sidebar-btn span {
    display: none;
}

/* Loading Bar */
.loading-bar {
    height: 3px;
    background: linear-gradient(90deg, var(--primary) 0%, var(--primary) 50%, transparent 50%);
    background-size: 200% 100%;
    animation: loading 1.5s linear infinite;
    margin: 8px 0;
    border-radius: 2px;
    display: none;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Chat List Items */
.chat-item {
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 4px;
}

.chat-item:hover {
    background: var(--gray);
}

.chat-item.active {
    background: var(--primary);
    color: white;
}

.chat-title {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-date {
    font-size: 12px;
    opacity: 0.7;
}

.chat-item.active .chat-date {
    opacity: 0.9;
}

/* Empty and Error Messages */
.empty-message,
.error-message {
    text-align: center;
    padding: 24px;
    color: var(--text-secondary);
    font-size: 14px;
}

.error-message {
    color: var(--error);
}

/* Scrollbar Styling */
.messages-area::-webkit-scrollbar {
    width: 6px;
}

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

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

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

/* Responsive Design */
@media (max-width: 768px) {
    .message {
        max-width: 85%;
    }
    
    .chat-container {
        padding: 0;
    }
    
    .messages-area {
        padding: 16px;
    }
    
    .input-area {
        padding: 12px 16px;
    }
}

@media (max-width: 768px) {
    .app-container {
        grid-template-columns: var(--sidebar-collapsed) 1fr;
    }
    
    .app-container.expanded {
        grid-template-columns: var(--sidebar-width) 1fr;
    }
    
    .sidebar-header {
        padding: 16px 8px;
        justify-content: center;
    }
    
    .expanded .sidebar-header {
        padding: 16px;
        justify-content: flex-start;
    }
    
    .sidebar-title,
    .section-title,
    .chat-list {
        opacity: 0;
        display: none;
    }
    
    .expanded .sidebar-title,
    .expanded .section-title,
    .expanded .chat-list {
        opacity: 1;
        display: block;
    }
}

/* Scrollbar Styling */
.chat-list::-webkit-scrollbar {
    width: 6px;
}

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

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

.chat-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}