/* ==========================================================================
   玄熠数字视觉 · AI 智能客服 样式
   XUANYI DIGITAL VISION — Chat Widget Styles
   沿用 style.css 的 :root 设计令牌，仅使用已定义的变量。
   ========================================================================== */

/* ---------- C1. 容器与启动器 ---------- */
.chat {
  position: fixed;
  right: 30px;
  bottom: 30px;
  z-index: 900;
  pointer-events: none;
}

.chat > * { pointer-events: auto; }

.chat__launcher {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 52px;
  padding: 0 22px 0 16px;
  border: 1px solid rgba(42, 212, 232, 0.4);
  border-radius: 999px;
  background: linear-gradient(140deg, rgba(14, 20, 32, 0.96), rgba(10, 15, 25, 0.96));
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--text);
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 18px 44px -16px rgba(0, 0, 0, 0.95),
              0 0 0 1px rgba(42, 212, 232, 0.1),
              var(--glow-cyan);
  transition: transform 0.45s var(--ease), box-shadow 0.45s var(--ease),
              border-color 0.45s var(--ease), padding 0.35s var(--ease);
}

.chat__launcher::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: var(--grad-brand);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0.55;
  transition: opacity 0.45s var(--ease);
  pointer-events: none;
}

.chat__launcher:hover {
  transform: translateY(-3px);
  border-color: rgba(42, 212, 232, 0.7);
  box-shadow: 0 26px 60px -18px rgba(0, 0, 0, 0.98),
              0 0 34px -6px rgba(42, 212, 232, 0.65);
}

.chat__launcher:hover::before { opacity: 1; }

.chat__launcher-ico {
  position: relative;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: none;
}

.chat__launcher-ico svg {
  position: absolute;
  width: 24px;
  height: 24px;
  color: var(--cyan);
  transition: opacity 0.3s var(--ease), transform 0.35s var(--ease);
}

.chat__launcher .ico-close { opacity: 0; transform: rotate(-90deg) scale(0.7); }
.chat__launcher.is-open .ico-chat { opacity: 0; transform: rotate(90deg) scale(0.7); }
.chat__launcher.is-open .ico-close { opacity: 1; transform: none; }

/* 未读提示小圆点 */
.chat__dot {
  position: absolute;
  top: 2px;
  right: 8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--magenta);
  box-shadow: 0 0 0 3px rgba(5, 7, 12, 0.9), 0 0 14px rgba(217, 70, 239, 0.9);
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.4s var(--ease), transform 0.4s var(--ease);
}

.chat__dot.is-on { opacity: 1; transform: none; animation: chat-dot 2.2s var(--ease) infinite; }

@keyframes chat-dot {
  0%, 100% { box-shadow: 0 0 0 3px rgba(5, 7, 12, 0.9), 0 0 14px rgba(217, 70, 239, 0.9); }
  50%      { box-shadow: 0 0 0 3px rgba(5, 7, 12, 0.9), 0 0 22px rgba(217, 70, 239, 1); }
}

/* 回到顶部按钮上移，给客服让位 */
body.chat-ready .totop { bottom: 98px; }

/* ---------- C2. 对话面板 ---------- */
.chat__panel {
  position: absolute;
  right: 0;
  bottom: 66px;
  width: 384px;
  max-width: calc(100vw - 60px);
  height: min(580px, calc(100vh - 130px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: linear-gradient(170deg, rgba(12, 17, 28, 0.97), rgba(5, 7, 12, 0.99));
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(42, 212, 232, 0.08);
  opacity: 0;
  transform: translateY(18px) scale(0.96);
  transform-origin: 100% 100%;
  transition: opacity 0.36s var(--ease), transform 0.44s var(--ease);
}

.chat__panel.is-show { opacity: 1; transform: none; }

/* 关键：作者样式里的 display:flex 会盖掉浏览器默认的 [hidden]{display:none}，
   必须显式补回，否则面板关闭时只是「透明」而非「不存在」，
   会以 384×580 的透明盒子拦截页面点击。 */
.chat__panel[hidden] { display: none; }

/* 关闭动画期间也不接收点击 */
.chat__panel { pointer-events: none; }
.chat__panel.is-show { pointer-events: auto; }

/* 顶部霓虹细线 */
.chat__panel::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--grad-line);
  z-index: 3;
}

/* ---------- C3. 头部 ---------- */
.chat__head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 15px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  flex: none;
}

.chat__avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 12px;
  background: var(--grad-brand);
  color: #fff;
  font-size: 17px;
  font-weight: 800;
  box-shadow: 0 8px 22px -8px rgba(42, 212, 232, 0.8);
}

.chat__id { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.chat__id b { font-size: 15px; font-weight: 700; letter-spacing: 0.03em; }
.chat__id i {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-style: normal;
  color: var(--text-muted);
  letter-spacing: 0.06em;
}

.chat__id i em {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #2ee6a8;
  box-shadow: 0 0 10px rgba(46, 230, 168, 0.9);
  animation: chat-live 2s var(--ease) infinite;
}

@keyframes chat-live { 50% { opacity: 0.35; } }

.chat__close {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.3s var(--ease);
}

.chat__close svg { width: 16px; height: 16px; }
.chat__close:hover { color: var(--text); background: var(--surface-2); border-color: var(--line-strong); }

/* ---------- C4. 消息区 ---------- */
.chat__log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 18px 6px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
}

.chat__log::-webkit-scrollbar { width: 5px; }
.chat__log::-webkit-scrollbar-track { background: transparent; }
.chat__log::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 99px;
}
.chat__log::-webkit-scrollbar-thumb:hover { background: rgba(42, 212, 232, 0.5); }

.chat__msg {
  display: flex;
  animation: chat-in 0.42s var(--ease) both;
}

@keyframes chat-in {
  from { opacity: 0; transform: translateY(10px); }
}

.chat__msg--bot { justify-content: flex-start; }
.chat__msg--me  { justify-content: flex-end; }

.chat__bubble {
  max-width: 86%;
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.72;
  letter-spacing: 0.015em;
  word-break: break-word;
}

.chat__msg--bot .chat__bubble {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
  color: var(--text-soft);
}

.chat__msg--bot .chat__bubble strong { color: var(--text); font-weight: 700; }

.chat__msg--me .chat__bubble {
  background: linear-gradient(135deg, rgba(42, 212, 232, 0.9), rgba(47, 123, 255, 0.92));
  border-bottom-right-radius: 5px;
  color: #05121a;
  font-weight: 600;
}

.chat__bubble a {
  color: var(--cyan);
  text-decoration: none;
  border-bottom: 1px solid rgba(42, 212, 232, 0.4);
  transition: border-color 0.3s;
}

.chat__bubble a:hover { border-bottom-color: var(--cyan); }

.chat__msg--me .chat__bubble a { color: #05121a; border-bottom-color: rgba(5, 18, 26, 0.4); }

/* 相关页面按钮 */
.chat__page {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: -2px;
  padding: 9px 15px;
  border: 1px solid rgba(42, 212, 232, 0.32);
  border-radius: 999px;
  background: rgba(42, 212, 232, 0.07);
  color: var(--cyan);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  letter-spacing: 0.02em;
  transition: all 0.35s var(--ease);
}

.chat__page svg { width: 14px; height: 14px; transition: transform 0.35s var(--ease); }
.chat__page:hover {
  background: rgba(42, 212, 232, 0.15);
  border-color: var(--cyan);
  box-shadow: 0 10px 26px -12px rgba(42, 212, 232, 0.8);
}
.chat__page:hover svg { transform: translateX(3px); }

/* 输入中指示器 */
.chat__typing .chat__bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 16px;
}

.chat__typing .chat__bubble i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: chat-blink 1.3s var(--ease) infinite;
}

.chat__typing .chat__bubble i:nth-child(2) { animation-delay: 0.18s; }
.chat__typing .chat__bubble i:nth-child(3) { animation-delay: 0.36s; }

@keyframes chat-blink {
  0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
  30%           { opacity: 1;    transform: translateY(-3px); }
}

/* ---------- C5. 快捷问题 ---------- */
.chat__quick {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 6px 18px 12px;
  flex: none;
}

.chat__quick:empty { display: none; }

.chat__chip {
  padding: 7px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12.5px;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: all 0.32s var(--ease);
  animation: chat-in 0.4s var(--ease) both;
}

.chat__chip:hover {
  color: var(--text);
  border-color: rgba(42, 212, 232, 0.55);
  background: rgba(42, 212, 232, 0.08);
  transform: translateY(-1px);
}

/* ---------- C6. 输入区 ---------- */
.chat__ask {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 12px 14px 12px 18px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  flex: none;
}

.chat__input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  outline: none;
}

.chat__input::placeholder { color: var(--text-faint); }

.chat__send {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border: none;
  border-radius: 11px;
  background: var(--grad-brand);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 10px 24px -10px rgba(42, 212, 232, 0.9);
  transition: all 0.35s var(--ease);
}

.chat__send svg { width: 17px; height: 17px; }
.chat__send:hover { transform: translateY(-2px) scale(1.04); }
.chat__send:active { transform: scale(0.96); }

.chat__foot {
  padding: 0 18px 12px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-faint);
  letter-spacing: 0.02em;
  flex: none;
}

/* ---------- C7. 响应式 ---------- */
@media (max-width: 720px) {
  .chat { right: 16px; bottom: 16px; }

  /* 手机上收成圆形按钮，避免遮挡内容 */
  .chat__launcher { width: 56px; height: 56px; padding: 0; justify-content: center; gap: 0; }
  .chat__launcher-txt { display: none; }
  .chat__launcher-ico { width: 28px; height: 28px; }
  .chat__launcher-ico svg { width: 26px; height: 26px; }
  .chat__dot { top: 4px; right: 4px; }

  body.chat-ready .totop { bottom: 84px; right: 16px; }

  .chat__panel {
    position: fixed;
    right: 12px;
    left: 12px;
    bottom: 84px;
    width: auto;
    max-width: none;
    height: min(70vh, 560px);
    height: min(70dvh, 560px);
    transform-origin: 100% 100%;
  }

  .chat__bubble { max-width: 92%; }
  .chat__log { padding: 16px 14px 4px; }
  .chat__quick { padding: 6px 14px 10px; }
  .chat__ask { padding: 10px 12px 10px 14px; }
  .chat__foot { padding: 0 14px 10px; }
}

@media (max-width: 380px) {
  .chat__id i { display: none; }
}

/* ---------- C8. 无障碍 / 减弱动效 ---------- */
@media (prefers-reduced-motion: reduce) {
  .chat__launcher, .chat__panel, .chat__chip, .chat__send, .chat__page { transition: none; }
  .chat__msg, .chat__chip { animation: none; }
  .chat__dot.is-on, .chat__id i em { animation: none; }
  .chat__typing .chat__bubble i { animation-duration: 0.01ms; }
}

@media print {
  .chat { display: none !important; }
}
