/* ============================================
   SoulAnchor - public/css/main.css
   主聊天界面样式（CDN 缓存友好）
   ============================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-primary: #0f0c29;
  --bg-chat: rgba(255,255,255,0.03);
  --bg-bubble-user: linear-gradient(135deg, #667eea, #764ba2);
  --bg-bubble-ai: rgba(255,255,255,0.06);
  --text-primary: #e8e8e8;
  --text-secondary: #888;
  --accent: #667eea;
  --accent-soft: rgba(102,126,234,0.15);
  --border: rgba(255,255,255,0.08);
  --success: #4ecdc4;
  --radius-lg: 20px;
  --radius-md: 14px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', sans-serif;
  background: linear-gradient(180deg, var(--bg-primary) 0%, #1a1640 50%, #0d0b1e 100%);
  min-height: 100vh;
  color: var(--text-primary);
  overflow: hidden;
}

/* ---- App Container ---- */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 680px;
  margin: 0 auto;
}

/* ---- Header ---- */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.chat-header .logo { display: flex; align-items: center; gap: 10px; }
.chat-header .logo-icon {
  width: 36px; height: 36px; border-radius: 12px;
  background: var(--bg-bubble-user);
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.chat-header .logo-text { font-size: 18px; font-weight: 600; letter-spacing: -0.3px; }
.chat-header .soul-profile-btn {
  padding: 6px 14px; border-radius: 20px;
  border: 1px solid var(--border); background: transparent;
  color: var(--text-secondary); font-size: 13px; cursor: pointer;
  transition: all 0.2s;
}
.chat-header .soul-profile-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---- Messages ---- */
.chat-messages {
  flex: 1; overflow-y: auto; padding: 20px; scroll-behavior: smooth;
}
.message {
  display: flex; margin-bottom: 16px;
  animation: messageIn 0.3s ease;
}
@keyframes messageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }
.bubble {
  max-width: 80%; padding: 12px 16px; border-radius: var(--radius-md);
  font-size: 15px; line-height: 1.6; word-break: break-word;
}
.message.user .bubble {
  background: var(--bg-bubble-user); color: white; border-bottom-right-radius: 4px;
}
.message.assistant .bubble {
  background: var(--bg-bubble-ai); border: 1px solid var(--border); border-bottom-left-radius: 4px;
}

/* ---- 记忆闪回 Chips ---- */
.memory-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.memory-chip {
  padding: 4px 12px; border-radius: 20px; font-size: 12px;
  background: var(--accent-soft); color: var(--accent);
  cursor: pointer; transition: all 0.2s; border: 1px solid transparent;
}
.memory-chip:hover { border-color: var(--accent); background: rgba(102,126,234,0.25); }
.memory-chip.has-media::after { content: ' \1f5bc\fe0f'; }

/* ---- 输入区 ---- */
.chat-input-area {
  padding: 12px 20px 24px; border-top: 1px solid var(--border);
  background: rgba(0,0,0,0.2);
}
.input-wrapper {
  display: flex; align-items: flex-end; gap: 10px;
  background: rgba(255,255,255,0.06); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 10px 16px;
  transition: border-color 0.3s;
}
.input-wrapper:focus-within { border-color: rgba(102,126,234,0.4); }
.chat-input {
  flex: 1; border: none; background: transparent; color: white;
  font-size: 15px; resize: none; outline: none; max-height: 120px; line-height: 1.5;
}
.chat-input::placeholder { color: #555; }
.send-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none;
  background: var(--bg-bubble-user); color: white; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s, opacity 0.2s; flex-shrink: 0;
}
.send-btn:hover { transform: scale(1.05); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.char-count {
  text-align: right; font-size: 11px; color: #555; margin-top: 4px; padding-right: 4px;
}

/* ---- Typing 指示器 ---- */
.typing-indicator { display: flex; gap: 4px; padding: 12px 16px; }
.typing-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--text-secondary);
  animation: typingBounce 1.4s infinite ease-in-out;
}
.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ---- 鼓励气泡 ---- */
.encouragement {
  text-align: center; padding: 8px 16px; font-size: 13px;
  color: var(--text-secondary); animation: fadeIn 0.5s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---- 骨架屏 ---- */
.skeleton-wrapper {
  padding: 20px; height: 100vh; display: flex; flex-direction: column;
}
.skeleton-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 30px; padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.skeleton-avatar { width: 40px; height: 40px; border-radius: 12px; background: rgba(255,255,255,0.08); }
.skeleton-title { width: 120px; height: 20px; border-radius: 6px; background: rgba(255,255,255,0.08); }
.skeleton-messages { flex: 1; display: flex; flex-direction: column; gap: 16px; }
.skeleton-bubble { height: 48px; border-radius: var(--radius-md); background: rgba(255,255,255,0.05); }
.skeleton-left { width: 60%; align-self: flex-start; }
.skeleton-right { width: 45%; align-self: flex-end; }
.skeleton-left.long { width: 75%; height: 72px; }
.skeleton-input {
  height: 52px; border-radius: var(--radius-lg);
  background: rgba(255,255,255,0.05); margin-top: auto;
}
.pulse { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 0.6; } 50% { opacity: 0.3; } }

/* ---- Safe Shield 工作模式 ---- */
body.safe-mode .memory-chips { display: none !important; }
body.safe-mode .char-count { display: none !important; }
body.safe-mode .soul-profile-btn { display: none !important; }

/* ---- Toast ---- */
.toast {
  position: fixed; top: 20px; left: 50%;
  transform: translateX(-50%) translateY(-60px);
  padding: 10px 20px; border-radius: 12px;
  background: rgba(30,30,60,0.9); border: 1px solid var(--border);
  backdrop-filter: blur(20px); font-size: 14px; color: var(--text-primary);
  opacity: 0; transition: all 0.3s ease; z-index: 1000;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ---- 记忆模态框 ---- */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 999; opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
.modal-overlay.show { opacity: 1; pointer-events: auto; }
.modal-content {
  background: rgba(20,18,50,0.95); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 24px;
  max-width: 480px; width: 90%; max-height: 80vh; overflow-y: auto;
}
.modal-content img { width: 100%; border-radius: var(--radius-md); margin-bottom: 12px; }

/* ---- 消息时间戳 + TTS 按钮 ---- */
.msg-meta {
  display: flex; align-items: center; gap: 8px;
  margin-top: 4px; padding: 0 4px;
}
.msg-time {
  font-size: 11px; color: #555; line-height: 1;
}
.message.user .msg-meta { justify-content: flex-end; }
.message.assistant .msg-meta { justify-content: flex-start; }
.tts-btn {
  background: none; border: none; cursor: pointer;
  font-size: 14px; padding: 2px 4px; border-radius: 6px;
  opacity: 0.5; transition: opacity 0.2s, transform 0.2s;
}
.tts-btn:hover { opacity: 1; transform: scale(1.15); }
/* ---- 响应式 ---- */
@media (max-width: 480px) {
  .bubble { max-width: 88%; font-size: 14px; }
  .chat-header { padding: 12px 16px; }
  .chat-messages { padding: 16px; }
  .chat-input-area { padding: 10px 16px 20px; }
}