/* ==========================================================================
   AI 桌宠 · 栗栗
   与 premium.css 共用色板，独立文件便于单独升级
   ========================================================================== */

.ai-pet,
.ai-chat {
  --ai-gold: #c8a96b;
  --ai-gold-light: #e2c894;
  --ai-ivory: #f0e9da;
  --ai-muted: #96a3a8;
  --ai-ink: #070c0f;
  --ai-panel: #0c151a;
  --ai-line: rgba(200, 169, 107, 0.24);
  --ai-serif: "方正小标宋简体", "FZXiaoBiaoSongJian", "Source Han Serif SC", "Noto Serif SC", "Songti SC", "SimSun", serif;
  --ai-sans: "宋体", "SimSun", "Songti SC", "STSong", serif;
}

.ai-pet[hidden],
.ai-chat[hidden],
.ai-chat__backdrop[hidden],
.ai-chat__quick[hidden] {
  display: none !important;
}

/* ---------- 桌宠主体 ---------- */
.ai-pet {
  position: fixed;
  left: 26px;
  bottom: 20px;
  z-index: 1300;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  pointer-events: none;
  font-family: var(--ai-sans);
  transition: opacity 0.25s ease, visibility 0.25s;
}

body.no-scroll .ai-pet {
  opacity: 0;
  visibility: hidden;
}

.ai-pet.is-right {
  left: auto;
  right: 26px;
  align-items: flex-end;
}

.ai-pet > * {
  pointer-events: auto;
}

.ai-pet__button {
  position: relative;
  display: block;
  width: clamp(104px, 9vw, 138px);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  animation: aiPetFloat 4.6s ease-in-out infinite;
  transform-origin: 50% 100%;
}

.ai-pet__button:focus-visible {
  outline: 2px solid var(--ai-gold);
  outline-offset: 6px;
  border-radius: 20px;
}

.ai-pet__halo {
  position: absolute;
  left: 50%;
  bottom: 6%;
  width: 118%;
  height: 82%;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 58%, rgba(200, 169, 107, 0.24), rgba(200, 169, 107, 0.06) 46%, transparent 70%);
  filter: blur(4px);
  opacity: 0.85;
  z-index: 0;
  animation: aiPetHalo 4.6s ease-in-out infinite;
}

.ai-pet__img {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: auto;
  transform-origin: 50% 100%;
  transition: transform 0.35s cubic-bezier(0.2, 0.7, 0.2, 1), filter 0.35s ease;
  filter: drop-shadow(0 12px 16px rgba(0, 0, 0, 0.26));
}

.ai-pet__button:hover .ai-pet__img,
.ai-pet__button:focus-visible .ai-pet__img {
  transform: translateY(-4px) scale(1.025);
  filter: drop-shadow(0 18px 22px rgba(0, 0, 0, 0.3));
}

.ai-pet__button.is-waving .ai-pet__img {
  animation: aiPetWave 0.9s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

.ai-pet__badge {
  position: absolute;
  top: 9%;
  right: 1%;
  z-index: 2;
  padding: 3px 7px 2px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 999px;
  background: linear-gradient(135deg, #e8d3a2, #c8a96b 58%, #a5844b);
  box-shadow: 0 4px 12px rgba(200, 169, 107, 0.32);
  color: #1a1206;
  font-family: var(--ai-sans);
  font-size: 9px;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: 0.09em;
  animation: aiPetBadge 3.6s ease-in-out infinite;
}

.ai-pet__hint {
  position: absolute;
  left: 50%;
  bottom: -2px;
  z-index: 2;
  transform: translate(-50%, 6px);
  padding: 4px 10px;
  border: 1px solid rgba(200, 169, 107, 0.28);
  border-radius: 999px;
  background: rgba(7, 12, 15, 0.82);
  color: var(--ai-gold-light);
  font-size: 10px;
  line-height: 1.4;
  letter-spacing: 0.12em;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  backdrop-filter: blur(8px);
}

.ai-pet__button:hover .ai-pet__hint,
.ai-pet__button:focus-visible .ai-pet__hint {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- 问候气泡 ---------- */
.ai-pet__greeting {
  position: relative;
  width: max-content;
  max-width: min(286px, calc(100vw - 52px));
  margin-bottom: 12px;
  padding: 15px 34px 14px 17px;
  border: 1px solid var(--ai-line);
  border-radius: 14px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.018)),
    rgba(8, 14, 17, 0.9);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  color: var(--ai-ivory);
  backdrop-filter: blur(16px);
  opacity: 0;
  transform: translateY(10px) scale(0.96);
  transform-origin: bottom left;
  transition: opacity 0.32s ease, transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
  pointer-events: none;
}

.ai-pet.is-right .ai-pet__greeting {
  transform-origin: bottom right;
}

.ai-pet__greeting.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.ai-pet__greeting::after {
  content: "";
  position: absolute;
  left: 30px;
  bottom: -7px;
  width: 12px;
  height: 12px;
  border-right: 1px solid var(--ai-line);
  border-bottom: 1px solid var(--ai-line);
  background: #0a1114;
  transform: rotate(45deg);
}

.ai-pet.is-right .ai-pet__greeting::after {
  left: auto;
  right: 30px;
}

.ai-pet__greeting-name {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 6px;
  color: var(--ai-gold-light);
  font-family: var(--ai-serif);
  font-size: 12px;
  letter-spacing: 0.16em;
}

.ai-pet__greeting-name::before {
  content: "";
  width: 14px;
  height: 1px;
  background: var(--ai-gold);
}

.ai-pet__greeting-text {
  margin: 0;
  color: rgba(240, 233, 218, 0.92);
  font-size: 13px;
  line-height: 1.8;
  letter-spacing: 0.015em;
}

.ai-pet__greeting-hint {
  display: block;
  margin-top: 8px;
  color: var(--ai-muted);
  font-size: 10px;
  letter-spacing: 0.12em;
}

.ai-pet__greeting-hint::after {
  content: " →";
  color: var(--ai-gold);
}

.ai-pet__greeting-close {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  background: none;
  color: rgba(240, 233, 218, 0.48);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.2s ease;
}

.ai-pet__greeting-close:hover,
.ai-pet__greeting-close:focus-visible {
  color: var(--ai-gold-light);
}

/* ---------- 对话面板 ---------- */
.ai-chat {
  position: fixed;
  left: 26px;
  bottom: 196px;
  z-index: 1310;
  display: flex;
  flex-direction: column;
  width: min(392px, calc(100vw - 52px));
  height: min(560px, calc(100vh - 238px));
  min-height: 380px;
  overflow: hidden;
  border: 1px solid var(--ai-line);
  border-radius: 18px;
  background:
    radial-gradient(120% 80% at 0% 0%, rgba(200, 169, 107, 0.1), transparent 54%),
    linear-gradient(165deg, rgba(14, 23, 28, 0.985), rgba(6, 11, 14, 0.99));
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.54), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  color: var(--ai-ivory);
  font-family: var(--ai-sans);
  backdrop-filter: blur(20px);
  transform-origin: bottom left;
  animation: aiChatIn 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.ai-chat.is-right {
  left: auto;
  right: 26px;
  transform-origin: bottom right;
}

.ai-chat__head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 15px 16px 13px;
  border-bottom: 1px solid rgba(200, 169, 107, 0.16);
}

.ai-chat__head::after {
  content: "";
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(200, 169, 107, 0.55), transparent);
}

.ai-chat__avatar {
  position: relative;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  overflow: hidden;
  border: 1px solid rgba(200, 169, 107, 0.34);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
}

.ai-chat__avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform: scale(1.14);
}

.ai-chat__meta {
  flex: 1 1 auto;
  min-width: 0;
}

.ai-chat__name {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--ai-ivory);
  font-family: var(--ai-serif);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.1em;
}

.ai-chat__status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
  color: var(--ai-muted);
  font-size: 10px;
  letter-spacing: 0.1em;
}

.ai-chat__status::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #7ec7a2;
  box-shadow: 0 0 0 3px rgba(126, 199, 162, 0.12);
}

.ai-chat__close {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.03);
  color: rgba(240, 233, 218, 0.62);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.ai-chat__close:hover,
.ai-chat__close:focus-visible {
  border-color: rgba(200, 169, 107, 0.42);
  background: rgba(200, 169, 107, 0.08);
  color: var(--ai-gold-light);
}

.ai-chat__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 16px 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(200, 169, 107, 0.32) transparent;
}

.ai-chat__body::-webkit-scrollbar {
  width: 5px;
}

.ai-chat__body::-webkit-scrollbar-thumb {
  border-radius: 99px;
  background: rgba(200, 169, 107, 0.28);
}

.ai-msg {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  margin-bottom: 14px;
  animation: aiMsgIn 0.28s ease both;
}

.ai-msg--user {
  flex-direction: row-reverse;
}

.ai-msg__avatar {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  overflow: hidden;
  border: 1px solid rgba(200, 169, 107, 0.26);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
}

.ai-msg__avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform: scale(1.16);
}

.ai-msg--user .ai-msg__avatar {
  display: none;
}

.ai-msg__main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  max-width: 79%;
  min-width: 0;
}

.ai-msg--user .ai-msg__main {
  align-items: flex-end;
}

.ai-msg__bubble {
  max-width: 100%;
  padding: 10px 13px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 13px 13px 13px 4px;
  background: rgba(255, 255, 255, 0.052);
  color: rgba(240, 233, 218, 0.94);
  font-size: 13.5px;
  line-height: 1.78;
  letter-spacing: 0.01em;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.ai-msg--user .ai-msg__bubble {
  border: 1px solid rgba(226, 200, 148, 0.26);
  border-radius: 13px 13px 4px 13px;
  background: linear-gradient(135deg, rgba(200, 169, 107, 0.95), rgba(160, 126, 68, 0.96));
  color: #171006;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.16);
}

.ai-msg__bubble.is-error {
  border-color: rgba(207, 120, 104, 0.3);
  background: rgba(120, 48, 40, 0.16);
  color: #e8b7ad;
}

.ai-msg__time {
  margin-top: 4px;
  color: rgba(150, 163, 168, 0.5);
  font-size: 9px;
  letter-spacing: 0.06em;
}

/* 相关馆藏 / 追问建议 / 消息操作 */
.ai-msg__refs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 2px 0;
}

.ai-msg__refs-label {
  width: 100%;
  color: rgba(200, 169, 107, 0.7);
  font-size: 10px;
  letter-spacing: 0.16em;
}

.ai-msg__ref {
  display: inline-flex;
  max-width: 100%;
  padding: 4px 9px;
  overflow: hidden;
  border: 1px solid rgba(200, 169, 107, 0.24);
  border-radius: 99px;
  background: rgba(200, 169, 107, 0.06);
  color: rgba(226, 200, 148, 0.92);
  font-size: 11px;
  line-height: 1.5;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.ai-msg__ref:hover,
.ai-msg__ref:focus-visible {
  border-color: rgba(200, 169, 107, 0.5);
  background: rgba(200, 169, 107, 0.13);
}

.ai-msg__follow {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ai-msg__follow-chip {
  padding: 4px 10px;
  border: 1px dashed rgba(200, 169, 107, 0.26);
  border-radius: 99px;
  background: transparent;
  color: rgba(226, 200, 148, 0.82);
  font-family: var(--ai-sans);
  font-size: 11px;
  line-height: 1.5;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.ai-msg__follow-chip:hover,
.ai-msg__follow-chip:focus-visible {
  border-color: rgba(200, 169, 107, 0.5);
  background: rgba(200, 169, 107, 0.1);
  color: var(--ai-gold-light);
}

.ai-msg__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ai-msg__act {
  padding: 2px 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 99px;
  background: transparent;
  color: rgba(190, 203, 210, 0.56);
  font-family: var(--ai-sans);
  font-size: 10px;
  line-height: 1.5;
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.ai-msg__act:hover,
.ai-msg__act:focus-visible,
.ai-msg__act.is-active {
  border-color: rgba(200, 169, 107, 0.4);
  background: rgba(200, 169, 107, 0.08);
  color: var(--ai-gold-light);
}

.ai-msg__act:disabled {
  cursor: default;
  opacity: 0.6;
}

.ai-chat__typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 1px;
}

.ai-chat__typing i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ai-gold-light);
  opacity: 0.36;
  animation: aiTyping 1.2s ease-in-out infinite;
}

.ai-chat__typing i:nth-child(2) {
  animation-delay: 0.16s;
}

.ai-chat__typing i:nth-child(3) {
  animation-delay: 0.32s;
}

/* ---------- 快捷问题 ---------- */
.ai-chat__quick {
  display: flex;
  gap: 7px;
  padding: 4px 16px 10px;
  overflow-x: auto;
  scrollbar-width: none;
}

.ai-chat__quick::-webkit-scrollbar {
  display: none;
}

.ai-chat__chip {
  flex: 0 0 auto;
  padding: 6px 11px;
  border: 1px solid rgba(200, 169, 107, 0.24);
  border-radius: 999px;
  background: rgba(200, 169, 107, 0.045);
  color: rgba(226, 200, 148, 0.86);
  font-family: var(--ai-sans);
  font-size: 11px;
  line-height: 1.4;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
  white-space: nowrap;
}

.ai-chat__chip:hover,
.ai-chat__chip:focus-visible {
  border-color: rgba(200, 169, 107, 0.5);
  background: rgba(200, 169, 107, 0.12);
  color: var(--ai-gold-light);
}

/* ---------- 输入区 ---------- */
.ai-chat__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px 8px;
  border-top: 1px solid rgba(200, 169, 107, 0.14);
  background: rgba(0, 0, 0, 0.12);
}

.ai-chat__input {
  flex: 1 1 auto;
  min-height: 40px;
  max-height: 110px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  outline: none;
  background: rgba(255, 255, 255, 0.045);
  color: var(--ai-ivory);
  font-family: var(--ai-sans);
  font-size: 13px;
  line-height: 1.55;
  resize: none;
  transition: border-color 0.2s ease, background 0.2s ease;
  scrollbar-width: thin;
}

.ai-chat__input::placeholder {
  color: rgba(150, 163, 168, 0.62);
}

.ai-chat__input:focus {
  border-color: rgba(200, 169, 107, 0.5);
  background: rgba(255, 255, 255, 0.06);
}

.ai-chat__send {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 40px;
  padding: 0;
  border: 1px solid rgba(226, 200, 148, 0.4);
  border-radius: 10px;
  background: linear-gradient(135deg, #dfc793, #c8a96b 62%, #a9844b);
  color: #171006;
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease, filter 0.2s ease;
}

.ai-chat__send.is-stop svg {
  display: none;
}

.ai-chat__send.is-stop::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: #171006;
}

.ai-chat__send svg {
  width: 17px;
  height: 17px;
}

.ai-chat__send:hover,
.ai-chat__send:focus-visible {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.ai-chat__send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  filter: none;
}

.ai-chat__note {
  margin: 0;
  padding: 0 16px 10px;
  color: rgba(150, 163, 168, 0.52);
  font-size: 9px;
  line-height: 1.5;
  letter-spacing: 0.07em;
  text-align: center;
}

/* ---------- 移动端 ---------- */
@media (max-width: 760px) {
  .ai-pet {
    left: auto;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    align-items: flex-end;
  }

  .ai-pet.is-right {
    right: 10px;
  }

  .ai-pet__button {
    width: 64px;
  }

  .ai-pet__badge {
    top: 8%;
    right: 0;
    padding: 2px 5px 1px;
    font-size: 8px;
  }

  .ai-pet__hint {
    display: none;
  }

  .ai-pet__greeting {
    max-width: min(268px, calc(100vw - 40px));
    transform-origin: bottom right;
  }

  .ai-pet__greeting::after {
    left: auto;
    right: 24px;
  }

  .ai-chat {
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    width: auto;
    height: min(76vh, 620px);
    min-height: 420px;
    border-radius: 16px;
  }

  .ai-chat.is-right {
    left: 10px;
    right: 10px;
  }

  .ai-msg__main {
    max-width: 86%;
  }

  .ai-chat__body {
    padding: 14px 12px 6px;
  }

  .ai-chat__input {
    font-size: 16px;
  }

  .ai-msg__bubble {
    font-size: 14px;
  }

  .ai-msg__act {
    padding: 4px 10px;
    font-size: 11px;
  }

  .ai-msg__ref,
  .ai-msg__follow-chip {
    font-size: 11.5px;
  }

  .ai-msg__refs,
  .ai-msg__follow {
    gap: 5px;
  }

  body.ai-chat-open {
    overflow: hidden;
  }

  body.ai-chat-open::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 1305;
    background: rgba(3, 7, 9, 0.56);
    backdrop-filter: blur(3px);
  }

  body.ai-chat-open .ai-pet {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
}

/* 小屏：缩小桌宠，会员中心订单表区域不显示，避免遮挡订单号与状态 */
@media (max-width: 640px) {
  .ai-pet {
    right: 8px;
  }

  .ai-pet__button {
    width: 54px;
  }

  body.member-ucenter .ai-pet {
    display: none !important;
  }
}

@media (max-width: 380px) {
  .ai-chat {
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(82vh - env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    border-radius: 16px 16px 0 0;
  }
}

/* ---------- 动画 ---------- */
@keyframes aiPetFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes aiPetHalo {
  0%, 100% { opacity: 0.62; transform: translateX(-50%) scale(0.96); }
  50% { opacity: 0.95; transform: translateX(-50%) scale(1.03); }
}

@keyframes aiPetBadge {
  0%, 100% { transform: translateY(0); box-shadow: 0 4px 12px rgba(200, 169, 107, 0.28); }
  50% { transform: translateY(-2px); box-shadow: 0 7px 16px rgba(200, 169, 107, 0.42); }
}

@keyframes aiPetWave {
  0%, 100% { transform: rotate(0deg) translateY(0); }
  20% { transform: rotate(-4deg) translateY(-3px); }
  45% { transform: rotate(4deg) translateY(-6px); }
  70% { transform: rotate(-2deg) translateY(-3px); }
}

@keyframes aiChatIn {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes aiMsgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes aiTyping {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
  .ai-pet__button,
  .ai-pet__halo,
  .ai-pet__badge,
  .ai-pet__button.is-waving .ai-pet__img,
  .ai-chat,
  .ai-msg,
  .ai-chat__typing i {
    animation: none !important;
  }

  .ai-pet__img,
  .ai-pet__greeting,
  .ai-chat__input,
  .ai-chat__send {
    transition: none !important;
  }
}
