/*
 * AI Chat Assistant Stylesheet - Split Component Version
 * This CSS is designed for a theme that loads sidebar and main content separately.
 */

/* --- 1. 侧边栏样式 --- */
/* 让侧边栏填满主题分配给它的空间 */
.chat-sidebar {
    height: 100%;
    max-height: 80vh; /* 限制一个最大高度，防止过高 */
    background: #fdfdfd;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    box-sizing: border-box; /* 确保 padding 不会增加宽度 */
}
.chat-sidebar .sidebar-header,
.chat-sidebar .sidebar-footer {
    flex-shrink: 0;
}
.chat-sidebar .chat-history {
    flex-grow: 1;
    overflow-y: auto;
    margin: 1rem 0;
}
/* (侧边栏内部其他样式保持不变) */
.chat-sidebar .chat-history h3 { font-size: 0.9rem; color: #6c757d; margin: 0 0 0.5rem; padding-bottom: 0.5rem; border-bottom: 1px solid #e9ecef; }
.chat-sidebar .history-loading, .chat-sidebar .history-empty { color: #6c757d; font-style: italic; padding: 1rem 0; }
.chat-sidebar #aiHistoryList ul { list-style: none; padding: 0; margin: 0; }
.chat-sidebar .history-item { padding: 0.6rem 0.8rem; margin-bottom: 0.5rem; border-radius: 6px; cursor: pointer; transition: background-color 0.2s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.9rem; }
.chat-sidebar .history-item:hover { background-color: #f0f2f5; }
.chat-sidebar .sidebar-button { display: flex; align-items: center; gap: 0.75rem; width: 100%; padding: 0.75rem; border: 1px solid #ced4da; border-radius: 8px; background-color: #fff; font-size: 1rem; cursor: pointer; transition: all 0.2s; text-align: left; }
.chat-sidebar .sidebar-button:hover { background-color: #f8f9fa; border-color: #adb5bd; }
.chat-sidebar .sidebar-button.danger:hover { background-color: #fbebeb; color: #dc3545; border-color: #f5c6cb; }


/* --- 2. 主聊天区样式 --- */
/* 让主聊天区填满主题的 #main 区域 */
.chat-main {
    height: 100%;
    max-height: 80vh; /* 同样限制最大高度 */
    display: flex;
    flex-direction: column;
    background: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    overflow: hidden;
}
.chat-main .chat-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid #e0e0e0; background: #fff; text-align: center; flex-shrink: 0; }
.chat-main .chat-header h1 { margin: 0; font-size: 1.4rem; }
.chat-main .chat-header p { margin: 0.25rem 0 0; color: #6c757d; font-size: 0.9rem; }
.chat-main .chat-messages { flex-grow: 1; overflow-y: auto; padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.chat-main .chat-input-area { padding: 1rem 1.5rem; border-top: 1px solid #e0e0e0; background: #fff; flex-shrink: 0; }
.chat-main .chat-input-area {
    padding: 1rem 1.5rem;
    border-top: 1px solid #e0e0e0;
    background: #fff;
    flex-shrink: 0;
    display: flex; /* 使输入区域成为flex容器 */
    flex-direction: column; /* 默认垂直堆叠 */
    gap: 0.75rem; /* 元素之间的间距 */
}

/* --- 模型选择器样式 --- */
.chat-main .control-wrapper{
    display: flex;
}

.chat-main .model-selector-wrapper {
    width: 100%;
    display: flex;
    justify-content: flex-end; /* 让选择器靠右对齐 */
}

.chat-main .model-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid #ced4da;
    border-radius: 8px;
    background-color: #f1f3f5;
    font-size: 0.9rem;
    color: #343a40;
    cursor: pointer;
    appearance: none; /* 移除默认的系统样式 */
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%20viewBox%3D%220%200%20292.4%22%3E%3Cpath%20fill%3D%22%23007bff%22%20d%3D%22M287%20197.3L159.9%2069.8c-4.8-4.8-12.5-4.8-17.3%200L5.4%20197.3c-3.6%203.6-5.4%208.4-5.4%2013.3%200%204.9%201.8%209.7%205.4%2013.3l16.4%2016.4c4.8%204.8%2012.5%204.8%2017.3%200l118-118.7L253.3%20240c4.8%204.8%2012.5%204.8%2017.3%200l16.4-16.4c3.6-3.6%205.4-8.4%205.4-13.3.1-4.9-1.7-9.7-5.3-13.3z%22%2F%3E%3C%2Fsvg%3E'); /* 自定义下拉箭头 */
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 0.8em;
    min-width: 150px; /* 确保在移动端也有足够宽度 */
}
.chat-main .model-select:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

/* 隐藏屏幕阅读器文本 */
.screen-reader-text {
    clip: rect(1px, 1px, 1px, 1px);
    position: absolute !important;
    height: 1px;
    width: 1px;
    overflow: hidden;
    word-wrap: normal !important;
}
.chat-main .chat-input-form { display: flex; align-items: center; gap: 0.75rem; }
.chat-main #aiMessageInput { flex-grow: 1; padding: 0.75rem 1rem; border-radius: 20px; border: 1px solid #ced4da; background-color: #f1f3f5; font-size: 1rem; resize: none; max-height: 120px; }
.chat-main #aiSendButton {
    /* 保持原来的尺寸和背景色 */
    width: 40px;
    height: 40px;
    border-radius: 50%; /* 保持圆形 */
    border: none;
    background-color: #007bff;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
    flex-shrink: 0;
    
    /* 新增/修改：适应文本 */
    font-size: 0.85rem; /* 调整字体大小以适应 */
    font-weight: bold; /* 让文本更突出 */
    padding: 0; /* 移除默认padding */
    line-height: 1; /* 确保文本垂直居中 */
}
.chat-main #aiSendButton:hover { background-color: #0056b3; }

.chat-main #clearHistoryButton {
    display: flex;
    justify-content: center; /* 让选择器靠右对齐 */
    padding: 0.5rem 0.75rem;
    border: 1px solid #ced4da;
    border-radius: 8px;
    background-color: #98F5F9;
    font-size: 0.9rem;
    color: #343a40;
    cursor: pointer;
    appearance: none; /* 移除默认的系统样式 */
    -webkit-appearance: none;
    -moz-appearance: none;
    
    overflow: hidden;
    min-width: 120px; /* 确保在移动端也有足够宽度 */
    width:100%;
}
.chat-main #clearHistoryButton:hover { background-color: #0056b3; }
        
/* 消息内容容器样式 */
.message-content {
    background: white;
    padding: 2.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    width: 100%;
    overflow-wrap: break-word;
}

/* 标题样式 */
.message-content h1 {
    font-size: 2.2rem;
    color: #1a1a1a;
    margin: 1.8rem 0 1.2rem;
    padding-bottom: 0.6rem;
    border-bottom: 2px solid #eaecef;
    font-weight: 700;
}

.message-content h2 {
    font-size: 1.8rem;
    color: #1f2937;
    margin: 2rem 0 1rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid #eaecef;
    font-weight: 600;
}

.message-content h3 {
    font-size: 1.4rem;
    color: #374151;
    margin: 1.6rem 0 0.8rem;
    font-weight: 600;
}

.message-content h4 {
    font-size: 1.2rem;
    color: #4b5563;
    margin: 1.4rem 0 0.6rem;
    font-weight: 600;
}

/* 段落样式 */
.message-content p {
    margin-bottom: 1.2rem;
    font-size: 1.05rem;
    line-height: 1.7;
}

/* 强调文本样式 */
.message-content strong {
    color: #1a56db;
    font-weight: 700;
}

.message-content em {
    color: #7c3aed;
    font-style: italic;
}

/* 水平分割线 */
.message-content hr {
    height: 1px;
    background: linear-gradient(to right, transparent, #cbd5e1, transparent);
    border: none;
    margin: 2.2rem 0;
}

/* 列表样式 */
.message-content ul, 
.message-content ol {
    margin-bottom: 1.4rem;
    padding-left: 2rem;
}

.message-content li {
    margin-bottom: 0.6rem;
    line-height: 1.6;
}

.message-content ul {
    list-style-type: disc;
}

.message-content ul ul {
    list-style-type: circle;
}

.message-content ul ul ul {
    list-style-type: square;
}

.message-content ol {
    list-style-type: decimal;
}

/* 表格样式 */
.message-content table {
    border-collapse: collapse;
    margin: 1.6rem 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    border-radius: 8px;
    overflow: auto;
}

.message-content th, 
.message-content td {
    padding: 0.85rem 1rem;
    border: 1px solid #e2e8f0;
    text-align: left;
}

.message-content th {
    background-color: #f1f5f9;
    font-weight: 600;
    color: #334155;
}

.message-content tr:nth-child(even) {
    background-color: #f8fafc;
}

.message-content tr:hover {
    background-color: #f1f5f9;
}

/* 代码样式 */
.message-content code {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    background-color: #f1f5f9;
    padding: 0.2em 0.4em;
    border-radius: 4px;
    font-size: 0.9em;
    color: #dc2626;
    border: 1px solid #e2e8f0;
}

.message-content pre {
    background: linear-gradient(to right, #f8fafc, #ffffff);
    padding: 1.2rem;
    border-radius: 8px;
    overflow: auto;
    margin: 1.4rem 0;
    border: 1px solid #e2e8f0;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.05);
}

.message-content pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: 0.95em;
    line-height: 1.5;
    border: none;
    color: #334155;
}

/* 代码块语法高亮 */
.message-content .language-python {
    color: #0f5132;
}

.message-content .language-html {
    color: #055160;
}

/* 引用样式 */
.message-content blockquote {
    margin: 1.4rem 0;
    padding: 1.2rem 1.5rem;
    color: #475569;
    border-left: 4px solid #3b82f6;
    background-color: #f8fafc;
    border-radius: 0 8px 8px 0;
}

.message-content blockquote p {
    margin-bottom: 0.5rem;
}

/* 图片样式 */
.message-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 1.4rem auto;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    border: 1px solid #e2e8f0;
}

/* 链接样式 */
.message-content a {
    color: #2563eb;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.message-content a:hover {
    color: #1d4ed8;
    text-decoration: underline;
}

/* 任务列表样式 */
.message-content li:has(> input[type="checkbox"]) {
    list-style-type: none;
    padding-left: 0;
    margin-left: -1.4rem;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .message-content {
        padding: 1.5rem;
    }
    
    .message-content h1 {
        font-size: 1.8rem;
    }
    
    .message-content h2 {
        font-size: 1.5rem;
    }
    
    .message-content table {
        display: block;
        overflow-x: auto;
    }
}




/* --- 3. 消息体样式 (与之前相同，但加上父级选择器) --- */
.chat-main .message { display: flex; align-items: flex-start; gap: 0.75rem;}
.chat-main .avatar { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.chat-main .ai-avatar { background-color: #d1e7dd; align-self:margin-top;}
.chat-main .user-avatar { background-color: #cce5ff; }
.chat-main .message-body { display: flex; flex-direction: column; }
.chat-main .message-content { padding: 0.75rem 1rem; border-radius: 18px; }
.chat-main .message-content p { margin: 0; white-space: pre-wrap; word-wrap: break-word; }
.chat-main .ai-timestamp { font-size: 0.75rem; color: #6c757d; margin-top: 0.25rem; padding: 0 0.5rem; align-self: flex-start;}
.chat-main .user-timestamp { font-size: 0.75rem; color: #6c757d; margin-top: 0.25rem; padding: 0 0.5rem; align-self: flex-end;}
.chat-main .ai-message { align-self: flex-start; margin-right:40px}
.chat-main .ai-message .message-content { background-color: #e9ecef; border-top-left-radius: 4px; }
.chat-main .user-message { align-self: flex-end; flex-direction: row-reverse;margin-left:40px; }
.chat-main .user-message .message-content { background-color: #007bff; color: #fff; border-top-right-radius: 4px; }
.chat-main .typing-indicator { display: flex; align-items: center; gap: 5px; padding: 5px 0; }
.chat-main .typing-indicator span { width: 8px; height: 8px; background-color: #999; border-radius: 50%; animation: typing 1.2s infinite ease-in-out; }
.chat-main .typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.chat-main .typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1.0); } }

/* --- 4. 响应式布局 --- */
/* 当屏幕变窄时，Bravada主题会自动将侧边栏和主内容区堆叠。我们只需要调整一下高度即可。 */
@media (max-width: 768px) { /* 或者你认为的移动端断点，例如 992px */
    .chat-main{min-height:80vh;}
    .chat-main .chat-header { padding: 0 1.5rem; border-bottom: 1px solid #e0e0e0; background: #fff; text-align: center; flex-shrink: 0; }
    .chat-main .chat-header h1 { margin: 0; font-size: 1.4rem; }
    .chat-main .chat-header p { margin: 0.25rem 0 0; color: #6c757d; font-size: 0.9rem; }
    .chat-main .message .avatar {
        display: none;
    }
    /* 调整消息体的边距，因为头像被隐藏了 */
    .chat-main .message {
        gap: 0; /* 移除头像和消息体之间的间距 */
    }
    .chat-main .message-body {
        margin-left: 0; /* 确保消息体没有额外的左边距 */
    }
    /* 如果需要，可以调整消息的最大宽度，让它占据更多空间 */
    .chat-main .message {
        max-width: 100%; /* 让消息在移动端可以占满更多宽度 */
        margin:0;
    }
    .chat-main .model-select {
        width: 60%; /* 移动端下拉菜单占满宽度 */
        min-width: unset; /* 移除最小宽度限制 */
    }
    .chat-main .model-selector-wrapper {
        justify-content: right; /* 移动端居中显示 */
    }
}
