/* style.css */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* 防止移动端输入框自动放大 */
input[type="text"],
input[type="search"],
input[type="tel"],
input[type="url"],
input[type="email"],
input[type="password"],
textarea {
    font-size: 16px !important; /* iOS Safari 默认会放大小于16px的输入框 */
    -webkit-appearance: none;
    border-radius: 0;
}

/* 防止页面缩放影响布局 */
@media screen and (max-width: 768px) {
    html {
        touch-action: manipulation; /* 防止双击缩放 */
    }
    
    /* 确保输入区域在键盘弹出时不被遮挡 */
    .chat-input-container {
        position: relative;
        z-index: 10;
    }
}

/* 添加居中容器 */
.app-container {
    display: flex;
    width: 100%;
    max-width: 1400px; /* 整体最大宽度 */
    margin: 0 auto;
    height: 100vh;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1); /* 可选：添加阴影 */
}

/* 修改现有的 .main-container */
.main-container {
    display: flex;
    flex: 1;
    height: 100%;
}

/* 侧边栏样式调整 */
.sidebar {
    width: 280px; /* 稍微调整宽度 */
    background-color: #f8f9fa;
    border-right: 1px solid #e5e5e6;
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* 移动端侧边栏切换按钮 */
.sidebar-toggle {
    background: none; /* 改为透明背景 */
    color: #6b7280; /* 使用和刷新按钮相同的颜色 */
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 4px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.sidebar-toggle:hover {
    color: #3b82f6; /* 悬停颜色和刷新按钮一致 */
    background-color: #f3f4f6; /* 悬停背景色和刷新按钮一致 */
}

.sidebar-toggle svg {
    display: block;
    width: 20px;
    height: 20px;
}

/* 移动端遮罩层 */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

/* 聊天容器调整 */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #fff;
    min-width: 0; /* 防止flex item溢出 */
}

/* 响应式调整 */
@media (max-width: 1200px) {
    .app-container {
        max-width: 100%;
        margin: 0;
    }
}
/* 响应式调整 - 移动端 */
@media (max-width: 768px) {
    .chat-input {
        font-size: 16px; /* 确保移动端输入框字体大小 */
    }
    
    .remove-chat-btn {
        opacity: 1; /* 在移动端始终显示删除按钮 */
    }
    
    .remove-chat-btn.confirm-mode {
        width: 45px;
    }
    /* 调整聊天头部的刷新按钮位置，避免重叠 */
    .chat-header {
        padding-right: 60px; /* 为两个按钮留出空间 */
    }
    
    .refresh-button {
        right: 50px; /* 刷新按钮向左移动，给切换按钮腾出空间 */
    }
    
    .chat-history-item {
        padding: 10px 12px;
        gap: 6px;
    }
    .sidebar {
        width: 280px;
        position: fixed;
        left: -300px;
        top: 0;
        bottom: 0;
        transition: left 0.3s ease;
        z-index: 1000;
        height: 100vh;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    }
    
    .sidebar:not(.open) {
        visibility: hidden; /* 完全隐藏，避免任何可能的显示 */
    }
    .sidebar.open {
        left: 0;
        visibility: visible; /* 展开时显示 */
    }
    
    .sidebar-overlay.open {
        display: block;
    }
    
    /* 当侧边栏打开时，隐藏切换按钮 */
    .sidebar.open ~ .sidebar-toggle {
        display: none !important;
    }
    
    /* 确保侧边栏关闭时显示按钮 */
    .sidebar:not(.open) ~ .sidebar-toggle {
        display: flex !important;
    }

    
    .sidebar-toggle {
        display: flex; /* 在移动端显示 */
    }
    
    .chat-container {
        width: 100%;
    }
    .chat-messages {
        padding: 12px;
    }
    
    .message {
        margin-bottom: 10px;
        max-width: 90%;
    }
    
    .user-message, .bot-message {
        padding: 8px 12px;
    }
    
    /* 确保在移动端侧边栏打开时，主内容区域不可滚动 */
    body.sidebar-open {
        overflow: hidden;
    }
}

/* 桌面端样式 - 确保侧边栏正常显示 */
@media (min-width: 769px) {
    .sidebar {
        position: static; /* 重置为静态定位 */
        left: auto;
        width: 280px;
        display: flex !important; /* 确保显示 */
    }
    
    .sidebar-toggle {
        display: none !important; /* 在桌面端强制隐藏 */
    }
    
    .sidebar-overlay {
        display: none !important; /* 在桌面端强制隐藏遮罩层 */
    }
    
    /* 恢复桌面端的刷新按钮位置 */
    .refresh-button {
        right: 15px;
    }
    
    .chat-header {
        padding-right: 20px;
    }
}

/* 确保 body 样式正确 */
body {
    background-color: #f7f7f8;
    color: #333;
    line-height: 1.6;
    margin: 0;
    padding: 0;
    overflow: hidden; /* 防止整体滚动 */
}

.chat-container {
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    height: 100vh;
    background-color: #fff;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.chat-header {
    position: sticky; /* 改为粘性定位 */
    top: 0; /* 固定在顶部 */
    z-index: 100; /* 确保在其他元素之上 */
    padding: 0 16px;
    background-color: #fff;
    border-bottom: 1px solid #e5e5e6;
    font-weight: bold;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 40px; /* 设置最小高度 */
}

.chat-header-center {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
}

.chat-logo {
    height: 20px; /* 根据你的Logo调整合适的高度 */
    width: auto; /* 保持原始宽高比 */
    vertical-align: middle; /* 垂直对齐 */
    margin-right: 6px; /* 间距 */
}

@media (max-width: 480px) {
    .chat-logo {
        height: 24px;
    }
    .chat-header {
        font-size: 16px;
    }
}

.refresh-button {
    background: none;
    border: none;
    cursor: pointer;
    color: #6b7280;
    padding: 3px;
    border-radius: 50%;
    transition: all 0.2s;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.refresh-button:hover {
    color: #3b82f6;
    background-color: #f3f4f6;
}

.refresh-button svg {
    display: block;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background-color: #f7f7f8;
}

.message {
    margin-bottom: 20px;
    max-width: 85%;
    min-width: 20%;
    width: fit-content;
    word-wrap: break-word;
}

.user-message {
    margin-left: auto;
    background-color: #5068f4;
    color: white;
    border-radius: 18px 18px 4px 18px;
    padding: 12px 16px;
}

.bot-message {
    position: relative;
    margin-right: auto;
    background-color: #fff;
    border: 1px solid #e5e5e6;
    border-radius: 18px 18px 18px 4px;
    padding: 12px 16px;
    margin-left: 35px; /* 为头像留出空间 */
}

.bot-avatar {
    position: absolute;
    left: -40px; /* 将头像定位到消息左侧 */
    top: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.chat-input-container {
    padding: 10px 12px;
    background-color: #fff;
    border-top: 1px solid #e5e5e6;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.chat-input {
    flex: 1;
    border: 1px solid #e5e5e6;
    border-radius: 16px;
    padding: 6px 10px; /* 调整输入框内边距 */
    min-height: 36px; /* 调整最小高度 */
    resize: none;
    outline: none;
    font-size: 16px; /* 移动端使用16px防止自动放大 */
    max-height: 200px;
    line-height: 1.3;
}

.chat-input:focus {
    border-color: #5068f4;
}

.send-button {
    background-color: #5068f4;
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
    flex-shrink: 0; /* 防止在弹性布局中被压缩 */
}

.send-button:hover {
    background-color: #2563eb;
}

.send-button:disabled {
    background-color: #9ca3af;
    cursor: not-allowed;
}

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

.typing-dot {
    width: 8px;
    height: 8px;
    background-color: #9ca3af;
    border-radius: 50%;
    animation: typing-animation 1.4s infinite ease-in-out;
}

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

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

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

@keyframes typing-animation {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-5px);
    }
}

.copy-button {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    font-size: 12px;
    margin-left: 10px;
    padding: 2px 6px;
    border-radius: 4px;
}

.copy-button:hover {
    background-color: #f3f4f6;
}

.message-header {
    display: none;
    
}

.message-content {
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.1 !important;
    font-size: 12px !important;
    /* 确保内容区本身没有多余间距 */
    margin: 0 !important;
    padding: 0 !important;
}

/* 侧边栏布局 */
.main-container {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 300px;
    background-color: #f8f9fa;
    border-right: 1px solid #e5e5e6;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-container {
    flex: 1;
    max-width: none;
    margin: 0;
    box-shadow: none;
}

/* 侧边栏头部 */
.sidebar-header {
    padding: 12px 16px;
    border-bottom: 1px solid #e5e5e6;
    background-color: #fff;
}

.sidebar-title {
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 10px;
}

.new-chat-btn {
    width: 100%;
    padding: 8px;
    background-color: #5068f4;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: background-color 0.2s;
}

.new-chat-btn:hover {
    background-color: #2563eb;
}

/* 对话历史列表 */
.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
}

/* 会话历史项布局调整 */
.chat-history-item {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.2s;
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
}

.chat-history-content {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-width: 0;
    margin-right: 8px; /* 增加右边距 */
    /* 确保可以点击 */
    pointer-events: auto;
    cursor: pointer;
}

/* 删除按钮样式 */
.remove-chat-btn {
    /* 确保删除按钮有自己的点击区域 */
    pointer-events: auto;
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    font-size: 14px;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    opacity: 0;
    position: relative;
    overflow: hidden;
}

.chat-history-item:hover {
    background-color: #e9ecef;
    color: white;
}

.chat-history-item:hover .remove-chat-btn {
    opacity: 1;
}

.remove-chat-btn:hover {
    background-color: #2563eb;
    color: white;
}

/* 删除图标和确认文字 */
.delete-icon, .confirm-text {
    transition: all 0.2s;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    white-space: nowrap;
}

.confirm-text {
    opacity: 0;
    font-size: 12px;
    font-weight: 500;
}

/* 确认模式样式 */
.remove-chat-btn.confirm-mode {
    background-color: #ff4757 !important;
    color: white !important;
    width: 50px; /* 变宽一些显示"确认" */
}

.remove-chat-btn.confirm-mode .delete-icon {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5);
}

.remove-chat-btn.confirm-mode .confirm-text {
    opacity: 1;
}

/* 确认模式下的会话项样式 */
.chat-history-item.delete-confirming {
    background-color: #fff5f5 !important;
    border-left: 3px solid #ff4757 !important;
}

.chat-history-item.active {
    background-color: #e3f2fd;
    border-left: 3px solid #5068f4;
}

.chat-preview {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #666;
    margin-right: 10px;
    font-size: 12px;
}

.chat-date {
    font-size: 12px;
    color: #999;
    flex-shrink: 0;
}

/* Markdown 样式 - 极致紧凑的布局 */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin: 0.2em 0 0.05em 0 !important;
    line-height: 1.1 !important;
    font-weight: bold;
}

.message-content h1 { font-size: 1.35em; }
.message-content h2 { font-size: 1.25em; }
.message-content h3 { font-size: 1.15em; }
.message-content h4 { font-size: 1.05em; }

.message-content p {
    margin: 0 !important; /* 完全移除段落默认间距 */
    line-height: 1.2 !important;
}

/* 确保连续的 p 标签紧密排列 */
.message-content p + p {
    margin-top: 0 !important; /* 连续段落之间无额外间距 */
}

.message-content ul,
.message-content ol {
    margin: 0.1em 0 !important;
    padding-left: 0.9em !important;
}

.message-content li {
    margin: 0 !important;
    line-height: 1.1 !important;
}

.message-content code {
    background-color: #f1f3f4;
    padding: 0.05em 0.25em;
    border-radius: 2px;
    font-family: 'Courier New', monospace;
    font-size: 0.8em;
}

.message-content pre {
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 3px;
    overflow-x: auto;
    margin: 0.2em 0 !important;
    padding: 0.25em !important;
    line-height: 1.25 !important;
    font-size: 0.85em;
}

.message-content pre code {
    background: none;
    padding: 0;
    font-size: 1em;
    line-height: 1.1;
}

.message-content blockquote {
    border-left: 2px solid #5068f4;
    color: #666;
    font-style: italic;
    margin: 0.2em 0 !important;
    padding-left: 0.4em !important;
    line-height: 1.1 !important;
    font-size: 0.9em;
}

.message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.2em 0;
}

.message-content th,
.message-content td {
    border: 1px solid #ddd;
    padding: 0.15em 0.25em;
    text-align: left;
    font-size: 0.85em;
}

.message-content th {
    background-color: #f8f9fa;
    font-weight: bold;
}

.message-content strong {
    font-weight: bold;
}

.message-content em {
    font-style: italic;
}

/* 针对嵌套元素的极致紧凑间距 */
.message-content ul ul,
.message-content ol ol,
.message-content ul ol,
.message-content ol ul {
    margin: 0 !important;
}

/* 特别针对连续段落的优化 */
.message-content > p {
    margin: 0 !important;
}

/* 对于非第一个段落，添加较小的上边距 */
.message-content > p + p {
    margin-top: 0.025em !important;
}

/* 优化换行符的显示 */
.message-content br {
    line-height: 0.4 !important;
}

/* 减少所有相邻块级元素的间距 */
.message-content > * + * {
    margin-top: 0.025em !important;
}

/* 进一步优化代码块间距 */
.message-content code {
    font-size: 0.8em;
    padding: 0.1em 0.3em;
    margin: 0 0.1em;
}

.message-content pre {
    margin: 0.3em 0 !important;
    padding: 0.4em !important;
}

.message-content pre code {
    font-size: 0.85em;
    line-height: 1.3;
    display: block;
    padding: 0 !important;
    margin: 0 !important;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background-color: #f7f7f8;
    max-width: 100%;
}

.message {
    margin-bottom: 15px;
    max-width: 80%; /* 限制消息气泡宽度 */
    min-width: 10%;
    width: fit-content;
    word-wrap: break-word;
}

/* 在大屏幕上居中聊天内容 */
@media (min-width: 1400px) {
    .app-container {
        max-width: 1400px; /* 增加最大宽度 */
    }
    
    .sidebar {
        width: 320px; /* 侧边栏稍微宽一些 */
    }
    
    .chat-container {
        max-width: none; /* 移除聊天容器最大宽度限制 */
    }
    
    .chat-messages {
        padding: 20px 100px; /* 增加左右内边距，让内容更集中 */
    }
}