/* ===== AI 聊天助手样式 ===== */

/* 页面基础布局 */
.chatbot-page {
    display: flex;
    height: 100vh;
    overflow: hidden;
    background: var(--bg-light);
}

/* ===== 侧边栏 ===== */
.sidebar {
    width: 280px;
    background: linear-gradient(180deg, #1e3a8a 0%, #4c1d95 100%);
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    z-index: 100;
}

.sidebar.collapsed {
    width: 0;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.new-chat-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    color: var(--white);
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
}

.new-chat-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.sidebar-toggle {
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 10px;
    color: var(--white);
    cursor: pointer;
    transition: var(--transition);
}

.sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* 搜索框 */
.search-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 1rem;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.search-box svg {
    color: rgba(255, 255, 255, 0.6);
    flex-shrink: 0;
}

.search-box input {
    flex: 1;
    background: none;
    border: none;
    color: var(--white);
    font-size: 0.9rem;
    outline: none;
}

.search-box input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

/* 聊天历史 */
.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 1rem;
}

.sidebar-content::-webkit-scrollbar {
    width: 4px;
}

.sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

.history-section {
    padding: 0 1rem;
    margin-top: 1rem;
}

.history-label {
    display: block;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0.5rem 0;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.history-item.active {
    background: rgba(255, 255, 255, 0.15);
    color: var(--white);
}

.history-item .chat-icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
}

.history-item span {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 删除聊天按钮 */
.delete-chat-btn {
    padding: 0.25rem;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.4);
    cursor: pointer;
    border-radius: 4px;
    transition: var(--transition);
    opacity: 0;
    flex-shrink: 0;
}

.history-item:hover .delete-chat-btn {
    opacity: 1;
}

.delete-chat-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #ef4444;
}

/* 侧边栏底部 */
.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-size: 0.9rem;
    transition: var(--transition);
}

.sidebar-link:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--white);
}

/* ===== 主聊天区域 ===== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--white);
}

/* 聊天头部 */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    background: var(--white);
    position: relative;
}

.mobile-menu-btn {
    display: none;
    position: absolute;
    left: 1rem;
    padding: 0.5rem;
    background: none;
    border: none;
    color: var(--text-dark);
    cursor: pointer;
    border-radius: 8px;
    transition: var(--transition);
}

.mobile-menu-btn:hover {
    background: var(--bg-light);
}

/* 展开侧边栏按钮 */
.expand-sidebar-btn {
    position: absolute;
    left: 1rem;
    padding: 0.5rem;
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    border-radius: 8px;
    transition: var(--transition);
    display: none;
}

.expand-sidebar-btn.show {
    display: flex;
}

.expand-sidebar-btn:hover {
    background: var(--bg-light);
    color: var(--text-dark);
}

/* 模型选择器 */
.model-selector {
    position: relative;
}

.model-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: none;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-dark);
    cursor: pointer;
    border-radius: 8px;
    transition: var(--transition);
}

.model-btn:hover {
    background: var(--bg-light);
}

.model-dropdown {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 0.5rem;
    min-width: 200px;
    background: var(--white);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 0.5rem;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
    z-index: 100;
}

.model-dropdown.show {
    opacity: 1;
    visibility: visible;
}

.model-option {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.9rem;
    color: var(--text-dark);
}

.model-option:hover {
    background: var(--bg-light);
}

.model-option.selected {
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.1) 0%, rgba(59, 130, 246, 0.1) 100%);
    color: var(--accent-cyan);
    font-weight: 500;
}

.model-dropdown .divider {
    height: 1px;
    background: rgba(0, 0, 0, 0.08);
    margin: 0.5rem 0;
}

.settings-btn {
    position: absolute;
    right: 1rem;
    padding: 0.5rem;
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    border-radius: 8px;
    transition: var(--transition);
}

.settings-btn:hover {
    background: var(--bg-light);
    color: var(--text-dark);
}

.back-btn {
    position: absolute;
    right: 3.5rem;
    padding: 0.5rem;
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    border-radius: 8px;
    transition: var(--transition);
}

.back-btn:hover {
    background: var(--bg-light);
    color: var(--text-dark);
}

/* ===== 聊天消息区域 ===== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

/* 欢迎界面 */
.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem;
}

.welcome-screen.hidden {
    display: none;
}

.welcome-logo {
    margin-bottom: 2rem;
}

.logo-circle {
    width: 80px;
    height: 80px;
    background: var(--gradient-btn);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white);
    box-shadow: 0 8px 30px rgba(6, 182, 212, 0.3);
}

.welcome-screen h1 {
    font-size: 2rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 2rem;
}

/* 建议卡片 */
.suggestion-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    width: 100%;
    max-width: 600px;
}

.suggestion-card {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    background: var(--bg-light);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 12px;
    cursor: pointer;
    text-align: left;
    transition: var(--transition);
    font-size: 0.9rem;
    color: var(--text-dark);
}

.suggestion-card:hover {
    border-color: var(--accent-cyan);
    background: rgba(6, 182, 212, 0.05);
    box-shadow: var(--shadow-sm);
}

.suggestion-card svg {
    flex-shrink: 0;
    color: var(--accent-cyan);
    margin-top: 2px;
}

/* 消息容器 */
.messages-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

/* 消息气泡 */
.message {
    display: flex;
    gap: 1rem;
    animation: fadeInUp 0.3s ease;
}

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message.assistant .message-avatar {
    background: var(--gradient-btn);
    color: var(--white);
}

.message.user .message-avatar {
    background: linear-gradient(135deg, #4c1d95 0%, #7c3aed 100%);
    color: var(--white);
    font-weight: 600;
    font-size: 0.9rem;
}

.message-content {
    flex: 1;
    max-width: 75%;
}

.message.user .message-content {
    text-align: right;
}

.message-bubble {
    display: inline-block;
    padding: 1rem 1.25rem;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.6;
}

.message.assistant .message-bubble {
    background: var(--bg-light);
    color: var(--text-dark);
    border-bottom-left-radius: 4px;
}

.message.user .message-bubble {
    background: linear-gradient(135deg, #1e3a8a 0%, #4c1d95 100%);
    color: var(--white);
    border-bottom-right-radius: 4px;
}

/* 流式输出光标动画 */
.streaming-cursor {
    display: inline-block;
    color: var(--accent-cyan);
    animation: blink 0.8s infinite;
    font-weight: normal;
    margin-left: 2px;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.message.streaming .message-bubble {
    min-height: 24px;
}

/* 消息操作按钮 */
.message-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    opacity: 0;
    transition: var(--transition);
}

.message:hover .message-actions {
    opacity: 1;
}

.message.user .message-actions {
    justify-content: flex-end;
}

.message-action-btn {
    padding: 0.25rem;
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    border-radius: 4px;
    transition: var(--transition);
}

.message-action-btn:hover {
    background: var(--bg-light);
    color: var(--text-dark);
}

/* 打字指示器 */
.typing-indicator {
    display: flex;
    gap: 0.25rem;
    padding: 1rem 1.25rem;
    background: var(--bg-light);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--accent-cyan);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* ===== 输入区域 ===== */
.chat-input-area {
    padding: 1rem 2rem 1.5rem;
    background: var(--white);
}

.input-container {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--bg-light);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 24px;
    transition: var(--transition);
}

.input-container:focus-within {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.1);
}

.input-container textarea {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-dark);
    resize: none;
    max-height: 200px;
    font-family: inherit;
}

.input-container textarea::placeholder {
    color: var(--text-light);
}

.attach-btn,
.voice-btn,
.send-btn {
    padding: 0.5rem;
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    border-radius: 8px;
    transition: var(--transition);
    flex-shrink: 0;
}

.attach-btn:hover,
.voice-btn:hover {
    color: var(--text-dark);
    background: rgba(0, 0, 0, 0.05);
}

.send-btn {
    background: var(--gradient-btn);
    color: var(--white);
    border-radius: 50%;
    padding: 0.6rem;
    opacity: 0.5;
    cursor: not-allowed;
}

.send-btn:not(:disabled) {
    opacity: 1;
    cursor: pointer;
}

.send-btn:not(:disabled):hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(6, 182, 212, 0.3);
}

.disclaimer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 0.75rem;
}

/* ===== 设置弹窗 ===== */
.settings-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.settings-modal.show {
    opacity: 1;
    visibility: visible;
}

.settings-content {
    width: 90%;
    max-width: 500px;
    background: var(--white);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    transform: translateY(20px);
    transition: var(--transition);
}

.settings-modal.show .settings-content {
    transform: translateY(0);
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.settings-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-dark);
}

.close-settings {
    padding: 0.5rem;
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    border-radius: 8px;
    transition: var(--transition);
}

.close-settings:hover {
    background: var(--bg-light);
    color: var(--text-dark);
}

.settings-body {
    padding: 1.5rem;
}

.setting-group {
    margin-bottom: 1.25rem;
}

.setting-group label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-dark);
    margin-bottom: 0.5rem;
}

.setting-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    font-size: 0.95rem;
    transition: var(--transition);
}

.setting-group input:focus {
    outline: none;
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.1);
}

.save-settings-btn {
    width: 100%;
    padding: 0.875rem;
    background: var(--gradient-btn);
    border: none;
    border-radius: 10px;
    color: var(--white);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.save-settings-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(6, 182, 212, 0.3);
}

/* 使用默认 API Key */
.use-default-group {
    padding: 1rem;
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.08) 0%, rgba(59, 130, 246, 0.08) 100%);
    border-radius: 10px;
    border: 1px solid rgba(6, 182, 212, 0.2);
    margin-bottom: 1.25rem;
}

.use-default-group .checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    user-select: none;
}

.use-default-group input[type="checkbox"] {
    display: none;
}

.use-default-group .checkmark {
    width: 22px;
    height: 22px;
    border: 2px solid var(--accent-cyan);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.use-default-group input[type="checkbox"]:checked + .checkmark {
    background: var(--gradient-btn);
    border-color: transparent;
}

.use-default-group input[type="checkbox"]:checked + .checkmark::after {
    content: '';
    width: 6px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    margin-bottom: 2px;
}

.use-default-group .checkbox-label {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-dark);
}

.setting-hint {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 0.5rem;
    margin-left: 2rem;
}

/* ===== 响应式设计 ===== */
@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        z-index: 200;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .mobile-menu-btn {
        display: flex;
    }

    /* 移动端隐藏展开按钮，使用 mobile-menu-btn */
    .expand-sidebar-btn {
        display: none !important;
    }

    .chat-messages {
        padding: 1.5rem;
    }

    .chat-input-area {
        padding: 1rem 1.5rem;
    }
}

@media (max-width: 768px) {
    .suggestion-cards {
        grid-template-columns: 1fr;
    }

    .welcome-screen h1 {
        font-size: 1.5rem;
    }

    .message-content {
        max-width: 85%;
    }

    .input-container {
        padding: 0.5rem 0.75rem;
    }
}

@media (max-width: 480px) {
    .chat-messages {
        padding: 1rem;
    }

    .chat-input-area {
        padding: 0.75rem 1rem;
    }

    .message-bubble {
        padding: 0.75rem 1rem;
    }

    .welcome-screen {
        padding: 1rem;
    }
}

/* ===== 动画 ===== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 代码块样式 */
.message-bubble pre {
    background: #1e1e1e;
    border-radius: 8px;
    padding: 1rem;
    overflow-x: auto;
    margin: 0.75rem 0;
}

.message-bubble code {
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.875rem;
}

.message-bubble pre code {
    color: #d4d4d4;
}

.message-bubble p code {
    background: rgba(0, 0, 0, 0.08);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-size: 0.875rem;
    color: var(--accent-cyan);
}

/* Markdown 样式 */
.message-bubble h1,
.message-bubble h2,
.message-bubble h3 {
    margin: 1rem 0 0.5rem;
}

.message-bubble h1 {
    font-size: 1.5rem;
}

.message-bubble h2 {
    font-size: 1.25rem;
}

.message-bubble h3 {
    font-size: 1.1rem;
}

.message-bubble ul,
.message-bubble ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.message-bubble li {
    margin: 0.25rem 0;
}

.message-bubble blockquote {
    border-left: 3px solid var(--accent-cyan);
    padding-left: 1rem;
    margin: 0.75rem 0;
    color: var(--text-light);
}

/* 移动端侧边栏遮罩 */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
}

.sidebar-overlay.show {
    display: block;
}
