/* ============================================================
   万境 AI · 像素小助手「万小境」
   ============================================================ */

/* ---------- 悬浮按钮（机器人） ---------- */
#chat-fab {
  position: fixed;
  right: 20px;
  bottom: var(--sf-pad, 56px);     /* 对齐固定底条顶部 */
  z-index: 4;                      /* 低于底条(5)，下半身被底条遮挡 → 趴边效果 */
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#chat-fab:active { transform: scale(.96); }

.chat-robot {
  width: 110px;
  height: 110px;
  position: relative;
  transform: translateY(60%);          /* 平时趴在底条上，只露头和上半身 */
  transition: transform .55s cubic-bezier(.34, 1.56, .64, 1);
  filter: drop-shadow(0 4px 12px rgba(6, 182, 212, .3));
  animation: robotPeek 3.5s ease-in-out infinite;
}
.chat-robot img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}
/* 平时趴在边上微微探头呼吸 */
@keyframes robotPeek {
  0%, 100% { transform: translateY(60%); }
  50% { transform: translateY(52%); }
}
/* hover / 打开面板时跳起来 */
#chat-fab:hover .chat-robot,
#chat-fab.panel-open .chat-robot {
  transform: translateY(-6px) scale(1.06);
  animation: robotJump .6s cubic-bezier(.34, 1.56, .64, 1), robotBob 2.4s ease-in-out infinite .6s;
  filter: drop-shadow(0 8px 22px rgba(6, 182, 212, .55));
}
@keyframes robotJump {
  0% { transform: translateY(60%) scale(1); }
  50% { transform: translateY(-14px) scale(1.1); }
  100% { transform: translateY(-6px) scale(1.06); }
}
/* 悬浮后的呼吸浮动 */
@keyframes robotBob {
  0%, 100% { transform: translateY(-6px) scale(1.06); }
  50% { transform: translateY(-12px) scale(1.06); }
}
/* 灵动：定时轻微点头+光晕 */
.chat-robot.blink img {
  animation: robotNod .6s ease;
}
@keyframes robotNod {
  0%, 100% { transform: rotate(0); }
  40% { transform: rotate(-4deg); }
  70% { transform: rotate(2deg); }
}
/* 说话时周身发光呼吸 */
.chat-robot.talk {
  filter: drop-shadow(0 10px 28px rgba(6, 182, 212, .7));
}
.chat-robot.talk img {
  animation: talkShake .4s ease-in-out infinite alternate;
}
@keyframes talkShake {
  from { transform: rotate(-2deg) scale(1.02); }
  to { transform: rotate(2deg) scale(1.05); }
}

/* 说话提示气泡 */
.chat-tip {
  position: absolute;
  right: 100px;
  top: 30%;
  transform: translateY(-50%);
  background: #fff;
  color: #16323f;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 14px;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
}
.chat-tip::after {
  content: '';
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-left-color: #fff;
}
#chat-fab:hover .chat-tip { opacity: 1; }

/* 小红点（未读提示） */
.chat-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 10px;
  height: 10px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid #04111f;
  animation: dotPulse 1.6s ease-in-out infinite;
}
@keyframes dotPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .5; transform: scale(1.3); }
}

/* ---------- 对话面板 ---------- */
#chat-panel {
  position: fixed;
  right: 24px;
  bottom: calc(var(--sf-pad, 56px) + 16px);
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 200px);
  background: linear-gradient(160deg, #0a2236 0%, #04111f 100%);
  border: 1px solid rgba(56, 224, 240, .35);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5), 0 0 0 1px rgba(30,159,255,.15) inset;
  z-index: 9991;
  display: none;
  flex-direction: column;
  overflow: hidden;
  backdrop-filter: blur(12px);
}
#chat-panel.open {
  display: flex;
  animation: panelIn .28s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes panelIn {
  from { opacity: 0; transform: translateY(20px) scale(.92); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-header {
  padding: 14px 16px;
  background: linear-gradient(90deg, rgba(2,132,199,.25), rgba(6,182,212,.15));
  border-bottom: 1px solid rgba(56, 224, 240, .25);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.chat-header .avatar {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
}
.chat-header .avatar img { width: 100%; height: 100%; object-fit: contain; }
.chat-header .meta { flex: 1; min-width: 0; }
.chat-header .name { color: #e0f7ff; font-size: 15px; font-weight: 700; }
.chat-header .status { color: #67e8f9; font-size: 12px; display: flex; align-items: center; gap: 5px; }
.chat-header .status::before {
  content: '';
  width: 7px; height: 7px;
  background: #22c55e;
  border-radius: 50%;
  box-shadow: 0 0 6px #22c55e;
  animation: dotPulse 2s infinite;
}
.chat-close {
  background: none; border: none; color: #8ab4c8;
  font-size: 22px; cursor: pointer; line-height: 1;
  padding: 4px 6px; border-radius: 6px;
}
.chat-close:hover { background: rgba(255,255,255,.1); color: #fff; }

/* 消息区 */
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.chat-body::-webkit-scrollbar { width: 5px; }
.chat-body::-webkit-scrollbar-thumb { background: rgba(56,224,240,.3); border-radius: 3px; }

.msg {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  animation: msgIn .25s ease;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg.bot {
  align-self: flex-start;
  background: rgba(255,255,255,.08);
  color: #d6f0ff;
  border: 1px solid rgba(56,224,240,.18);
  border-bottom-left-radius: 4px;
}
.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #0284c7, #06b6d4);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* 打字中 */
.typing {
  align-self: flex-start;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(56,224,240,.18);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 12px 14px;
  display: flex;
  gap: 4px;
}
.typing span {
  width: 7px; height: 7px;
  background: #67e8f9;
  border-radius: 50%;
  animation: typingDot 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* 快捷回复 */
.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 16px;
  border-top: 1px solid rgba(56,224,240,.15);
  flex-shrink: 0;
}
.qr-btn {
  background: rgba(6,182,212,.12);
  color: #67e8f9;
  border: 1px solid rgba(6,182,212,.3);
  border-radius: 14px;
  padding: 5px 12px;
  font-size: 12.5px;
  cursor: pointer;
  transition: all .18s;
}
.qr-btn:hover { background: rgba(6,182,212,.25); color: #a5f3fc; }
.qr-btn:active { transform: scale(.96); }

/* 输入区 */
.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 10px 16px 14px;
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(56,224,240,.25);
  border-radius: 20px;
  padding: 9px 16px;
  color: #e0f7ff;
  font-size: 14px;
  outline: none;
  transition: border-color .2s;
}
.chat-input::placeholder { color: #5f8aa0; }
.chat-input:focus { border-color: rgba(6,182,212,.6); }
.chat-send {
  background: linear-gradient(135deg, #0284c7, #06b6d4);
  border: none;
  color: #fff;
  border-radius: 50%;
  width: 38px; height: 38px;
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
  transition: transform .15s;
}
.chat-send:hover { transform: scale(1.08); }
.chat-send:active { transform: scale(.92); }
.chat-send:disabled { opacity: .4; cursor: not-allowed; }

/* 移动端 */
@media (max-width: 520px) {
  #chat-fab { right: 10px; bottom: var(--sf-pad, 56px); }
  .chat-robot { width: 84px; height: 84px; }
  #chat-panel {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: calc(var(--sf-pad, 56px) + 10px);
    height: 70vh;
    max-height: 70vh;
  }
  .chat-tip { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-robot, .chat-robot.blink, .chat-robot.talk,
  .typing span, .chat-dot { animation: none !important; }
}
