@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap');

/* ==============================
   变量与基础设置
============================== */
:root {
  --primary-color: #2F3C3E;
  --internal-color: #00008B;
  --accent-color: #00989F;
  --accent-hover: #007a81;
  --reset-bg: #2F3C3E;
  --reset-hover: #1F2B2C;
  --search-color: #4e6ef2;
  --search-bg: rgba(78, 110, 242, 0.1);
  --citation-color: #1a73e8;
  --citation-hover: #0b5cdd;
  
  /* 阴影 */
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 8px rgba(0,0,0,0.15);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.2);
  
  /* 圆角 */
  --radius-sm: 18px;
  --radius-md: 25px;
  --radius-lg: 55px;
  
  /* 过渡 */
  --transition-default: 0.3s ease;
}

/* ==============================
   工具类
============================== */
.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }
.transition-all { 
  transition: box-shadow var(--transition-default), 
              transform var(--transition-default), 
              background-color var(--transition-default), 
              opacity var(--transition-default); 
}
.hidden { display: none !important; }

/* ==============================
   主容器样式
============================== */
.ensight-chat-container {
  width: 97vw;
  height: 96vh; 
  padding: 10px;
  box-sizing: border-box;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  position: relative;
  transform: scale(0.44);
  opacity: 0.9;
  transform-origin: center bottom;
  transition: box-shadow 0.5s ease, transform 0.5s ease, opacity 0.5s ease;
}

.ensight-chat-container:hover {
  box-shadow: 0 6px 18px rgba(0,0,0,0.16);
}

.ensight-chat-container.fully-expanded {
  transform: scale(1);
  opacity: 1;
}

/* ==============================
   消息区域
============================== */
.ensight-messages {
  padding: 10px;
  height: calc(96vh - 200px);
  overflow-y: auto;
  border-radius: var(--radius-md);
  text-align: center;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,0.2) transparent;
}

.ensight-messages::-webkit-scrollbar {
  width: 8px;
}

.ensight-messages::-webkit-scrollbar-thumb {
  background-color: rgba(0,0,0,0.2);
  border-radius: 20px;
}

/* ==============================
   消息样式
============================== */
.message {
  margin: 10px auto;
  padding: 10px;
  line-height: 1.4;
  max-width: 92%;
  text-align: center;
  border-radius: var(--radius-md);
  transform: translateZ(0);
  will-change: opacity;
}

.message span {
  display: inline-block;
  padding: 10px;
  border-radius: var(--radius-sm);
  font-size: 20px;
  box-shadow: var(--shadow-sm);
  transform-origin: center center;
  transition: box-shadow var(--transition-default);
  position: relative;
  overflow: hidden;
  transform: translateZ(0);
  will-change: transform;
  min-height: 20px;
}

/* 用户消息 */
.message.user span {
  background: transparent;
  color: #243830;
  text-align: center;
  box-shadow: none;
  border: none;
}

/* 助手消息 - 修改为居中显示 */
.message.assistant span {
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: var(--primary-color);
  text-align: center;
}

/* 助手消息中的段落 */
.message.assistant span p {
  margin-bottom: 0.8em;
  padding-bottom: 0;
  text-align: center;
}

.message.assistant span p:last-child {
  margin-bottom: 0;
}

/* ==============================
   引用区域
============================== */
.citations-container {
  margin-top: 10px;
  text-align: left;
  font-size: 12px;
  line-height: 1.5;
  max-width: 90%;
  opacity: 0.85;
  transition: opacity var(--transition-default);
  padding: 5px 0;
}

.citations-container:hover {
  opacity: 1;
}

.citations-title {
  font-weight: 600;
  color: var(--primary-color);
  margin-bottom: 5px;
}

.citations-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.citation-link {
  display: inline-block;
  background-color: rgba(255, 255, 255, 0.7);
  border-radius: 12px;
  padding: 3px 8px;
  color: var(--citation-color);
  text-decoration: none;
  transition: all var(--transition-default);
  font-size: 11px;
  max-width: 300px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid rgba(26, 115, 232, 0.2);
}

.citation-link:hover {
  background-color: rgba(255, 255, 255, 0.9);
  color: var(--citation-hover);
  border-color: rgba(26, 115, 232, 0.4);
  box-shadow: var(--shadow-sm);
}

/* 模态框中的引用 */
.modal-citations {
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px solid rgba(0,0,0,0.1);
}

.modal-citations .citations-title {
  font-size: 16px;
  margin-bottom: 8px;
}

.modal-citations .citation-link {
  font-size: 14px;
  max-width: none;
  padding: 4px 10px;
  margin-bottom: 6px;
}

/* ==============================
   可展开消息样式
============================== */
.message.assistant span.expandable {
  cursor: pointer;
  transition: transform var(--transition-default), box-shadow var(--transition-default);
}

.message.assistant span.expandable:hover {
  transform: translateY(-2px) scale(1.01);
  box-shadow: var(--shadow-md);
}

/* 高亮效果 */
.message-highlight {
  position: absolute;
  top: 0;
  left: -100%;
  width: 70%;
  height: 100%;
  background: linear-gradient(90deg, 
    rgba(255,255,255,0) 0%, 
    rgba(255,255,255,0.6) 50%, 
    rgba(255,255,255,0) 100%);
  pointer-events: none;
  z-index: 10;
}

/* ============================== 
   Internet Insight Button with SVG Icon
============================== */
#ensight-web-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f5f5f5;
  color: var(--primary-color);
  padding: 10px 15px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  border: none;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-default);
}

#ensight-web-search:hover {
  background: #e8e8e8;
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

#ensight-web-search.active {
  background: var(--search-color);
  color: white;
}

#ensight-web-search.active:hover {
  background: #3d5bd8;
}

/* SVG Web Icon */
.web-icon-svg {
  width: 20px;
  height: 20px;
  transition: transform 0.3s ease;
}

#ensight-web-search.active .web-icon-svg {
  filter: brightness(0) invert(1); /* 当按钮激活时，将SVG变为白色 */
}

#ensight-web-search:hover .web-icon-svg {
  transform: scale(1.1);
}

/* Pulse animation for active state */
@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(78, 110, 242, 0.4);
  }
  70% {
    box-shadow: 0 0 0 5px rgba(78, 110, 242, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(78, 110, 242, 0);
  }
}

#ensight-web-search.active {
  animation: pulse 2s infinite;
}

/* ============================== 
   Toast Notifications
============================== */
.ensight-toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(30px);
  background-color: var(--search-color);
  color: white;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  z-index: 9999;
  box-shadow: var(--shadow-md);
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.ensight-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Toast with web search theme */
.ensight-toast::before {
  content: '🔍';
  margin-right: 8px;
}

/* ==============================
   加载指示器
============================== */
.message.loading span {
  min-height: 28px;
  min-width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dot-typing {
  position: relative;
  left: -9999px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--primary-color);
  color: var(--primary-color);
  box-shadow: 9984px 0 0 0 var(--primary-color), 
              9999px 0 0 0 var(--primary-color), 
              10014px 0 0 0 var(--primary-color);
  animation: dot-typing 1.5s infinite linear;
}

@keyframes dot-typing {
  0% {
    box-shadow: 9984px 0 0 0 var(--primary-color), 
                9999px 0 0 0 var(--primary-color), 
                10014px 0 0 0 var(--primary-color);
  }
  16.667% {
    box-shadow: 9984px -5px 0 0 var(--primary-color), 
                9999px 0 0 0 var(--primary-color), 
                10014px 0 0 0 var(--primary-color);
  }
  33.333% {
    box-shadow: 9984px 0 0 0 var(--primary-color), 
                9999px 0 0 0 var(--primary-color), 
                10014px 0 0 0 var(--primary-color);
  }
  50% {
    box-shadow: 9984px 0 0 0 var(--primary-color), 
                9999px -5px 0 0 var(--primary-color), 
                10014px 0 0 0 var(--primary-color);
  }
  66.667% {
    box-shadow: 9984px 0 0 0 var(--primary-color), 
                9999px 0 0 0 var(--primary-color), 
                10014px 0 0 0 var(--primary-color);
  }
  83.333% {
    box-shadow: 9984px 0 0 0 var(--primary-color), 
                9999px 0 0 0 var(--primary-color), 
                10014px -5px 0 0 var(--primary-color);
  }
  100% {
    box-shadow: 9984px 0 0 0 var(--primary-color), 
                9999px 0 0 0 var(--primary-color), 
                10014px 0 0 0 var(--primary-color);
  }
}

/* ==============================
   按钮区域
============================== */
.ensight-action-buttons-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  padding: 10px 0;
  margin: 10px 0;
}

.ensight-action-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* ==============================
   输入区域
============================== */
.ensight-input-area {
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-radius: var(--radius-md);
  margin-top: 10px;
}

.ensight-controls-container {
  display: flex;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  align-items: center;
  gap: 10px;
}

/* New button container for mobile */
.mobile-button-container {
  display: flex;
  justify-content: center;
  gap: 10px;
}

/* 统一按钮样式 */
.ensight-controls-container button,
#ensight-stop,
#ensight-retry {
  padding: 10px 15px;
  font-weight: bold;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  font-size: 16px;
  white-space: nowrap;
  transition: box-shadow var(--transition-default), 
              transform var(--transition-default), 
              background-color var(--transition-default);
}

#ensight-input {
  flex: 1;
  min-height: 40px;
  border-radius: var(--radius-md);
  padding: 10px;
  border: none;
  box-shadow: var(--shadow-sm);
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  resize: none;
  background-color: rgba(255, 255, 255, 0.7);
  transition: transform var(--transition-default), 
              background-color var(--transition-default);
}

#ensight-input::placeholder {
  color: rgba(47, 60, 62, 0.5);
  font-size: 16px;
  font-weight: 400;
}

#ensight-input:focus {
  outline: none;
  box-shadow: none;
  transform: translateY(-1px);
  background-color: rgba(255, 255, 255, 0.9);
}

/* 按钮特定样式 */
#ensight-send {
  background: var(--accent-color);
  color: #fff;
}

#ensight-send:hover {
  background: var(--accent-hover);
}

#ensight-reset {
  background: var(--reset-bg);
  color: #fff;
}

#ensight-reset:hover {
  background: var(--reset-hover);
}

#ensight-stop {
  background: #e74c3c;
  color: #fff;
  min-width: 100px;
}

#ensight-stop:hover {
  background: #c0392b;
}

#ensight-retry {
  background: #3498db;
  color: #fff;
  min-width: 100px;
}

#ensight-retry:hover {
  background: #2980b9;
}

/* ==============================
   消息展开覆盖层
============================== */
.message-expand-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(3px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.message-expand-container {
  position: relative;
  width: 98%;
  height: 94vh;
  max-width: 1600px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  padding: 20px;
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.message-expand-content {
  font-size: 20px;
  line-height: 1.6;
  color: var(--primary-color);
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.message-expand-close {
  position: absolute;
  top: 20px;
  right: 25px;
  font-size: 32px;
  line-height: 1;
  font-weight: 300;
  cursor: pointer;
  color: #555;
  background: none;
  border: none;
  width: auto;
  height: auto;
  opacity: 0.7;
  transition: opacity var(--transition-default), transform var(--transition-default);
  padding: 0;
  margin: 0;
  z-index: 10;
}

.message-expand-close:hover {
  opacity: 1;
  transform: scale(1.1);
}

/* ==============================
   重置对话框
============================== */
.reset-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(2px);
}

.reset-modal {
  background: #fff;
  padding: 20px;
  border-radius: var(--radius-md);
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow-md);
}

.reset-modal p {
  font-size: 18px;
  margin-bottom: 20px;
  color: var(--primary-color);
}

.reset-modal button {
  margin: 10px;
  padding: 10px 15px;
  font-size: 16px;
  font-weight: bold;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background-color var(--transition-default), 
              transform var(--transition-default), 
              box-shadow var(--transition-default);
}

.reset-modal button:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.reset-modal .confirm-btn {
  background: var(--accent-color);
  color: #fff;
}

.reset-modal .confirm-btn:hover {
  background: var(--accent-hover);
}

.reset-modal .cancel-btn {
  background: var(--reset-bg);
  color: #fff;
}

.reset-modal .cancel-btn:hover {
  background: var(--reset-hover);
}

/* ==============================
   Three.js 背景样式
============================== */
#ensight-threejs-background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
}

#ensight-threejs-background canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100% !important;
  height: 100% !important;
}

/* ==============================
   移动端响应式
============================== */
@media (max-width: 768px) {
  /* 容器样式调整 - 确保放大后没有底部间隔 */
  .ensight-chat-container {
    width: 100vw;
    height: 100%; /* 使用100%而不是100vh */
    border-radius: var(--radius-md);
    padding: 5px 5px 0 5px; /* 移除底部内边距 */
    transform-origin: center bottom;
    transform: scale(0.6) translateY(25%);
    position: fixed; /* 使用fixed而不是absolute */
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
  }
  
  /* 标题层调整 */
  .ensight-text-overlay {
    transform: translateY(-15%) !important; /* 增加标题上移以避免被聊天窗口挡住 */
  }
  
  /* 全屏展开状态 - 确保铺满整个屏幕 */
  .ensight-chat-container.fully-expanded {
    height: 100%; /* 使用100%而不是100vh */
    transform: scale(1) translateY(0);
    opacity: 1;
    border-radius: 0;
    top: 0; /* 确保容器顶部对齐视口顶部 */
    bottom: 0; /* 确保容器底部对齐视口底部 */
    padding: 0; /* 移除所有内边距 */
  }
  
  /* 调整消息区域，确保不会超出屏幕 */
  .ensight-messages {
    height: calc(100% - 190px); /* 使用百分比而不是vh单位 */
    padding: 15px 10px 10px 10px;
    max-height: none; /* 移除最大高度限制 */
    margin-bottom: 0;
  }
  
  /* 调整消息样式 */
  .message {
    margin: 8px auto;
  }
  
  .message span {
    padding: 8px;
    font-size: 16px;
  }
  
  /* 输入区域调整 - 确保固定在底部 */
  .ensight-input-area {
    padding: 10px 10px 15px 10px; /* 减少底部内边距 */
    margin-top: 5px;
    margin-bottom: 0; /* 移除底部外边距 */
    position: relative;
    bottom: 0;
  }
  
  /* 将控制容器重构为纵向布局 */
  .ensight-controls-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
  }
  
  /* 调整输入框占满宽度 */
  #ensight-input {
    width: 100%;
    order: 1;
    margin-bottom: 10px;
    flex: 1 0 100%;
    min-height: 60px;
  }
  
  /* 确保按钮完全可见 */
  .mobile-button-container {
    display: flex;
    justify-content: center;
    width: 100%;
    gap: 10px;
    order: 2;
    margin-bottom: 5px; /* 减少底部边距 */
    padding-bottom: 0; /* 移除内边距 */
  }
  
  /* 调整按钮大小和间距 */
  #ensight-reset, 
  #ensight-send, 
  #ensight-stop, 
  #ensight-retry {
    order: unset;
    padding: 10px 18px; /* 略微减小按钮高度 */
    font-size: 15px;
    margin-bottom: 0; /* 移除底部边距 */
  }
  
  /* 动作按钮居中 */
  .ensight-action-buttons-container {
    padding: 8px 0;
    margin: 8px 0;
  }
  
  .ensight-action-buttons {
    gap: 10px;
  }
  
  /* 调整停止和重试按钮的大小 */
  #ensight-stop, 
  #ensight-retry {
    min-width: 90px; /* 稍微减小宽度 */
    padding: 10px 12px;
  }
  
  /* Toast通知调整 */
  .ensight-toast {
    width: 80%;
    padding: 8px 15px;
    font-size: 13px;
    bottom: 20px;
  }
  
  /* 扩展消息模态框调整 */
  .message-expand-container {
    width: 100%;
    height: 100vh;
    border-radius: 0;
  }
  
  .message-expand-content {
    font-size: 18px;
  }
  
  /* Internet Insight按钮调整 */
  #ensight-web-search {
    padding: 8px 12px;
    font-size: 14px;
  }
  
  .web-icon-svg {
    width: 16px;
    height: 16px;
  }
  
  /* 确保标题在移动设备上可见 */
  #ensight-threejs-background {
    display: block !important;
    opacity: 1 !important;
    z-index: -1 !important; /* 确保在聊天窗口下方 */
    height: 100%; /* 使用100%而不是100vh */
    position: fixed;
  }
}