/* public/css/style.css --- 最终版：桌面端与移动端响应式设计 */

:root {
  --background-color: #f0f2f5; /* 更柔和、更浅的背景色 */
  --container-background: #ffffff;
  --user-bubble-background: #0b84fe; /* 更亮、更鲜艳的蓝色，灵感来自 iOS 信息气泡 */
  --assistant-bubble-background: #f0f0f0; /* 更柔和的灰色 */
  --text-color-primary: #333333; /* 更深的颜色以提高对比度 */
  --text-color-secondary: #777777; /* 稍深的辅助文本颜色 */
  --text-color-light: #ffffff;
  --border-color: #e0e0e0; /* 更浅、更细致的边框 */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; /* 引入现代字体 */
  --shadow-light: 0 4px 12px rgba(0, 0, 0, 0.05); /* 更轻、更扩散的阴影 */
  --shadow-medium: 0 8px 24px rgba(0, 0, 0, 0.1); /* 标准阴影 */
  --shadow-dropdown: 0 8px 16px rgba(0, 0, 0, 0.15); /* 下拉菜单的阴影 */
}

/* 引入 Google Font for a modern look */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

* {
  box-sizing: border-box;
}

body, html {
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
  background-color: var(--background-color);
  height: 100%;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden; /* 防止在聊天窗口全高时body出现滚动条 */
}

/* --- 桌面端默认样式 --- */
.chat-wrapper {
  width: 100%;
  max-width: 480px; /* 增加最大宽度以提供更宽敞的感觉 */
  height: 90vh; /* 略微增加垂直空间 */
  max-height: 760px; /* 增加最大高度 */
  background-color: var(--container-background);
  border-radius: 20px; /* 略微调整圆角以获得现代感 */
  box-shadow: var(--shadow-medium); /* 使用定义的阴影变量 */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1); /* 更复杂的 cubic-bezier 过渡效果 */
}

.chat-header {
  padding: 18px 24px; /* 调整内边距 */
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  background-color: var(--container-background); /* 确保头部背景为白色 */
  z-index: 10; /* 确保在消息滚动时它保持在上方 */
  
  /* 头部内容布局调整：左侧头像和标题 */
  display: flex;
  justify-content: flex-start; /* 靠左对齐 */
  align-items: center;
}

/* 隐藏原生的 select 元素 */
.hidden-select {
    display: none;
}

/* 顶部标题栏的头像样式 */
.header-avatar {
    width: 36px; /* 头像大小 */
    height: 36px;
    border-radius: 8px; /* 圆角矩形 */
    overflow: hidden; /* 确保图片不溢出 */
    flex-shrink: 0; /* 防止头像被挤压 */
    box-shadow: 0 1px 3px rgba(0,0,0,0.1); /* 细微阴影 */
}

.header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* 确保图片覆盖整个头像区域 */
}

/* 顶部头像和标题组合 (重命名为 header-content-left) */
.header-content-left {
    display: flex; /* 自身也是 Flex 容器 */
    align-items: center;
    gap: 10px; /* 头像与标题之间的间距 */
    /* 靠左对齐，宽度由内容决定 */
    flex-shrink: 0; 
    flex-grow: 0;
    z-index: 1; 
}

.chat-header h1 {
  margin: 0; /* 移除默认外边距 */
  font-size: 18px; /* 略微增大字体大小 */
  font-weight: 600;
  color: var(--text-color-primary);
  letter-spacing: -0.02em; /* 标题的细微字间距 */
}


/* --- 自定义下拉框样式 --- */
.custom-select-wrapper {
    position: relative;
    display: inline-flex; /* 更改为 inline-flex，让其内容flex布局 */
    align-items: center; /* 垂直居中内容 */
    user-select: none; /* 防止文本被选中 */
    z-index: 3; /* 确保下拉菜单在其他元素之上 */
    flex-shrink: 0; /* 防止被挤压 */
    margin-bottom: 10px; /* 与下方输入框的间距 */
    width: fit-content; /* 让其宽度自适应内容 */
}

/* 语言 ICON 样式 */
.lang-icon {
    width: 16px; /* ICON 宽度 */
    height: 16px; /* ICON 高度 */
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0; /* 防止图标被压缩 */
}
.lang-icon svg,
.lang-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain; /* 确保图标完整显示 */
    vertical-align: middle; /* 垂直居中文本 */
    color: var(--text-color-primary); /* 默认图标颜色 */
}


.select-displayed-value {
    background-color: var(--container-background);
    border: 1px solid var(--border-color);
    color: var(--text-color-primary);
    padding: 8px 12px; /* 调整内边距 */
    border-radius: 18px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.2;
    transition: all 0.2s ease-in-out;
    display: flex; /* 自身也是flex，让 ICON、文本和箭头对齐 */
    align-items: center;
    gap: 6px; /* 控制 ICON、文本和箭头之间的间距 */
    white-space: nowrap; /* 防止文本换行，保持按钮单行 */
    width: fit-content; /* 关键：让按钮宽度紧凑适应内容 */
}

.select-displayed-value:hover {
    border-color: var(--user-bubble-background);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08); /* 悬停时添加细微阴影 */
}

.select-displayed-value.active {
    border-color: var(--user-bubble-background);
    box-shadow: 0 0 0 3px rgba(11, 132, 254, 0.2);
}

/* 箭头本身 */
.select-arrow {
    color: var(--text-color-secondary);
    transition: transform 0.2s ease;
    flex-shrink: 0; /* 确保箭头不被压缩 */
}

/* 当下拉框打开时，箭头旋转 */
.select-displayed-value.active .select-arrow {
    transform: rotate(180deg);
}


.select-options-list {
    list-style: none; /* 移除列表点 */
    padding: 8px 0; /* 内部内边距 */
    margin: 0;
    position: absolute;
    bottom: calc(100% + 5px); /* 定位到自定义下拉框上方，并留出5px间距 */
    left: 0;
    width: max-content; /* 让下拉列表宽度由最长内容决定 */
    min-width: 100%; /* 确保下拉列表至少与触发器同宽 */
    background-color: var(--container-background);
    border: 1px solid var(--border-color);
    border-radius: 12px; /* 圆角 */
    box-shadow: var(--shadow-dropdown); /* 漂亮的阴影 */
    overflow: hidden; /* 确保圆角效果和内部滚动内容不溢出 */
    
    /* 初始隐藏动画属性：从下方-10px处出现 */
    opacity: 0;
    transform: translateY(10px); /* 初始位置略微下移，向上运动的起点 */
    pointer-events: none; /* 隐藏时禁止鼠标事件，防止点击到下方元素 */
    transition: opacity 0.3s ease-out, transform 0.3s ease-out; /* 过渡动画 */
    
    max-height: 200px; /* 限制高度，可滚动 */
    overflow-y: auto; /* 允许垂直滚动 */
}

.select-options-list.show {
    opacity: 1; /* 显示时完全不透明 */
    transform: translateY(0); /* 移动到正常位置 */
    pointer-events: auto; /* 显示时允许鼠标事件 */
}

/* 下拉列表选项，不包含 ICON，只包含文本 */
.select-options-list li {
    padding: 10px 15px; /* 选项内边距 */
    color: var(--text-color-primary);
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
    white-space: nowrap; /* 防止选项文字换行 */
    /* 确保文本靠左 */
    text-align: left; /* 仅针对 li 内部文本 */
}

.select-options-list li:hover {
    background-color: var(--assistant-bubble-background); /* 悬停背景色 */
}

.select-options-list li.selected {
    background-color: var(--user-bubble-background); /* 选中项背景色 */
    color: var(--text-color-light); /* 选中项文字颜色 */
    font-weight: 500;
}


/* --- 其他现有样式保持不变 --- */
.chat-container {
  flex-grow: 1;
  padding: 20px 24px; /* 调整内边距 */
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px; /* 略微增加消息之间的间距 */
  scroll-behavior: smooth; /* 新消息平滑滚动 */
}

/* 彻底移除聊天消息中的头像相关样式，以确保不再显示 */
.message-item, .message-avatar {
    display: none !important; 
}


.message {
  padding: 12px 18px; /* 调整内边距 */
  border-radius: 22px; /* 更圆润的消息气泡 */
  max-width: 80%; /* 消息的宽度 */
  line-height: 1.6; /* 改善行高以提高可读性 */
  word-wrap: break-word;
  font-size: 15px; /* 略微调整字体大小 */
  animation: fadeIn 0.3s ease-out; /* 消息的淡入动画 */
  box-shadow: 0 1px 2px rgba(0,0,0,0.05); /* 消息上的细微阴影 */
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-user {
  background-color: var(--user-bubble-background);
  color: var(--text-color-light);
  align-self: flex-end;
  border-bottom-right-radius: 8px;
}

.message-assistant {
  background-color: var(--assistant-bubble-background);
  color: var(--text-color-primary);
  align-self: flex-start;
  border-bottom-left-radius: 8px;
  /* 调整助手消息的最大宽度，不再考虑头像 */
  max-width: 80%; 
}

/* Markdown 样式增强 */
.message-assistant p { margin: 0 0 10px; } /* 增加段落外边距 */
.message-assistant p:last-child { margin-bottom: 0; }
.message-assistant ul, .message-assistant ol { padding-left: 25px; margin: 10px 0; } /* 增加列表的内边距和外边距 */
.message-assistant li { margin-bottom: 6px; } /* 增加列表项的外边距 */
.message-assistant strong { font-weight: 700; color: var(--text-color-primary); } /* 更粗的粗体 */
.message-assistant h1, .message-assistant h2, .message-assistant h3 {
    margin: 15px 0 10px; font-weight: 700; line-height: 1.4; color: var(--text-color-primary);
}
.message-assistant h1 { font-size: 1.3em; border-bottom: 1px solid var(--border-color); padding-bottom: 5px; } /* 为 h1 添加细微的下边框 */
.message-assistant h2 { font-size: 1.2em; }
.message-assistant h3 { font-size: 1.1em; }
.message-assistant pre {
  background-color: #e8e8e8; /* 代码块背景 */
  padding: 10px 15px;
  border-radius: 8px;
  overflow-x: auto;
  font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace; /* 代码的等宽字体 */
  font-size: 14px;
}
.message-assistant code {
  background-color: #e8e8e8; /* 行内代码背景 */
  padding: 2px 5px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
  font-size: 0.9em;
}

.message-error {
  color: #d93025;
  background-color: #fce8e6;
  font-weight: 500; /* 错误信息略微加粗 */
  border: 1px solid #d93025; /* 错误信息的红色边框 */
}

.chat-footer {
  padding: 12px 20px; /* 调整内边距 */
  border-top: 1px solid var(--border-color);
  background-color: var(--container-background);
  flex-shrink: 0;
  box-shadow: var(--shadow-light); /* 底部细微阴影 */
  
  /* 底部内容布局：垂直排列 */
  display: flex;
  flex-direction: column;
}

/* 新增：底部输入区域的容器 */
.footer-input-area {
    width: 100%; /* 占据底部所有可用宽度 */
    display: flex;
    flex-direction: column; /* 内部元素垂直堆叠 */
    align-items: flex-start; /* 内部元素靠左对齐 */
}


.chat-form {
  display: flex;
  align-items: center;
  gap: 12px; /* 调整间距 */
  width: 100%; /* 占据父容器所有宽度 */
}

#message-input {
  flex-grow: 1; padding: 12px 20px; border: 1px solid var(--border-color);
  background-color: var(--assistant-bubble-background);
  border-radius: 24px; font-size: 16px; color: var(--text-color-primary);
  outline: none;
  transition: all 0.2s ease-in-out;
}
#message-input:focus {
  border-color: var(--user-bubble-background); background-color: var(--container-background);
  box-shadow: 0 0 0 3px rgba(11, 132, 254, 0.2);
}

#send-button {
  background: var(--user-bubble-background); border: none; padding: 10px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--text-color-light); border-radius: 50%;
  transition: all 0.2s ease-in-out;
  box-shadow: 0 2px 6px rgba(11, 132, 254, 0.3);
}
#send-button:hover {
  background-color: #086adf; transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(11, 132, 254, 0.4);
}
#send-button:active {
  transform: translateY(0); box-shadow: 0 1px 3px rgba(11, 132, 254, 0.2);
}
#send-button svg { width: 20px; height: 20px; fill: currentColor; }

/* 滚动条样式以获得更简洁的外观 */
.chat-container::-webkit-scrollbar { width: 8px; }
.chat-container::-webkit-scrollbar-track { background: var(--background-color); border-radius: 4px; }
.chat-container::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.15); border-radius: 4px;
  transition: background-color 0.2s ease;
}
.chat-container::-webkit-scrollbar-thumb:hover { background-color: rgba(0, 0, 0, 0.3); }

/* ================================================================= */
/*                      移动端响应式样式 (核心)                      */
/* ================================================================= */
@media (max-width: 768px) {
  body, html { align-items: flex-start; }
  .chat-wrapper { height: 100%; max-height: 100%; width: 100%; max-width: 100%; border-radius: 0; box-shadow: none; }
  .chat-header { padding-top: calc(18px + env(safe-area-inset-top)); padding-left: 20px; padding-right: 20px; }
  .chat-footer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); padding-left: 20px; padding-right: 20px; }
  .chat-container { padding: 15px 18px; gap: 10px; }
  .message { padding: 10px 15px; font-size: 14.5px; }
  .message-assistant { max-width: 90%; }
  #message-input { padding: 10px 16px; font-size: 15px; }
  #send-button { padding: 9px; }
  #send-button svg { width: 18px; height: 18px; }

  /* 移动端自定义下拉框调整 */
  .custom-select-wrapper { width: 100%; align-self: flex-start; } /* 确保在移动端也靠左 */
  .select-displayed-value { padding: 7px 10px; font-size: 13px; }
  .select-arrow { width: 14px; height: 14px; }
  .select-options-list li { padding: 8px 12px; font-size: 13px; }
}