/* ==========================================================================
   官网悬浮 AI 助手 —— 右侧抽屉面板
   与 floating-unb3.css 搭配：那里只负责右下角的悬浮球，本文件负责点开后的面板。
   由 ai-assistant-unb1.js 动态创建 DOM，因此所有样式都挂在 .ub-ai* 命名空间下。
   ========================================================================== */

.ub-ai {
  position: fixed;
  inset: 0;
  z-index: 9998;
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
  padding: 0 20px 24px;
  pointer-events: none;
}

.ub-ai[hidden] {
  display: none;
}

/* 面板本体：桌面端右下角悬浮卡片，窄屏铺满；遮罩不做，点击外部直接关闭 */
.ub-ai-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(404px, calc(100vw - 40px));
  height: min(660px, calc(100vh - 120px));
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.18), 0 4px 12px rgba(15, 23, 42, 0.08);
  overflow: hidden;
  pointer-events: auto;
  transform: translateY(16px) scale(0.98);
  opacity: 0;
  transition: transform 0.24s cubic-bezier(0.22, 0.61, 0.36, 1), opacity 0.2s ease;
}

.ub-ai.is-open .ub-ai-panel {
  transform: none;
  opacity: 1;
}

/* ------------------------------ 头部 ------------------------------ */

.ub-ai-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid rgba(15, 23, 42, 0.07);
}

.ub-ai-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  color: #2d5aff;
  font-size: 15px;
  font-weight: 700;
}

/* 头部角标与消息头像共用品牌 AI 图标，加载失败时才回退到文字 */
.ub-ai-mark img,
.ub-ai-avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.ub-ai-titles {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.ub-ai-title {
  font-size: 14.5px;
  font-weight: 700;
  color: #0f172a;
  letter-spacing: 0.01em;
}

.ub-ai-sub {
  font-size: 11.5px;
  color: #8a94a6;
}

.ub-ai-close {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #64748b;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease;
}

.ub-ai-close:hover {
  background: rgba(15, 23, 42, 0.06);
  color: #0f172a;
}

/* ------------------------------ 消息区 ------------------------------ */

.ub-ai-body {
  flex: 1;
  min-height: 0;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #fbfcfe;
  scrollbar-width: thin;
}

.ub-ai-body::-webkit-scrollbar {
  width: 6px;
}

.ub-ai-body::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.16);
  border-radius: 999px;
}

.ub-ai-hello {
  padding: 2px 2px 4px;
}

.ub-ai-hello h4 {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 700;
  color: #0f172a;
}

.ub-ai-hello p {
  margin: 0 0 14px;
  font-size: 12.8px;
  line-height: 1.7;
  color: #5b6678;
}

.ub-ai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ub-ai-chip {
  padding: 7px 12px;
  border: 1px solid rgba(45, 90, 255, 0.18);
  border-radius: 999px;
  background: #fff;
  color: #2d5aff;
  font-family: inherit;
  font-size: 12.3px;
  line-height: 1.3;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.ub-ai-chip:hover {
  background: rgba(45, 90, 255, 0.06);
  border-color: rgba(45, 90, 255, 0.36);
  transform: translateY(-1px);
}

.ub-ai-msg {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 14px;
}

/* 用户消息整体靠右：用 row-reverse 让头像跟到右侧，不使用 justify-content */
.ub-ai-msg.is-user {
  flex-direction: row-reverse;
}

.ub-ai-avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 26px;
  height: 26px;
  margin-top: 2px;
  color: #2d5aff;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1;
  user-select: none;
}

.ub-ai-avatar svg {
  width: 15px;
  height: 15px;
}

/* 访客头像：真实头像图 / 首字母 / 人形图标，只有这一侧需要底色卡块 */
.ub-ai-msg.is-user .ub-ai-avatar {
  border-radius: 9px;
  overflow: hidden;
  background: #eaf0fa;
  color: #6b7a90;
}

.ub-ai-bubble {
  max-width: calc(100% - 34px);
  padding: 10px 13px;
  border-radius: 15px;
  font-size: 13.4px;
  line-height: 1.72;
  color: #16233a;
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.07);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  white-space: pre-wrap;
  word-break: break-word;
}

.ub-ai-msg.is-user .ub-ai-bubble {
  background: linear-gradient(135deg, #3d7bff, #2d5aff);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 16px rgba(45, 90, 255, 0.24);
}

.ub-ai-bubble strong {
  font-weight: 700;
}

.ub-ai-bubble code {
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(15, 23, 42, 0.06);
  font-size: 12.4px;
}

.ub-ai-bubble a {
  color: #2d5aff;
  text-decoration: underline;
}

/* 等待首个 token 的三点动效 */
.ub-ai-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  height: 18px;
}

.ub-ai-typing i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #98a3b6;
  animation: ubAiBlink 1.1s infinite ease-in-out;
}

.ub-ai-typing i:nth-child(2) {
  animation-delay: 0.16s;
}

.ub-ai-typing i:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes ubAiBlink {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

.ub-ai-note {
  margin: 8px 2px 0;
  font-size: 11.8px;
  line-height: 1.6;
  color: #94a0b3;
}

.ub-ai-note.is-error {
  color: #d14343;
}

/* ------------------------------ 输入区 ------------------------------ */

.ub-ai-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid rgba(15, 23, 42, 0.07);
  background: #fff;
}

.ub-ai-input {
  flex: 1;
  min-height: 42px;
  max-height: 116px;
  padding: 11px 12px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 12px;
  background: #fff;
  color: #16233a;
  font-family: inherit;
  font-size: 13.4px;
  line-height: 1.5;
  resize: none;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.ub-ai-input:focus {
  border-color: rgba(45, 90, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(45, 90, 255, 0.12);
}

.ub-ai-send {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, #3d7bff, #2d5aff);
  color: #fff;
  cursor: pointer;
  transition: transform 0.16s ease, opacity 0.16s ease, box-shadow 0.16s ease;
}

.ub-ai-send:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(45, 90, 255, 0.28);
}

.ub-ai-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ub-ai-send svg {
  width: 18px;
  height: 18px;
}

.ub-ai-foot {
  margin: 0;
  padding: 0 14px 10px;
  background: #fff;
  font-size: 11px;
  color: #a2acbd;
  text-align: center;
}

/* 面板打开时收起悬浮球，避免与面板底部重叠 */
body.ub-ai-open .ub-ai-fab {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.9);
}

.ub-ai-fab {
  transition: opacity 0.2s ease, transform 0.2s ease;
}

/* ------------------------------ 移动端 ------------------------------ */

@media (max-width: 640px) {
  .ub-ai {
    padding: 0;
    align-items: stretch;
  }

  .ub-ai-panel {
    width: 100%;
    height: 100%;
    border-radius: 0;
  }

  .ub-ai-head {
    padding-top: max(14px, env(safe-area-inset-top));
  }

  .ub-ai-form {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .ub-ai-bubble {
    max-width: calc(100% - 34px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ub-ai-panel,
  .ub-ai-fab {
    transition: none;
  }

  .ub-ai-typing i {
    animation: none;
  }
}
