/* ==========================================================================
   AI 悬浮按钮 + 对话窗口
   1rem = 40px（桌面端 2.084vw，移动端固定 40px）
   ========================================================================== */

.ai-chat {
  position: fixed;
  right: 1.2rem;
  bottom: 1.2rem;
  z-index: 9990;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* ---------- 悬浮按钮 ---------- */
.ai-chat__fab {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 1.4rem;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  /* background: linear-gradient(135deg, #1f7cff 0%, #4f9bff 58%, #7cc0ff 100%); */
  /* box-shadow: 0 0.16rem 0.4rem rgba(31, 124, 255, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.35); */
  transition:
    transform 0.3s ease,
    box-shadow 0.3s ease;
}

.ai-chat__fab:hover {
  transform: translateY(-0.06rem) scale(1.04);
  box-shadow:
    0 0.22rem 0.5rem rgba(31, 124, 255, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.ai-chat__fab:active {
  transform: scale(0.96);
}

@keyframes ai-fab-pulse {
  0% {
    transform: scale(0.88);
    opacity: 0.8;
  }
  70% {
    transform: scale(1.28);
    opacity: 0;
  }
  100% {
    transform: scale(1.28);
    opacity: 0;
  }
}

.ai-chat__fab svg {
  display: block;
  width: 58%;
  height: 58%;
  fill: #fff;
}

.ai-chat.is-open .ai-chat__fab::after {
  animation: none;
  opacity: 0;
}

/* ---------- 对话面板 ---------- */
.ai-chat__panel {
  position: absolute;
  right: 0;
  bottom: calc(1.4rem + 0.4rem);
  display: flex;
  flex-direction: column;
  width: 9rem;
  height: 13rem;
  overflow: hidden;
  background: #fff;
  border-radius: 0.36rem;
  box-shadow:
    0 0.3rem 0.9rem rgba(11, 44, 92, 0.18),
    0 0 0 1px rgba(11, 44, 92, 0.05);
  opacity: 0;
  visibility: hidden;
  transform: translateY(0.24rem) scale(0.94);
  transform-origin: 100% 100%;
  transition:
    opacity 0.3s ease,
    transform 0.3s cubic-bezier(0.22, 0.68, 0.36, 1),
    visibility 0.3s;
}

.ai-chat.is-open .ai-chat__panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* 头部 */
.ai-chat__head {
  display: flex;
  align-items: center;
  gap: 0.22rem;
  flex-shrink: 0;
  padding: 0.28rem 0.32rem;
  background: linear-gradient(120deg, #1f7cff 0%, #5aa2ff 100%);
  color: #fff;
}

.ai-chat__avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 0.72rem;
  height: 0.72rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.ai-chat__avatar svg {
  display: block;
  width: 60%;
  height: 60%;
  fill: #fff;
}

.ai-chat__title {
  flex: 1;
  min-width: 0;
}

.ai-chat__title h3 {
  margin: 0;
  font-size: 0.36rem;
  font-weight: 500;
  line-height: 1.3;
}

.ai-chat__title p {
  margin-top: 0.04rem;
  font-size: 0.28rem;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.78);
}

.ai-chat__min,
.ai-chat__clear {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 0.6rem;
  height: 0.6rem;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 0.4rem;
  line-height: 1;
  transition: background 0.25s ease;
}

.ai-chat__min:hover,
.ai-chat__clear:hover {
  background: rgba(255, 255, 255, 0.3);
}

.ai-chat__clear {
  margin-left: 0.08rem;
}

.ai-chat__clear svg {
  display: block;
  width: 58%;
  height: 58%;
}

/* 消息区 */
.ai-chat__body {
  display: flex;
  flex-direction: column;
  gap: 0.24rem;
  flex: 1;
  padding: 0.3rem 0.3rem 0.34rem;
  overflow-y: auto;
  background: #f5f8fd;
  -webkit-overflow-scrolling: touch;
}

.ai-chat__body::-webkit-scrollbar {
  width: 0.08rem;
}

.ai-chat__body::-webkit-scrollbar-thumb {
  background: rgba(31, 124, 255, 0.22);
  border-radius: 0.04rem;
}

.ai-chat__msg {
  max-width: 82%;
  padding: 0.2rem 0.26rem;
  border-radius: 0.22rem;
  font-size: 0.325rem;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
  animation: ai-msg-in 0.32s ease both;
}

@keyframes ai-msg-in {
  from {
    opacity: 0;
    transform: translateY(0.1rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ai-chat__msg--bot {
  align-self: flex-start;
  background: #fff;
  color: #1b2436;
  border: 1px solid rgba(11, 44, 92, 0.06);
  border-top-left-radius: 0.06rem;
  box-shadow: 0 0.04rem 0.14rem rgba(11, 44, 92, 0.05);
}

.ai-chat__msg--user {
  align-self: flex-end;
  background: linear-gradient(135deg, #1f7cff 0%, #5aa2ff 100%);
  color: #fff;
  border-top-right-radius: 0.06rem;
}

/* 相关问题列表 */
.ai-chat__msg--list {
  max-width: 100%;
  padding: 0.24rem 0.26rem;
}

.ai-chat__tip {
  margin: 0 0 0.18rem;
  font-size: 0.3rem;
  line-height: 1.5;
  color: #7c8ba1;
}

.ai-chat__qlist {
  display: flex;
  flex-direction: column;
  gap: 0.14rem;
}

.ai-chat__q {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.14rem;
  width: 100%;
  padding: 0.18rem 0.22rem;
  background: #f2f6fc;
  border: 1px solid rgba(31, 124, 255, 0.14);
  border-radius: 0.16rem;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.3rem;
  line-height: 1.5;
  color: #1b2436;
  text-align: left;
  transition:
    background 0.25s ease,
    border-color 0.25s ease,
    color 0.25s ease,
    transform 0.25s ease;
}

.ai-chat__q::after {
  content: "›";
  flex-shrink: 0;
  color: #1f7cff;
  font-size: 0.38rem;
  line-height: 1;
}

.ai-chat__q:hover {
  background: #fff;
  border-color: rgba(31, 124, 255, 0.5);
  color: #1f7cff;
  transform: translateX(0.04rem);
}

.ai-chat__q.is-done {
  background: #fff;
  border-color: rgba(31, 124, 255, 0.16);
  color: #9aa7ba;
  cursor: default;
}

.ai-chat__q.is-done::after {
  color: #c3cedd;
}

/* 正在输入 */
.ai-chat__typing {
  display: flex;
  align-items: center;
  gap: 0.08rem;
  align-self: flex-start;
  padding: 0.24rem 0.28rem;
  background: #fff;
  border: 1px solid rgba(11, 44, 92, 0.06);
  border-radius: 0.22rem;
  border-top-left-radius: 0.06rem;
}

.ai-chat__typing span {
  width: 0.1rem;
  height: 0.1rem;
  border-radius: 50%;
  background: #a9c6ee;
  animation: ai-typing 1.2s infinite ease-in-out;
}

.ai-chat__typing span:nth-child(2) {
  animation-delay: 0.16s;
}

.ai-chat__typing span:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes ai-typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  30% {
    transform: translateY(-0.08rem);
    opacity: 1;
  }
}

/* 输入区 */
.ai-chat__foot {
  display: flex;
  align-items: center;
  gap: 0.16rem;
  flex-shrink: 0;
  padding: 0.24rem 0.26rem;
  background: #fff;
  border-top: 1px solid rgba(11, 44, 92, 0.07);
}

.ai-chat__input {
  flex: 1;
  min-height: 0.8rem;
  max-height: 2.2rem;
  padding: 0.2rem 0.26rem;
  background: #f2f6fc;
  border: 1px solid transparent;
  border-radius: 0.2rem;
  font-family: inherit;
  font-size: 0.325rem;
  line-height: 1.5;
  color: #1b2436;
  resize: none;
  overflow-y: auto;
  transition:
    border-color 0.25s ease,
    background 0.25s ease;
}

.ai-chat__input::placeholder {
  color: #a6b4c9;
}

.ai-chat__input:focus {
  background: #fff;
  border-color: rgba(31, 124, 255, 0.45);
}

.ai-chat__send {
  flex-shrink: 0;
  min-height: 0.95rem;
  padding: 0 0.3rem;
  border: none;
  border-radius: 0.2rem;
  cursor: pointer;
  background: linear-gradient(135deg, #1f7cff 0%, #5aa2ff 100%);
  color: #fff;
  font-size: 0.32rem;
  transition:
    opacity 0.25s ease,
    transform 0.25s ease;
}

.ai-chat__send:hover:not(:disabled) {
  transform: translateY(-0.02rem);
}

.ai-chat__send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---------- 移动端 ---------- */
@media (max-width: 1024px) {
  .ai-chat {
    right: 0.24rem;
    bottom: 0.5rem;
  }

  .ai-chat__fab {
    width: 1.15rem;
    height: 1.15rem;
  }

  .ai-chat__panel {
    position: fixed;
    left: 0.2rem;
    right: 0.2rem;
    bottom: calc(0.5rem + 1.15rem + 0.3rem);
    width: auto;
    height: min(11.5rem, 72vh);
    transform-origin: 100% 100%;
  }
}
