/* 基础样式 */
:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --background-color: #ffffff;
    --sidebar-bg: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --user-msg-bg: #3b82f6;
    --bot-msg-bg: #f1f5f9;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* 暗色主题 */
[data-theme="dark"] {
    --primary-color: #3b82f6;
    --primary-hover: #60a5fa;
    --secondary-color: #94a3b8;
    --background-color: #0f172a;
    --sidebar-bg: #1e293b;
    --card-bg: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --border-color: #334155;
    --bot-msg-bg: #334155;
    --user-msg-bg: #3b82f6;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.5;
    transition: background-color 0.3s, color 0.3s;
    min-height: 100vh;
    overflow: hidden;
}

.container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* 侧边栏样式 */
.sidebar {
    width: 280px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 100;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-new-chat {
    width: 100%;
    padding: 0.75rem 1rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: background-color 0.2s;
}

.btn-new-chat:hover {
    background-color: var(--primary-hover);
}

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

.conversation-item {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: background-color 0.2s;
    font-size: 0.875rem;
}

.conversation-item:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .conversation-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

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

.conversation-item i {
    width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.avatar {
    width: 36px;
    height: 36px;
    background-color: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.user-details {
    display: flex;
    flex-direction: column;
}

.username {
    font-weight: 500;
    font-size: 0.875rem;
}

.user-email {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.btn-settings {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-md);
    transition: background-color 0.2s;
}

.btn-settings:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

/* 主内容区域 */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--background-color);
    z-index: 10;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.btn-menu {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-md);
    font-size: 1.25rem;
}

.chat-title h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.thread-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

.thread-id {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-family: 'Monaco', 'Courier New', monospace;
    background: rgba(0, 0, 0, 0.05);
    padding: 0.125rem 0.5rem;
    border-radius: var(--radius-sm);
}

[data-theme="dark"] .thread-id {
    background: rgba(255, 255, 255, 0.1);
}

.btn-copy-thread {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-clear, .btn-dark-mode {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background-color 0.2s;
}

.btn-clear:hover, .btn-dark-mode:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

[data-theme="dark"] .btn-clear:hover,
[data-theme="dark"] .btn-dark-mode:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.btn-text {
    display: inline;
}

/* 聊天容器 */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    scroll-behavior: smooth;
}

.welcome-message {
    text-align: center;
    padding: 3rem 1rem;
    max-width: 600px;
    margin: 0 auto;
}

.welcome-icon {
    font-size: 3rem;
    color: var(--primary-color);
    margin-bottom: 1.5rem;
}

.welcome-message h2 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--primary-color), #7c3aed);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-message p {
    color: var(--text-secondary);
    font-size: 1.125rem;
    margin-bottom: 2rem;
}

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin: 2rem 0;
}

.feature {
    background: var(--card-bg);
    padding: 1rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    flex-direction: column;
    gap: 0.5rem;
    transition: transform 0.2s, box-shadow 0.2s;
}

.feature:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.feature i {
    font-size: 1.5rem;
    color: var(--primary-color);
}

.quick-questions {
    margin-top: 2rem;
}

.quick-questions h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.question-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.question-chip {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 2rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.question-chip:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-1px);
}

/* 消息样式 */
.message {
    display: flex;
    gap: 1rem;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

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

.avatar-container {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.avatar-bot, .avatar-user {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 600;
}

.avatar-bot {
    background: linear-gradient(135deg, #8b5cf6, #3b82f6);
    color: white;
}

.avatar-user {
    background: linear-gradient(135deg, #10b981, #3b82f6);
    color: white;
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-text {
    background-color: var(--bot-msg-bg);
    padding: 1rem 1.25rem;
    border-radius: var(--radius-lg);
    border-top-left-radius: 0.25rem;
    font-size: 1rem;
    line-height: 1.6;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message.user .message-text {
    background-color: var(--user-msg-bg);
    color: white;
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: 0.25rem;
}

.message-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.message-role {
    font-weight: 600;
    font-size: 0.875rem;
}

.message-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
    opacity: 0.8;
}

.message-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s;
}

.message:hover .message-actions {
    opacity: 1;
}

.btn-action {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.btn-action:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 1rem 1.25rem;
    background-color: var(--bot-msg-bg);
    border-radius: var(--radius-lg);
    width: fit-content;
    border-top-left-radius: 0.25rem;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background-color: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

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

@keyframes typing {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* 输入区域 */
.input-container {
    border-top: 1px solid var(--border-color);
    background-color: var(--background-color);
    padding: 1rem 1.5rem;
}

.chat-form {
    max-width: 800px;
    margin: 0 auto;
}

.input-wrapper {
    position: relative;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background-color: var(--card-bg);
    padding: 0.75rem 1rem;
    display: flex;
    align-items: flex-end;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea#messageInput {
    flex: 1;
    border: none;
    background: none;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 1rem;
    line-height: 1.5;
    resize: none;
    min-height: 24px;
    max-height: 120px;
    padding: 0.25rem 0;
    outline: none;
}

textarea#messageInput::placeholder {
    color: var(--text-secondary);
}

.input-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: 1rem;
}

.btn-attach, .btn-voice, .btn-send {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-md);
    font-size: 1.125rem;
    transition: background-color 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-send {
    background-color: var(--primary-color);
    color: white;
    width: 40px;
    height: 40px;
}

.btn-send:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-attach:hover, .btn-voice:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.75rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.model-badge {
    background-color: rgba(37, 99, 235, 0.1);
    color: var(--primary-color);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.hint {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* 模态框 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background-color: var(--background-color);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalFadeIn 0.3s ease;
}

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

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-md);
    font-size: 1.25rem;
}

.modal-body {
    padding: 1.5rem;
}

.setting-group {
    margin-bottom: 2rem;
}

.setting-group h4 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.setting-item {
    margin-bottom: 1.25rem;
}

.setting-item label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.setting-control {
    display: flex;
    gap: 0.5rem;
}

.setting-control input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--card-bg);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.875rem;
}

.setting-control input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.btn-small {
    padding: 0.5rem 1rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.75rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-small:hover {
    background-color: var(--primary-hover);
}

.theme-switch, .font-size-control {
    display: flex;
    gap: 0.5rem;
}

.theme-option, .font-size-btn {
    flex: 1;
    padding: 0.5rem 1rem;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.theme-option:hover, .font-size-btn:hover {
    border-color: var(--primary-color);
}

.theme-option.active, .font-size-btn.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.about-info p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

/* Toast消息 */
.toast {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    background-color: var(--card-bg);
    color: var(--text-primary);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: none;
    align-items: center;
    gap: 0.75rem;
    z-index: 1001;
    max-width: 350px;
    animation: toastSlideIn 0.3s ease;
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.toast.show {
    display: flex;
}

/* 加载动画 */
.loading-spinner {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1002;
}

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

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 1s linear infinite;
}

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

/* 侧边栏遮罩（移动端） */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100%;
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .sidebar-overlay.show {
        display: block;
    }

    .btn-menu {
        display: block;
    }

    .btn-text {
        display: none;
    }

    .header-right {
        gap: 0.25rem;
    }

    .chat-header {
        padding: 0.75rem 1rem;
    }

    .chat-container {
        padding: 1rem;
    }

    .input-container {
        padding: 0.75rem 1rem;
    }

    .input-wrapper {
        padding: 0.5rem 0.75rem;
    }

    .message {
        max-width: 100%;
    }

    .avatar-container {
        width: 32px;
        height: 32px;
    }

    .welcome-message {
        padding: 2rem 0.5rem;
    }

    .welcome-message h2 {
        font-size: 1.5rem;
    }

    .features {
        grid-template-columns: 1fr 1fr;
    }

    .question-chips {
        justify-content: flex-start;
    }

    .question-chip {
        font-size: 0.75rem;
        padding: 0.375rem 0.75rem;
    }

    .message-text {
        font-size: 0.9375rem;
        padding: 0.75rem 1rem;
    }
}

@media (max-width: 480px) {
    .features {
        grid-template-columns: 1fr;
    }

    .chat-title h1 {
        font-size: 1.125rem;
    }

    .thread-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }
}

/* 字体大小控制 */
[data-font-size="small"] {
    font-size: 14px;
}

[data-font-size="small"] .message-text {
    font-size: 13px;
}

[data-font-size="medium"] {
    font-size: 16px;
}

[data-font-size="large"] {
    font-size: 18px;
}

[data-font-size="large"] .message-text {
    font-size: 17px;
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: #475569;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}