/* ===== mh-ai-chat.css — 站内AI对话小精灵 v3 ===== */
/* 风格：明亮清爽，匹配 Blocksy 博客主题白色基调 */

/* --- CSS Variables --- */
:root {
  --mh-chat-primary: #E34132;
  --mh-chat-primary-hover: #c93528;
  --mh-chat-primary-light: rgba(227, 65, 50, .08);
  --mh-chat-bg: #f8f8fa;
  --mh-chat-bg-card: #ffffff;
  --mh-chat-bg-ai: #f1f1f5;
  --mh-chat-bg-input: #ffffff;
  --mh-chat-text: #1a1a2e;
  --mh-chat-text-secondary: #6e6e82;
  --mh-chat-text-on-primary: #ffffff;
  --mh-chat-border: #e4e4ec;
  --mh-chat-shadow-sm: 0 2px 8px rgba(0,0,0,.08);
  --mh-chat-shadow: 0 4px 24px rgba(0,0,0,.12);
  --mh-chat-shadow-lg: 0 8px 40px rgba(0,0,0,.16), 0 0 0 1px var(--mh-chat-border);
  --mh-chat-radius: 14px;
  --mh-chat-radius-sm: 10px;
  --mh-chat-radius-full: 9999px;
  --mh-chat-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mh-chat-transition: 200ms cubic-bezier(.4,0,.2,1);
}

/* --- Floating Bubble (left-bottom) --- */
.mh-chat-bubble {
  position: fixed;
  bottom: 28px;
  left: 28px;
  z-index: 9998;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--mh-chat-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(227,65,50,.3);
  transition: all var(--mh-chat-transition), opacity .3s;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}
.mh-chat-bubble:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(227,65,50,.4);
}
.mh-chat-bubble:active { transform: scale(.92); }

/* Pulse ring */
.mh-chat-bubble::after {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 16px;
  border: 2px solid rgba(227,65,50,.2);
  animation: mh-chat-pulse 3s cubic-bezier(.4,0,.2,1) infinite;
}
@keyframes mh-chat-pulse {
  0%, 100% { transform: scale(1); opacity: .5; }
  50%      { transform: scale(1.2); opacity: 0; }
}

.mh-chat-bubble svg {
  width: 22px;
  height: 22px;
  color: #fff;
}

.mh-chat-bubble--hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(.4);
}

/* --- Chat Panel --- */
.mh-chat-panel {
  position: fixed;
  bottom: 100px;
  left: 28px;
  z-index: 9999;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 560px;
  max-height: calc(100vh - 140px);
  background: var(--mh-chat-bg-card);
  border-radius: var(--mh-chat-radius);
  box-shadow: var(--mh-chat-shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--mh-chat-border);
  transform-origin: bottom left;
  transform: scale(.25);
  opacity: 0;
  pointer-events: none;
  transition: transform .28s cubic-bezier(.34,1.56,.64,1), opacity .2s;
}
.mh-chat-panel--open {
  transform: scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* --- Header --- */
.mh-chat-header {
  padding: 14px 18px;
  background: var(--mh-chat-primary);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
}
.mh-chat-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: rgba(255,255,255,.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.mh-chat-header-avatar svg { width: 20px; height: 20px; color: #fff; }
.mh-chat-header-info { flex: 1; min-width: 0; }
.mh-chat-header-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
}
.mh-chat-header-subtitle {
  font-size: 11px;
  color: rgba(255,255,255,.7);
  line-height: 1.3;
}
.mh-chat-header-close {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  background: rgba(255,255,255,.15);
  color: rgba(255,255,255,.7);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--mh-chat-transition);
}
.mh-chat-header-close:hover { background: rgba(255,255,255,.25); color: #fff; }
.mh-chat-header-close svg { width: 16px; height: 16px; }

/* --- Messages --- */
.mh-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  background: var(--mh-chat-bg);
}
.mh-chat-messages::-webkit-scrollbar { width: 3px; }
.mh-chat-messages::-webkit-scrollbar-thumb {
  background: #d0d0d8;
  border-radius: 2px;
}

/* --- Message Bubbles --- */
.mh-chat-msg {
  display: flex;
  gap: 8px;
  max-width: 85%;
  width: fit-content;
  animation: mh-chat-msg-in .25s ease-out;
}
@keyframes mh-chat-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* AI message */
.mh-chat-msg--ai { align-self: flex-start; }
.mh-chat-msg--ai .mh-chat-msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--mh-chat-primary-light);
  border: 1px solid var(--mh-chat-border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}
.mh-chat-msg--ai .mh-chat-msg-avatar svg { width: 16px; height: 16px; color: var(--mh-chat-primary); }
.mh-chat-msg--ai .mh-chat-msg-bubble {
  background: var(--mh-chat-bg-ai);
  color: var(--mh-chat-text);
  border-radius: 2px var(--mh-chat-radius-sm) var(--mh-chat-radius-sm) var(--mh-chat-radius-sm);
  padding: 9px 13px;
  font-size: 13.5px;
  line-height: 1.6;
  word-break: break-word;
  border: 1px solid var(--mh-chat-border);
}

/* User message */
.mh-chat-msg--user {
  align-self: flex-end;
  flex-direction: row-reverse;
  align-items: flex-start;
}
.mh-chat-msg--user > div { width: fit-content; }
.mh-chat-msg--user .mh-chat-msg-time { display: none; }
.mh-chat-msg--user .mh-chat-msg-bubble {
  background: var(--mh-chat-primary);
  color: #ffffff;
  border-radius: 12px 12px 12px 3px;
  padding: 6px 12px;
  font-size: 14px;
  line-height: 1.4;
  word-break: break-word;
  box-shadow: 0 2px 8px rgba(227,65,50,.2);
}

/* Typing indicator */
.mh-chat-typing { display: flex; gap: 4px; padding: 2px 0; }
.mh-chat-typing span {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--mh-chat-text-secondary);
  animation: mh-chat-dot-bounce 1.4s infinite ease-in-out both;
}
.mh-chat-typing span:nth-child(1) { animation-delay: 0s; }
.mh-chat-typing span:nth-child(2) { animation-delay: .16s; }
.mh-chat-typing span:nth-child(3) { animation-delay: .32s; }
@keyframes mh-chat-dot-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-5px); }
}

/* Time */
.mh-chat-msg-time {
  font-size: 10px;
  color: var(--mh-chat-text-secondary);
  margin-top: 2px;
  padding: 0 4px;
}
.mh-chat-msg--ai .mh-chat-msg-time { display: block; }

/* --- Welcome card --- */
.mh-chat-welcome {
  text-align: center;
  padding: 20px 8px;
}
.mh-chat-welcome-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  border-radius: 14px;
  background: var(--mh-chat-primary-light);
  border: 1px solid var(--mh-chat-border);
  display: flex;
  align-items: center;
  justify-content: center;
}
.mh-chat-welcome-icon svg { width: 24px; height: 24px; color: var(--mh-chat-primary); }
.mh-chat-welcome-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--mh-chat-text);
  margin-bottom: 6px;
}
.mh-chat-welcome-desc {
  font-size: 13px;
  color: var(--mh-chat-text-secondary);
  line-height: 1.6;
  margin-bottom: 12px;
  max-width: 280px;
  margin-left: auto;
  margin-right: auto;
}
.mh-chat-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: center;
}
.mh-chat-quick-btn {
  padding: 6px 14px;
  border-radius: var(--mh-chat-radius-full);
  border: 1px solid var(--mh-chat-border);
  background: transparent;
  color: var(--mh-chat-text-secondary);
  font-size: 12.5px;
  cursor: pointer;
  font-family: var(--mh-chat-font);
  transition: all var(--mh-chat-transition);
  white-space: nowrap;
}
.mh-chat-quick-btn:hover {
  border-color: var(--mh-chat-primary);
  color: var(--mh-chat-primary);
  background: var(--mh-chat-primary-light);
}

/* --- Input Area --- */
.mh-chat-input-area {
  padding: 12px 14px 14px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-shrink: 0;
  background: var(--mh-chat-bg-card);
  border-top: 1px solid var(--mh-chat-border);
}
.mh-chat-input {
  flex: 1;
  border: 1px solid var(--mh-chat-border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: var(--mh-chat-font);
  font-weight: 400;
  color: var(--mh-chat-text);
  background: var(--mh-chat-bg);
  outline: none;
  resize: none;
  overflow: hidden;
  scrollbar-width: none;
  max-height: 100px;
  line-height: 1.5;
  transition: border-color var(--mh-chat-transition), box-shadow var(--mh-chat-transition);
}
.mh-chat-input::-webkit-scrollbar { display: none; }
.mh-chat-input:focus {
  border-color: var(--mh-chat-primary);
  box-shadow: 0 0 0 3px rgba(227,65,50,.1);
  background: #fff;
}
.mh-chat-input::placeholder { color: #999; }
.mh-chat-send {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  background: var(--mh-chat-primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--mh-chat-transition);
  box-shadow: 0 2px 10px rgba(227,65,50,.25);
}
.mh-chat-send:hover { background: var(--mh-chat-primary-hover); transform: translateY(-1px); }
.mh-chat-send:disabled { opacity: .3; cursor: not-allowed; transform: none; box-shadow: none; }
.mh-chat-send svg { width: 16px; height: 16px; }

/* Error / status indicators */
.mh-chat-status {
  text-align: center;
  font-size: 11px;
  color: var(--mh-chat-text-secondary);
  padding: 6px 0;
  opacity: .7;
}

/* AI message with markdown formatting */
.mh-chat-msg--ai .mh-chat-msg-bubble p { margin: 0 0 6px; }
.mh-chat-msg--ai .mh-chat-msg-bubble p:last-child { margin: 0; }
.mh-chat-msg--ai .mh-chat-msg-bubble strong { color: var(--mh-chat-primary); }
.mh-chat-msg--ai .mh-chat-msg-bubble a { color: var(--mh-chat-primary); }

/* --- Mobile --- */
@media (max-width: 480px) {
  .mh-chat-bubble { bottom: 18px; left: 18px; }
  .mh-chat-panel {
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100%; max-width: 100%;
    height: 100%; max-height: 100%;
    border-radius: 0; border: none;
    transform-origin: center;
  }
  .mh-chat-bubble--hidden { display: none; }
}
