/* ==========================================================================
   数字人「小象」：右下角常驻形象 + 问答面板
   只在简体、繁体中文页面加载（views/layout.html 的 assistant 标记）。颜色取自 site.css 的变量。
   形象是原创 SVG（views/partials/assistant-mascot.html），三种状态：待机、思考（查找依据）、回答。
   ========================================================================== */

/* ---------- 形象 ---------- */
/* 形象外观（配色、描边）已移到 site.css 的「小象形象」一节：产品页也要用。
   这里只保留挂件的动效与状态。 */

.xx-mascot__body,
.xx-mascot__ear,
.xx-mascot__eyes,
.xx-mascot__trunk {
  transform-box: fill-box;
  transform-origin: center;
}
.xx-mascot__trunk { transform-origin: 20% 0%; }
.xx-mascot__ear--left { transform-origin: 90% 50%; }
.xx-mascot__ear--right { transform-origin: 10% 50%; }

/* 待机：轻轻浮动、定时眨眼、偶尔扇耳朵 */
.xx-mascot__body { animation: xx-float 3.4s ease-in-out infinite; }
.xx-mascot__eyes { animation: xx-blink 4.6s infinite; }
.xx-mascot__ear--left { animation: xx-ear-left 6s ease-in-out infinite; }
.xx-mascot__ear--right { animation: xx-ear-right 6s ease-in-out infinite; }

/* 思考：头顶冒泡、耳朵扇得更快 */
.is-thinking .xx-mascot__thinking circle { animation: xx-dot 1.2s infinite; }
.is-thinking .xx-mascot__thinking circle:nth-child(2) { animation-delay: 0.2s; }
.is-thinking .xx-mascot__thinking circle:nth-child(3) { animation-delay: 0.4s; }
.is-thinking .xx-mascot__ear--left,
.is-thinking .xx-mascot__ear--right { animation-duration: 1.4s; }

/* 回答：象鼻摆动、右侧出现声波 */
.is-speaking .xx-mascot__trunk { animation: xx-trunk 0.9s ease-in-out infinite; }
.is-speaking .xx-mascot__waves path { animation: xx-wave 1.1s ease-out infinite; }
.is-speaking .xx-mascot__waves path:nth-child(2) { animation-delay: 0.25s; }

@keyframes xx-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-2.5px); } }
@keyframes xx-blink { 0%, 94%, 100% { transform: scaleY(1); } 96.5% { transform: scaleY(0.12); } }
@keyframes xx-ear-left { 0%, 82%, 100% { transform: rotate(0deg); } 88% { transform: rotate(-9deg); } 94% { transform: rotate(3deg); } }
@keyframes xx-ear-right { 0%, 82%, 100% { transform: rotate(0deg); } 88% { transform: rotate(9deg); } 94% { transform: rotate(-3deg); } }
@keyframes xx-dot { 0%, 100% { opacity: 0.15; } 40% { opacity: 0.9; } }
@keyframes xx-trunk { 0%, 100% { transform: rotate(0deg); } 50% { transform: rotate(-5deg); } }
@keyframes xx-wave { 0% { opacity: 0; } 35% { opacity: 0.85; } 100% { opacity: 0; } }

/* ---------- 右下角常驻 ---------- */
.xx-dock {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 45;
  display: flex;
  align-items: flex-end;
  pointer-events: none;
  gap: 6px;
  animation: xx-dock-in 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}

.xx-dock button {
  pointer-events: auto;
}

@keyframes xx-dock-in {
  from { opacity: 0; transform: translateY(16px) scale(0.9); }
  to { opacity: 1; transform: none; }
}

.xx-fab {
  position: relative;
  width: 78px;
  height: 78px;
  padding: 0;
  border-radius: 50%;
  filter: drop-shadow(0 8px 16px rgba(31, 64, 55, 0.3));
  transition: transform 0.2s ease, filter 0.2s ease;
}

.xx-fab:hover {
  transform: translateY(-3px) scale(1.04);
  filter: drop-shadow(0 12px 22px rgba(31, 64, 55, 0.38));
}

.xx-fab:active { transform: scale(0.96); }

.xx-fab:focus-visible {
  outline: 3px solid var(--jade-500);
  outline-offset: 3px;
  border-radius: 50%;
}

.xx-fab-badge {
  position: absolute;
  right: -2px;
  top: 2px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: var(--cinnabar);
  color: #fff;
  font-family: var(--serif);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  box-shadow: 0 4px 10px rgba(181, 64, 47, 0.35);
  outline: 1px solid rgba(255, 255, 255, 0.5);
  outline-offset: -3px;
}

/* 招呼气泡 */
.xx-teaser {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 4px;
  max-width: 236px;
  margin-bottom: 46px;
  padding: 10px 6px 10px 14px;
  border: 1px solid var(--line);
  border-radius: 16px 16px 4px 16px;
  background: var(--card);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-2);
  animation: xx-teaser-in 0.4s ease both;
}

@keyframes xx-teaser-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.xx-teaser-text { text-align: left; color: inherit; }
.xx-teaser-text:hover { color: var(--jade-700); }

.xx-teaser-close {
  display: grid;
  flex: none;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: var(--ink-3);
}

.xx-teaser-close:hover { background: var(--jade-50); color: var(--jade-700); }
.xx-teaser-close svg { width: 12px; height: 12px; }

/* ---------- 面板 ---------- */
.xx-panel {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 70;
  display: flex;
  flex-direction: column;
  width: min(408px, calc(100vw - 32px));
  height: min(660px, calc(100vh - 44px));
  height: min(660px, calc(100dvh - 44px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--paper-light);
  box-shadow: var(--shadow-lg);
  transform-origin: 100% 100%;
  animation: xx-panel-in 0.28s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}

@keyframes xx-panel-in {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.xx-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 12px 12px 16px;
  background: linear-gradient(135deg, var(--jade-800), var(--jade-600));
  color: #fff;
}

.xx-head-avatar {
  flex: none;
  width: 54px;
  height: 54px;
}

.xx-head-avatar .xx-mascot__halo { fill: rgba(255, 255, 255, 0.14); stroke: rgba(255, 255, 255, 0.6); }

.xx-head-text { flex: 1; min-width: 0; }

.xx-title {
  font-size: 17px;
  line-height: 1.35;
  letter-spacing: 0.04em;
  color: #fff;
}

.xx-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 6px;
  margin-top: 2px;
  font-size: 12px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.78);
}

.xx-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #8fe3b8;
  box-shadow: 0 0 0 3px rgba(143, 227, 184, 0.22);
}

.xx-dot.is-thinking { background: var(--gold); box-shadow: 0 0 0 3px rgba(194, 165, 110, 0.3); }
.xx-dot.is-speaking { background: #ffd28a; }

.xx-actions { display: flex; flex: none; gap: 2px; align-self: flex-start; }

.xx-icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.86);
  transition: background-color 0.2s;
}

.xx-icon-btn:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }
.xx-icon-btn:focus-visible { outline-color: #fff; }
.xx-icon-btn svg { width: 18px; height: 18px; }
.xx-icon-btn svg path { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.xx-icon-btn .xx-voice-speaker { fill: currentColor; stroke: none; }
.xx-icon-btn .xx-voice-on { display: none; }
.xx-icon-btn[aria-pressed="true"] { background: rgba(255, 255, 255, 0.18); }
.xx-icon-btn[aria-pressed="true"] .xx-voice-on { display: inline; }
.xx-icon-btn[aria-pressed="true"] .xx-voice-off { display: none; }

/* 身份切换 */
.xx-persona {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--card);
}

.xx-persona-label { font-size: 12px; color: var(--ink-3); }

.xx-chip {
  padding: 3px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper-light);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink-2);
  transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}

.xx-chip:hover { border-color: var(--jade-300); color: var(--jade-700); }

.xx-chip[aria-pressed="true"] {
  border-color: var(--jade-600);
  background: var(--jade-600);
  color: #fff;
}

/* 对话区 */
.xx-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 14px 6px;
  scroll-behavior: smooth;
}

.xx-body:focus { outline: none; }

.xx-loading { display: grid; place-items: center; padding: 40px 0; }

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

.xx-msg--user { justify-content: flex-end; }

.xx-msg-avatar { flex: none; width: 32px; height: 32px; margin-top: 2px; }

.xx-bubble {
  max-width: calc(100% - 40px);
  padding: 10px 13px;
  border: 1px solid var(--line-soft);
  border-radius: 4px 14px 14px 14px;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  font-size: 14px;
  line-height: 1.75;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.xx-msg--user .xx-bubble {
  border-color: var(--jade-600);
  border-radius: 14px 4px 14px 14px;
  background: var(--jade-600);
  color: #fff;
  box-shadow: none;
}

.xx-bubble p + p { margin-top: 8px; }

.xx-tag {
  display: inline-block;
  margin-right: 6px;
  padding: 0 7px;
  border-radius: 6px;
  background: var(--jade-50);
  font-size: 11.5px;
  line-height: 1.8;
  color: var(--jade-700);
  vertical-align: 1px;
}

.xx-tag--local { background: #f6ebd8; color: #8a5a17; }
.xx-tag--company { background: #f8e7e3; color: var(--cinnabar-dark); }

.xx-question {
  margin-bottom: 6px;
  font-family: var(--serif);
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.6;
  color: var(--ink);
}

.xx-understood {
  margin-bottom: 8px;
  padding: 6px 10px;
  border-left: 3px solid var(--gold);
  border-radius: 0 8px 8px 0;
  background: #faf4e7;
  font-size: 12.5px;
  color: var(--ink-2);
}

.xx-block { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); }

.xx-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink-3);
}

.xx-steps { padding-left: 1.3em; list-style: decimal; font-size: 13.5px; }
.xx-steps li + li { margin-top: 2px; }

.xx-links { display: flex; flex-wrap: wrap; gap: 6px; }

.xx-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border: 1px solid var(--jade-100);
  border-radius: 8px;
  background: var(--jade-50);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--jade-700);
}

.xx-link:hover { border-color: var(--jade-300); background: #fff; }

.xx-sources li {
  display: flex;
  flex-direction: column;
  padding: 4px 0;
  font-size: 12.5px;
  line-height: 1.55;
}

.xx-sources li + li { border-top: 1px solid var(--line-soft); }
.xx-sources a { color: var(--jade-700); text-decoration: underline; text-decoration-color: var(--jade-300); text-underline-offset: 3px; }
.xx-sources a:hover { text-decoration-color: var(--jade-600); }
.xx-sources small { font-size: 11.5px; color: var(--ink-3); }

.xx-verified { margin-top: 8px; font-size: 11.5px; color: var(--ink-3); }

.xx-followups { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

.xx-ask {
  max-width: 100%;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper-light);
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-2);
  text-align: left;
  transition: border-color 0.2s, color 0.2s, background-color 0.2s;
}

.xx-ask:hover:not(:disabled) { border-color: var(--jade-300); background: #fff; color: var(--jade-700); }
.xx-ask:disabled { opacity: 0.55; cursor: default; }

.xx-lead {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 7px 14px;
  border-radius: 10px;
  background: var(--cinnabar);
  font-size: 13.5px;
  font-weight: 600;
  color: #fff;
  box-shadow: 0 6px 16px rgba(181, 64, 47, 0.25);
  transition: background-color 0.2s;
}

.xx-lead:hover { background: var(--cinnabar-dark); }

/* 欢迎区 */
.xx-welcome-greeting { margin-bottom: 10px; font-size: 13px; line-height: 1.7; color: var(--ink-2); }

.xx-topics-title {
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink-3);
}

.xx-topics { display: grid; gap: 7px; }

.xx-topic {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink);
  text-align: left;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}

.xx-topic:hover {
  border-color: var(--jade-300);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.xx-topic .xx-tag { flex: none; }

.xx-typing { display: inline-flex; gap: 4px; padding: 4px 2px; }

.xx-typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--jade-300);
  animation: xx-typing 1.2s infinite;
}

.xx-typing i:nth-child(2) { animation-delay: 0.15s; }
.xx-typing i:nth-child(3) { animation-delay: 0.3s; }

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

/* 输入区 */
.xx-form {
  display: flex;
  gap: 8px;
  padding: 10px 12px 8px;
  border-top: 1px solid var(--line-soft);
  background: var(--card);
}

.xx-field {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper-light);
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.xx-field:focus { border-color: var(--jade-500); outline: none; box-shadow: 0 0 0 3px rgba(51, 112, 92, 0.15); }

.xx-send {
  flex: none;
  height: 40px;
  padding: 0 16px;
  border-radius: 12px;
  background: var(--jade-600);
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  transition: background-color 0.2s, opacity 0.2s;
}

.xx-send:hover:not(:disabled) { background: var(--jade-700); }
.xx-send:disabled { opacity: 0.5; cursor: default; }

/* 工具行：联网检索开关 */
.xx-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-top: 1px solid var(--line-soft);
  background: var(--card);
}

.xx-switch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: none;
  font-size: 12.5px;
  color: var(--ink-2);
}

.xx-switch:disabled {
  cursor: default;
  opacity: 0.75;
}

.xx-switch-track {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 19px;
  border-radius: 999px;
  background: #c7d2cd;
  transition: background-color 0.2s;
}

.xx-switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
  transition: transform 0.2s;
}

.xx-switch.is-on .xx-switch-track { background: var(--jade-600); }
.xx-switch.is-on .xx-switch-thumb { transform: translateX(15px); }

.xx-switch:focus-visible {
  outline: 3px solid rgba(51, 112, 92, 0.25);
  outline-offset: 2px;
  border-radius: 8px;
}

.xx-tools-hint {
  min-width: 0;
  overflow: hidden;
  font-size: 11px;
  line-height: 1.4;
  color: var(--ink-3);
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* 麦克风按钮 */
.xx-mic {
  position: relative;
  display: grid;
  flex: none;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper-light);
  color: var(--jade-700);
  transition: border-color 0.2s, background-color 0.2s, color 0.2s;
}

.xx-mic:hover:not(:disabled) { border-color: var(--jade-300); }
.xx-mic:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(51, 112, 92, 0.15); }
.xx-mic:disabled { opacity: 0.5; cursor: default; }
.xx-mic-icon { position: relative; z-index: 1; width: 19px; height: 19px; }
.xx-mic-icon path { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.xx-mic-pulse {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background: var(--cinnabar);
  opacity: 0;
  transform: scale(1);
}

.xx-mic.is-recording {
  border-color: var(--cinnabar);
  background: var(--cinnabar);
  color: #fff;
}

.xx-mic.is-recording .xx-mic-pulse {
  animation: xx-mic-pulse 1.4s ease-out infinite;
}

@keyframes xx-mic-pulse {
  0% { opacity: 0.35; transform: scale(1); }
  70% { opacity: 0; transform: scale(1.35); }
  100% { opacity: 0; transform: scale(1.35); }
}

/* 联网检索回答 */
.xx-tag--web {
  background: #eef3f9;
  color: #2f5d8a;
}

.xx-web-notice {
  margin-bottom: 8px;
  padding: 6px 10px;
  border-left: 3px solid var(--gold);
  border-radius: 0 8px 8px 0;
  background: #faf4e7;
  font-size: 12.5px;
  color: var(--ink-2);
}

.xx-web-meta {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--ink-3);
}

.xx-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 14px 10px;
  background: var(--card);
  font-size: 11px;
  line-height: 1.5;
  color: var(--ink-3);
}

.xx-foot-link {
  flex: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--cinnabar);
}

.xx-foot-link:hover { color: var(--cinnabar-dark); text-decoration: underline; text-underline-offset: 3px; }

/* ---------- 手机 ---------- */
@media (max-width: 640px) {
  .xx-dock { right: 14px; bottom: 16px; }
  .xx-fab { width: 66px; height: 66px; }
  .xx-teaser { max-width: 200px; margin-bottom: 40px; font-size: 12.5px; }

  .xx-panel {
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
    transform-origin: 50% 100%;
  }

  .xx-head { padding-top: max(14px, env(safe-area-inset-top)); }
  .xx-foot { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .xx-field { font-size: 16px; } /* 避免 iOS 聚焦时自动放大 */
}

@media print {
  .xx-dock,
  .xx-panel {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .xx-mascot *,
  .xx-dock,
  .xx-panel,
  .xx-teaser {
    animation: none !important;
  }

  .is-thinking .xx-mascot__thinking circle,
  .is-speaking .xx-mascot__waves path {
    opacity: 0.7;
  }
}
