/* chat.css - AI閹剚璇為懕濠傘亯缁愭褰涢弽宄扮础 */

.ai-chat-btn {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 60px;
  height: 60px;
  background: var(--bg-white);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transition: transform 0.2s, box-shadow 0.2s;
  z-index: 1000;
  border: 1px solid var(--border);
  user-select: none;
}
.ai-chat-btn:hover { transform: scale(1.08); box-shadow: 0 4px 16px rgba(0,0,0,0.15); }
.ai-chat-btn:active { transform: scale(0.95); }
.ai-chat-btn.active { background: var(--bg); border-color: var(--text); }

.ai-chat-window {
  position: fixed;
  bottom: 100px;
  right: 30px;
  width: 280px;
  height: 70vh;
  max-height: 700px;
  min-height: 500px;
  background: var(--bg);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  display: none;
  flex-direction: column;
  z-index: 1001;
  overflow: hidden;
  border: 1px solid var(--border);
  font-size: 12px;
}
.ai-chat-window.show { display: flex; animation: chatWindowIn 0.3s ease; }
.ai-chat-window.closing { display: flex; animation: chatWindowOut 0.25s ease forwards; }

@keyframes chatWindowIn {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes chatWindowOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(20px) scale(0.95); }
}

/* 聊天窗口头部 */
.chat-header {
  background: var(--bg-white);
  color: var(--text);
  padding: 0 10px 0 0;
  height: 38px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-header-left {
  display: flex;
  align-items: center;
  gap: 0;
  flex: 1;
  min-width: 0;
  height: 100%;
}
.chat-sidebar-title {
  width: 0;
  overflow: hidden;
  white-space: nowrap;
  transition: width 0.25s ease, opacity 0.2s ease;
  font-size: 12px;
  color: var(--text);
  border-right: 1px solid transparent;
  padding: 0;
  margin: 0;
  opacity: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}
.ai-chat-window:has(.chat-sidebar.show) .chat-sidebar-title {
  width: 100px;
  border-right-color: var(--border);
  opacity: 1;
}
.chat-main-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding-left: 10px;
}
.chat-close-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-light);
  font-size: 16px;
  cursor: pointer;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.2s;
  flex-shrink: 0;
}
.chat-close-btn:hover { background: var(--border); color: var(--text); transform: rotate(90deg); }

/* 聊天窗口内容区（侧边栏+主区域） */
.chat-body {
  flex: 1;
  display: flex;
  flex-direction: row;
  overflow: hidden;
  min-height: 0;
}

/* 侧边栏 - 在窗口内部左侧 */
.chat-sidebar {
  width: 0;
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.25s ease;
  flex-shrink: 0;
}
.chat-sidebar.show { width: 100px; }

.chat-sidebar-header {
  padding: 8px;
  flex-shrink: 0;
}

.chat-new-btn {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
  white-space: nowrap;
}

.chat-new-btn:hover {
  background: var(--bg);
}
.chat-sidebar-list { flex: 1; overflow-y: auto; padding: 6px; }
.chat-sidebar-item {
  padding: 6px 8px;
  border-radius: 5px;
  cursor: pointer;
  margin-bottom: 2px;
  font-size: 11px;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.15s;
}
.chat-sidebar-item:hover, .chat-sidebar-item.active { background: var(--border); }
.chat-sidebar-item-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-sidebar-item-delete { opacity: 0; background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 2px; font-size: 10px; }
.chat-sidebar-item:hover .chat-sidebar-item-delete { opacity: 1; }
.chat-sidebar-empty { text-align: center; padding: 16px 8px; color: var(--text-muted); font-size: 11px; }

/* 主聊天区域 - 被侧边栏挤压 */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
  background: var(--bg);
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.chat-msg {
  max-width: 88%;
  padding: 8px 10px;
  border-radius: 12px;
  margin-bottom: 8px;
  font-size: 12px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: msgFadeIn 0.3s ease;
}
.chat-msg.user {
  background: var(--bg);
  color: var(--text);
  margin-left: auto;
  border-bottom-right-radius: 4px;
  border: 1px solid var(--border);
}
.chat-msg.ai {
  background: var(--bg-white);
  color: var(--text);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

/* 输入区域 - 在主区域底部，被侧边栏挤压 */
.chat-input-wrapper {
  display: flex;
  align-items: center;
  gap: 3px;
  background: #f4f4f4;
  padding: 6px 8px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-input-wrapper:focus-within { background: #ececec; }
.chat-input-divider { width: 1px; height: 14px; background: var(--border); margin: 0 2px; }
.chat-input-wrapper textarea {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 12px;
  font-family: inherit;
  line-height: 1.4;
  resize: none;
  max-height: 60px;
  color: var(--text);
  padding: 2px 4px;
  overflow: hidden;
}
.chat-input-wrapper textarea:focus { outline: none; }
.chat-input-wrapper textarea::placeholder { color: var(--text-muted); }


.chat-input-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-light);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  font-size: 12px;
}
.chat-input-btn:hover, .chat-input-btn.active { background: var(--border); color: var(--text); }
.chat-input-btn.chat-thinking-btn.active { color: #333; background: transparent; border: 1px solid #333; }
.chat-input-btn.chat-send-btn { background: var(--text); color: var(--bg-white); }
.chat-input-btn.chat-send-btn:hover { background: #000; }

:root.dark .chat-input-wrapper { background: #2d2d2d; }
:root.dark .chat-input-wrapper:focus-within { background: #3d3d3d; }
:root.dark .chat-input-btn.chat-send-btn { background: #e0e0e0; color: #212121; }
:root.dark .chat-input-btn.chat-send-btn:hover { background: #fff; }
:root.dark .chat-input-btn.chat-thinking-btn.active { color: #e0e0e0; border-color: #e0e0e0; }

/* ========== 平板端适配 ========== */
@media (max-width: 768px) {
  .chat-sidebar.show { width: 90px; }
  .chat-sidebar-item { font-size: 10px; padding: 5px 6px; }
}

/* ========== 手机端适配 ========== */
@media (max-width: 480px) {
  .ai-chat-btn {
    width: 46px;
    height: 46px;
    font-size: 20px;
    right: 12px;
    bottom: 12px;
  }
  
  /* 聊天窗口 - 增加宽度以容纳侧边栏 */
  .ai-chat-window {
    bottom: 70px;
    right: 12px;
    left: auto;
    width: 280px;
    height: 60vh;
    min-height: 350px;
    max-height: 450px;
    border-radius: 14px;
  }
  
  .chat-header {
    padding: 0 8px 0 0;
    height: 34px;
    font-size: 12px;
  }
  
  .chat-close-btn {
    width: 22px;
    height: 22px;
    font-size: 14px;
  }
  
  .chat-sidebar.show { width: 80px; }
  
  .chat-sidebar-header { padding: 6px; }
  
  .chat-new-btn {
    padding: 6px 8px;
    font-size: 10px;
    border-radius: 5px;
  }
  
  .chat-sidebar-title { font-size: 10px; }
  .ai-chat-window:has(.chat-sidebar.show) .chat-sidebar-title {
    width: 80px;
  }
  
  .chat-sidebar-item {
    font-size: 9px;
    padding: 4px 5px;
  }
  
  .chat-messages {
    padding: 8px 6px;
  }
  
  .chat-msg {
    max-width: 92%;
    padding: 5px 7px;
    font-size: 8px;
    border-radius: 10px;
    line-height: 1.4;
  }
  
  .chat-input-wrapper {
    padding: 6px 8px;
  }
  
  .chat-input-wrapper textarea {
    font-size: 14px;
    padding: 3px 4px;
  }
  
  .chat-input-btn {
    width: 26px;
    height: 26px;
    font-size: 12px;
  }
  
  .chat-input-divider {
    height: 14px;
    margin: 0 3px;
  }
}
