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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #f5f7fa;
    color: #1a1a2e;
    line-height: 1.6;
}

/* Flash Messages */
.flash-messages {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.flash {
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: slideDown 0.3s ease;
}

.flash-success { background: #d4edda; color: #155724; }
.flash-error { background: #f8d7da; color: #721c24; }
.flash-warning { background: #fff3cd; color: #856404; }

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Auth Pages */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.auth-card {
    background: white;
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.auth-header h1 {
    font-size: 28px;
    margin-bottom: 8px;
    color: #1a1a2e;
}

.auth-header p {
    color: #6b7280;
    font-size: 14px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 14px;
    font-weight: 500;
    color: #374151;
}

.form-group input,
.form-group textarea {
    padding: 12px 16px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-hint {
    font-size: 12px;
    color: #9ca3af;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #f3f4f6;
    color: #374151;
}

.btn-secondary:hover {
    background: #e5e7eb;
}

.btn-block {
    width: 100%;
}

.auth-footer {
    text-align: center;
    margin-top: 24px;
    font-size: 14px;
    color: #6b7280;
}

.auth-footer a {
    color: #667eea;
    text-decoration: none;
    font-weight: 500;
}

/* Settings Page */
.settings-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.top-nav {
    background: white;
    border-bottom: 1px solid #e5e7eb;
    padding: 0 24px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-brand {
    font-size: 18px;
    font-weight: 600;
    color: #1a1a2e;
    text-decoration: none;
}

.nav-right {
    display: flex;
    gap: 24px;
}

.nav-link {
    color: #6b7280;
    text-decoration: none;
    font-size: 14px;
    padding: 8px 0;
    border-bottom: 2px solid transparent;
}

.nav-link.active,
.nav-link:hover {
    color: #667eea;
    border-bottom-color: #667eea;
}

.settings-content {
    flex: 1;
    padding: 40px 24px;
    max-width: 700px;
    margin: 0 auto;
    width: 100%;
}

.settings-card {
    background: white;
    border-radius: 12px;
    padding: 32px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.settings-card h2 {
    font-size: 22px;
    margin-bottom: 8px;
}

.settings-desc {
    color: #6b7280;
    font-size: 14px;
    margin-bottom: 28px;
}

#config-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 8px;
}

.test-result {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    display: none;
}

.test-result.success {
    display: block;
    background: #d4edda;
    color: #155724;
}

.test-result.error {
    display: block;
    background: #f8d7da;
    color: #721c24;
}

.help-section {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid #e5e7eb;
}

.help-section h3 {
    font-size: 16px;
    margin-bottom: 16px;
}

.help-section ol {
    padding-left: 20px;
    color: #4b5563;
    font-size: 14px;
    line-height: 2;
}

.help-section a {
    color: #667eea;
    text-decoration: none;
}

/* Chat Page */
.chat-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    width: 260px;
    background: #1a1a2e;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.btn-new-chat {
    width: 100%;
    padding: 12px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.btn-new-chat:hover {
    background: rgba(255,255,255,0.15);
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conversation-item {
    padding: 10px 12px;
    color: rgba(255,255,255,0.8);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
    transition: background 0.2s;
}

.conversation-item:hover {
    background: rgba(255,255,255,0.1);
}

.conversation-item.active {
    background: rgba(102, 126, 234, 0.3);
}

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

.conv-delete {
    background: none;
    border: none;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    font-size: 18px;
    padding: 0 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

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

.conv-delete:hover {
    color: #ef4444;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-link {
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    font-size: 14px;
    padding: 8px 12px;
    border-radius: 6px;
    transition: background 0.2s;
}

.sidebar-link:hover {
    background: rgba(255,255,255,0.1);
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f5f7fa;
    min-width: 0;
}

.chat-header {
    height: 60px;
    background: white;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
}

.chat-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
}

.no-config-prompt {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.prompt-card {
    background: white;
    padding: 48px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    max-width: 450px;
}

.prompt-card h3 {
    font-size: 22px;
    margin-bottom: 12px;
}

.prompt-card p {
    color: #6b7280;
    margin-bottom: 24px;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.welcome-screen {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
}

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

.welcome-screen h2 {
    font-size: 24px;
    margin-bottom: 8px;
    color: #6b7280;
}

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

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

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

.message.assistant .message-avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.message.user .message-avatar {
    background: #e5e7eb;
}

.message-bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.6;
    word-wrap: break-word;
}

.message.assistant .message-bubble {
    background: white;
    border-top-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.message.user .message-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-top-right-radius: 4px;
}

.message-bubble p {
    margin-bottom: 8px;
}

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

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

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

.typing-cursor {
    display: inline-block;
    width: 2px;
    height: 16px;
    background: #667eea;
    margin-left: 2px;
    animation: blink 1s infinite;
    vertical-align: text-bottom;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.input-area {
    padding: 16px 24px 24px;
    background: white;
    border-top: 1px solid #e5e7eb;
}

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

#message-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    font-size: 14px;
    resize: none;
    max-height: 200px;
    font-family: inherit;
    line-height: 1.5;
}

#message-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.btn-send {
    padding: 12px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    height: 44px;
    transition: transform 0.2s;
}

.btn-send:hover:not(:disabled) {
    transform: translateY(-1px);
}

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

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        bottom: 0;
        z-index: 100;
        transition: left 0.3s;
    }
    
    .sidebar.open {
        left: 0;
    }
    
    .menu-toggle {
        display: block;
    }
    
    .message-bubble {
        max-width: 85%;
    }
    
    .settings-content {
        padding: 20px 16px;
    }
    
    .settings-card {
        padding: 24px 20px;
    }
}
/* 上传按钮样式 */
.upload-buttons {
    display: flex;
    gap: 8px;
    padding: 0 8px;
    align-items: center;
}

.upload-btn {
    cursor: pointer;
    font-size: 20px;
    padding: 6px 10px;
    border-radius: 8px;
    transition: background 0.2s;
    user-select: none;
}

.upload-btn:hover {
    background: rgba(139, 92, 246, 0.1);
}

/* 图片预览 */
.image-preview {
    position: relative;
    display: inline-block;
    margin-bottom: 10px;
    margin-left: 12px;
}

.image-preview img {
    max-width: 150px;
    max-height: 150px;
    border-radius: 10px;
    border: 2px solid #e5e7eb;
}

.remove-image {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #ef4444;
    color: white;
    border: none;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 消息里的图片 */
.message-content img.chat-image {
    max-width: 300px;
    border-radius: 10px;
    margin-top: 8px;
    cursor: pointer;
}