/* ============================================================
   chat.css - 对话页面专属样式
   与 style.css 共用 CSS 变量，补充对话气泡、输入栏等样式
   ============================================================ */

/* ---------- 整体布局（全屏固定高度） ---------- */
body {
  padding: 0;
  background: var(--bg);
  overflow: hidden;        /* 禁止 body 滚动，由消息区内部滚动 */
}

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 800px;
  margin: 0 auto;
}

/* ---------- 顶部标题栏 ---------- */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  box-shadow: 0 2px 12px rgba(37, 99, 235, 0.06);
}

.chat-header-center {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-logo {
  font-size: 1.3rem;
  color: var(--primary);
}

.chat-header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.back-link {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 8px;
  transition: background var(--transition), color var(--transition);
}
.back-link:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.clear-btn {
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 600;
  color: #dc2626;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}
.clear-btn:hover {
  background: #fee2e2;
  transform: translateY(-1px);
}

/* ---------- 消息列表区（可滚动） ---------- */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

/* 美化滚动条 */
.messages-area::-webkit-scrollbar { width: 5px; }
.messages-area::-webkit-scrollbar-track { background: transparent; }
.messages-area::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}

/* ---------- 消息气泡基础 ---------- */
.message {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 78%;
  animation: fadeInUp 0.25s ease forwards;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 700;
}

.assistant-avatar {
  background: linear-gradient(135deg, var(--primary), var(--violet));
  color: white;
}

.user-avatar {
  background: linear-gradient(135deg, var(--teal), #14b8a6);
  color: white;
  font-size: 0.8rem;
}

.bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 0.975rem;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

/* AI 消息 - 左对齐 */
.assistant-message {
  align-self: flex-start;
}
.assistant-message .bubble {
  background: var(--white);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

/* 用户消息 - 右对齐 */
.user-message {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.user-message .bubble {
  background: linear-gradient(135deg, var(--primary), #3b82f6);
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.25);
}

/* ---------- 底部输入区 ---------- */
.chat-footer {
  padding: 16px 20px;
  background: var(--white);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 10px 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input-bar:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

#userInput {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-size: 0.975rem;
  font-family: inherit;
  line-height: 1.6;
  background: transparent;
  color: var(--text);
  max-height: 140px;
  overflow-y: auto;
}
#userInput::placeholder { color: #c0ccd8; }

.send-btn {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #3b82f6);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition), box-shadow var(--transition), opacity var(--transition);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}
.send-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.4);
}
.send-btn:active:not(:disabled) { transform: translateY(0); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.send-btn svg { width: 17px; height: 17px; }

.chat-tip {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 8px;
  opacity: 0.7;
}

/* ---------- 打字机光标（复用） ---------- */
.typing-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--primary);
  margin-left: 2px;
  vertical-align: text-bottom;
  border-radius: 1px;
  animation: blink 0.8s step-end infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ---------- 响应式 ---------- */
@media (max-width: 560px) {
  .message { max-width: 92%; }
  .chat-header h1 { font-size: 1rem; }
}
