/* --- 全局与主题变量 --- */
:root {
--primary-color: #007bff;
--secondary-color: #f0f8ff;
--background-color: #f4f7f9;
--font-color: #333;
--border-color: #e0e0e0;
--user-msg-bg: #007bff;
--user-msg-font: #ffffff;
--ai-msg-bg: #ffffff;
--ai-msg-font: #333;
--sidebar-bg: #f8f9fa;
--hover-bg: #e9ecef;
--app-max-width: 1400px;
--app-border-radius: 12px;
--overlay-bg: rgba(0, 0, 0, 0.4);
--header-height: 80px; /* 定义头部高度变量 */
}

/* --- 基础重置与布局 --- */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

/* 【修改 1】确保聊天页面占满整个可用空间，考虑头部导航栏 */
.body-container {
display: flex;
justify-content: center;
align-items: stretch;
height: calc(100vh - var(--header-height)); /* 减去头部导航栏高度 */
padding: 0;
}

/* 【修改 2】应用容器高度优化 */
.app-container {
position: relative;
display: flex;
width: 100%;
height: 100%; /* 使用父容器的高度 */
max-width: var(--app-max-width);
border-radius: 0;
box-shadow: none;
overflow: hidden;
background-color: #fff;
}

/* --- 侧边栏 (Prompt 提示与新对话) --- */
.sidebar {
width: 260px;
background-color: var(--sidebar-bg);
border-right: 1px solid var(--border-color);
padding: 20px;
display: flex;
flex-direction: column;
flex-shrink: 0;
transition: transform 0.3s ease-in-out;
}

.sidebar h2 {
font-size: 1.2rem;
color: var(--primary-color);
margin-bottom: 10px;
}

.new-chat-btn {
width: 100%;
padding: 10px;
margin-bottom: 20px;
background-color: var(--primary-color);
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 0.95rem;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
transition: background-color 0.2s;
}
.new-chat-btn:hover {
background-color: #0056b3;
}
.new-chat-btn svg {
width: 18px;
height: 18px;
}

.prompt-list {
flex-grow: 1;
overflow-y: auto;
}
.prompt-list::-webkit-scrollbar { width: 6px; }
.prompt-list::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

.prompt-item {
padding: 12px 15px;
margin-bottom: 10px;
border-radius: 8px;
cursor: pointer;
transition: all 0.2s ease;
font-size: 0.9rem;
border: 1px solid var(--border-color);
background-color: #fff;
}
.prompt-item:hover {
background-color: var(--hover-bg);
border-color: #d0d0d0;
}

/* 选中状态样式 */
.prompt-item.selected {
background-color: var(--primary-color);
color: white;
border-color: var(--primary-color);
}

/* --- 主聊天窗口 --- */
.chat-container {
flex-grow: 1;
display: flex;
flex-direction: column;
background-color: #fff;
min-width: 0;
height: 100%; /* 确保聊天容器占满高度 */
}

.chat-header {
padding: 15px 20px;
border-bottom: 1px solid var(--border-color);
font-weight: bold;
font-size: 1.1rem;
display: flex;
align-items: center;
gap: 15px;
flex-shrink: 0; /* 防止头部被压缩 */
background-color: #fff;
z-index: 10;
}

/* 当前模板显示 */
.current-prompt {
margin-left: auto;
font-size: 0.9rem;
color: #666;
display: flex;
align-items: center;
gap: 5px;
}

#current-prompt-name {
color: var(--primary-color);
font-weight: 600;
}

#menu-toggle {
display: none;
background: none;
border: none;
cursor: pointer;
padding: 5px;
}
#menu-toggle svg {
width: 24px;
height: 24px;
color: var(--font-color);
}

/* 【修改 3】聊天消息区域 - 关键修改 */
.chat-messages {
flex: 1; /* 占据剩余空间 */
padding: 20px;
overflow-y: auto;
scroll-behavior: smooth;
min-height: 0; /* 重要：允许flex子元素缩小 */
}
.chat-messages::-webkit-scrollbar { width: 8px; }
.chat-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

/* --- 消息气泡与操作按钮 --- */
.message-wrapper {
display: flex;
margin-bottom: 10px;
flex-direction: column;
}
.message {
display: flex;
max-width: 80%;
align-items: flex-start;
}

.message .avatar {
width: 40px;
height: 40px;
border-radius: 50%;
margin-right: 15px;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
color: white;
}

.message .content {
padding: 12px 18px;
border-radius: 18px;
line-height: 1.6;
font-size: 0.95rem;
white-space: pre-wrap;
position: relative;
word-break: break-word;
}

.user-message .message { justify-content: flex-end; margin-left: auto; }
.user-message .avatar { margin-left: 15px; margin-right: 0; background-color: #6c757d; }
.user-message .content { background-color: var(--user-msg-bg); color: var(--user-msg-font); border-bottom-right-radius: 4px; }

.ai-message .message { justify-content: flex-start; margin-right: auto; }
.ai-message .avatar { background-color: var(--primary-color); }
.ai-message .content { background-color: var(--ai-msg-bg); color: var(--ai-msg-font); border-bottom-left-radius: 4px; border: 1px solid var(--border-color); }

.message-actions {
display: flex;
align-items: center;
gap: 8px;
margin-top: 8px;
padding-left: 55px;
opacity: 0;
transition: opacity 0.2s ease;
}
.message-wrapper:hover .message-actions {
opacity: 1;
}
.user-message .message-actions {
justify-content: flex-end;
padding-right: 55px;
padding-left: 0;
}

.action-btn {
background: #f1f3f5;
border: 1px solid #dee2e6;
border-radius: 6px;
padding: 4px 8px;
cursor: pointer;
display: flex;
align-items: center;
gap: 5px;
font-size: 0.8rem;
color: #495057;
-webkit-tap-highlight-color: transparent;
}
.action-btn:hover {
background: #e9ecef;
}
.action-btn svg {
width: 14px;
height: 14px;
}

/* 打字动画样式 */
.typing-animation {
display: flex;
align-items: center;
gap: 4px;
padding: 8px 0;
}

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

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

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

/* 【修改 4】输入区域 - 固定在底部 */
.chat-input-area {
flex-shrink: 0; /* 防止被压缩 */
padding: 15px 20px;
border-top: 1px solid var(--border-color);
background-color: #f8f9fa;
display: flex;
align-items: center;
gap: 10px;
}

.input-wrapper {
flex-grow: 1;
position: relative;
}

.chat-input-area textarea {
width: 100%;
padding: 12px 15px;
border: 1px solid var(--border-color);
border-radius: 22px;
resize: none;
max-height: 120px;
font-family: inherit;
font-size: 1rem;
outline: none;
transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input-area textarea:focus {
border-color: var(--primary-color);
box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.2);
}

#send-button {
width: 44px;
height: 44px;
border: none;
background-color: var(--primary-color);
color: white;
border-radius: 50%;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.3s ease;
flex-shrink: 0;
}
#send-button:hover { background-color: #0056b3; }
#send-button:disabled { background-color: #a0a0a0; cursor: not-allowed; }
#send-button svg { width: 24px; height: 24px; transition: transform 0.3s ease; }

#send-button.stop-generating { background-color: #dc3545; }
#send-button.stop-generating:hover { background-color: #c82333; }

/* --- 覆盖层 --- */
.overlay {
display: none;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: var(--overlay-bg);
z-index: 99;
transition: opacity 0.3s ease;
}
.overlay.visible {
display: block;
}

/* --- 响应式设计: 移动端适配 --- */
@media (max-width: 768px) {
:root {
--header-height: 60px; /* 移动端头部高度更小 */
}

.app-container {
height: 100%;
border-radius: 0;
}

#menu-toggle {
display: flex; /* 在移动端显示汉堡菜单 */
}

.sidebar {
position: absolute;
top: 0;
left: 0;
height: 100%;
z-index: 100; /* 确保在覆盖层之上 */
border-right: 1px solid var(--border-color);
transform: translateX(-100%); /* 默认移出屏幕 */
}

.sidebar.visible {
transform: translateX(0); /* 滑入屏幕 */
box-shadow: 4px 0 15px rgba(0,0,0,0.1);
}

.chat-messages {
padding: 15px;
}

.chat-input-area {
padding: 10px 15px;
}

/* 优化触摸友好性 */
.action-btn {
padding: 8px 12px;
}

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

/* 移动端消息操作按钮始终显示 */
@media (max-width: 768px) {
.message-actions {
opacity: 1;
}
}
}