/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f7f7f8;
    color: #1f1f1f;
    height: 100vh;
    overflow: hidden;
}

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

/* Sidebar Styles */
.sidebar {
    width: 320px;
    background: #f7f7f8;
    border-right: 1px solid #e5e5e7;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid #e5e5e7;
}

.app-title {
    font-size: 24px;
    font-weight: 700;
    color: #1f1f1f;
    margin-bottom: 4px;
}

.app-subtitle {
    font-size: 14px;
    color: #666;
    font-weight: 400;
}

.api-key-section {
    padding: 20px;
    border-bottom: 1px solid #e5e5e7;
}

.api-key-section h3 {
    font-size: 16px;
    font-weight: 600;
    color: #1f1f1f;
    margin-bottom: 16px;
}

.api-key-input-area {
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
}

.api-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    font-size: 14px;
}

.status-dot {
    font-size: 12px;
}

.api-key-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

#apiKeyInput {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    padding: 8px 12px;
    font-size: 14px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
}

#apiKeyInput:focus {
    outline: none;
    border-color: #10a37f;
}

.api-key-btn {
    background: #10a37f;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
}

.api-key-btn:hover {
    background: #0d8f6c;
}

.api-key-btn:disabled {
    background: #d1d5db;
    cursor: not-allowed;
}

.api-key-toggle {
    margin-top: 8px;
}

.toggle-btn {
    background: none;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
}

.toggle-btn:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.api-key-help {
    font-size: 12px;
    color: #666;
    margin: 0;
    font-style: italic;
}

.knowledge-base {
    padding: 20px;
    border-bottom: 1px solid #e5e5e7;
}

.knowledge-base h3,
.chat-history h3 {
    font-size: 16px;
    font-weight: 600;
    color: #1f1f1f;
    margin-bottom: 16px;
}

.file-upload-area {
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    padding: 24px;
    text-align: center;
    background: #fff;
    transition: all 0.2s ease;
    cursor: pointer;
}

.file-upload-area:hover {
    border-color: #10a37f;
    background: #f0fdf4;
}

.file-upload-area.dragover {
    border-color: #10a37f;
    background: #f0fdf4;
    transform: scale(1.02);
}

.upload-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.file-upload-area p {
    font-size: 14px;
    color: #666;
    margin-bottom: 12px;
}

.upload-btn {
    background: #10a37f;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
}

.upload-btn:hover {
    background: #0d8f6c;
}

.uploaded-files {
    margin-top: 16px;
}

.file-item {
    background: #fff;
    border: 1px solid #e5e5e7;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.file-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.file-icon {
    font-size: 16px;
}

.file-name {
    font-size: 14px;
    font-weight: 500;
    color: #1f1f1f;
}

.file-size {
    font-size: 12px;
    color: #666;
}

.file-remove {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.file-remove:hover {
    background: #fef2f2;
}

.chat-history {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
}

.conversation-list {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 16px;
}

.conversation-item {
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s ease;
    margin-bottom: 4px;
}

.conversation-item:hover {
    background: #f3f4f6;
}

.conversation-item.active {
    background: #e6f3ff;
    border: 1px solid #10a37f;
}

.conversation-title {
    font-size: 14px;
    font-weight: 500;
    color: #1f1f1f;
    display: block;
    margin-bottom: 2px;
}

.conversation-time {
    font-size: 12px;
    color: #666;
}

.new-chat-btn {
    width: 100%;
    background: #fff;
    border: 1px solid #d1d5db;
    color: #374151;
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.new-chat-btn:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

/* Main Content Styles */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
}

.chat-header {
    padding: 20px 24px;
    border-bottom: 1px solid #e5e5e7;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: #1f1f1f;
}

.chat-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #666;
}

.status-indicator {
    font-size: 12px;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.welcome-message {
    text-align: center;
    max-width: 600px;
    margin: auto;
    padding: 40px 20px;
}

.welcome-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.welcome-message h3 {
    font-size: 24px;
    font-weight: 600;
    color: #1f1f1f;
    margin-bottom: 12px;
}

.welcome-message p {
    font-size: 16px;
    color: #666;
    line-height: 1.5;
    margin-bottom: 32px;
}

.example-questions {
    text-align: left;
}

.example-questions h4 {
    font-size: 16px;
    font-weight: 500;
    color: #1f1f1f;
    margin-bottom: 12px;
}

.example-item {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    color: #475569;
}

.example-item:hover {
    background: #e2e8f0;
    border-color: #cbd5e1;
    color: #334155;
}

.message {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

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

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: #10a37f;
    color: white;
}

.message.assistant .message-avatar {
    background: #f3f4f6;
    color: #374151;
}

.message-content {
    max-width: 70%;
    background: #f8fafc;
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.5;
}

.message.user .message-content {
    background: #10a37f;
    color: white;
}

.message.assistant .message-content {
    background: #f8fafc;
    color: #1f1f1f;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 16px;
}

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

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

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

.input-container {
    padding: 20px 24px;
    border-top: 1px solid #e5e5e7;
    background: #fff;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    padding: 12px;
    transition: border-color 0.2s ease;
}

.input-wrapper:focus-within {
    border-color: #10a37f;
}

#messageInput {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    max-height: 120px;
    min-height: 20px;
}

.send-btn {
    background: #10a37f;
    color: white;
    border: none;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-btn:hover:not(:disabled) {
    background: #0d8f6c;
}

.send-btn:disabled {
    background: #d1d5db;
    cursor: not-allowed;
}

.input-footer {
    margin-top: 8px;
    text-align: center;
}

.input-footer small {
    color: #9ca3af;
    font-size: 12px;
}

/* Loading Modal */
.loading-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-modal.show {
    display: flex;
}

.loading-content {
    background: #fff;
    border-radius: 12px;
    padding: 32px;
    text-align: center;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #f3f4f6;
    border-top: 3px solid #10a37f;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-content p {
    font-size: 14px;
    color: #666;
    margin: 0;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: absolute;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .main-content {
        width: 100%;
    }
    
    .message-content {
        max-width: 85%;
    }
}

/* Error states */
.error-message {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #dc2626;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 16px;
}

.success-message {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #16a34a;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 16px;
}

/* Code blocks */
pre {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 12px;
    overflow-x: auto;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    font-size: 13px;
    margin: 8px 0;
}

code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    font-size: 13px;
}