/* AIChat - 站点 AI 客服组件样式（全部以 .aic- 前缀隔离，不污染主题） */

.aic-root {
  --aic-accent: #4f7cff;
  --aic-accent-soft: rgba(79, 124, 255, 0.12);
  --aic-bg: #ffffff;
  --aic-panel: #ffffff;
  --aic-text: #1b1f27;
  --aic-text-soft: #6b7280;
  --aic-line: rgba(15, 23, 42, 0.08);
  --aic-bot-bg: #f4f5f8;
  --aic-shadow: 0 24px 60px rgba(15, 23, 42, 0.18), 0 4px 14px rgba(15, 23, 42, 0.06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--aic-text);
}

.aic-root.aic-dark {
  --aic-bg: #1a1d24;
  --aic-panel: #1e222a;
  --aic-text: #e8eaef;
  --aic-text-soft: #9aa3b2;
  --aic-line: rgba(255, 255, 255, 0.1);
  --aic-bot-bg: #262b35;
  --aic-accent-soft: rgba(79, 124, 255, 0.2);
  --aic-shadow: 0 24px 60px rgba(0, 0, 0, 0.5), 0 4px 14px rgba(0, 0, 0, 0.3);
}

/* 悬浮按钮 */
.aic-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: 9990;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 50%;
  background: var(--aic-accent);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.24);
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.aic-launcher.aic-has-avatar {
  background: #fff;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.24), 0 0 0 2px var(--aic-accent);
}

.aic-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.3), 0 0 0 2px var(--aic-accent);
}

.aic-launcher:active {
  transform: scale(0.96);
}

.aic-launcher svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
  pointer-events: none;
}

.aic-launcher img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: top center;
  pointer-events: none;
  user-select: none;
  animation: aic-bob 3.2s ease-in-out infinite;
}

@keyframes aic-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2.5px); }
}

@media (prefers-reduced-motion: reduce) {
  .aic-launcher img { animation: none; }
  .aic-launcher.aic-pulse::after { animation: none; opacity: 0.55; }
  .aic-hint.aic-show { animation: none; }
}

.aic-launcher.aic-hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
}

/* 首次进入时的脉冲光晕，提示这里可以点 */
.aic-launcher.aic-pulse::after {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 2px solid var(--aic-accent);
  pointer-events: none;
  animation: aic-pulse 2s ease-out 3;
}

@keyframes aic-pulse {
  0% { transform: scale(0.92); opacity: 0.7; }
  70%, 100% { transform: scale(1.3); opacity: 0; }
}

/* 引导气泡 */
.aic-hint {
  position: fixed;
  right: 92px;
  bottom: calc(32px + env(safe-area-inset-bottom, 0px));
  z-index: 9990;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: min(260px, calc(100vw - 120px));
  padding: 9px 8px 9px 12px;
  border: 1px solid rgba(15, 23, 42, 0.07);
  border-radius: 12px;
  background: #fff;
  color: #1f2937;
  font-size: 13px;
  line-height: 1.35;
  letter-spacing: 0.01em;
  white-space: nowrap;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateX(10px) scale(0.96);
  transform-origin: right center;
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.16);
  -webkit-tap-highlight-color: transparent;
}

.aic-hint::after {
  content: '';
  position: absolute;
  right: -5px;
  top: 50%;
  width: 9px;
  height: 9px;
  margin-top: -4.5px;
  background: #fff;
  border-top: 1px solid rgba(15, 23, 42, 0.07);
  border-right: 1px solid rgba(15, 23, 42, 0.07);
  transform: rotate(45deg);
}

.aic-hint.aic-show {
  opacity: 1;
  visibility: visible;
  transform: translateX(0) scale(1);
  animation: aic-hint-nudge 2.4s ease-in-out 0.4s 2;
}

@keyframes aic-hint-nudge {
  0%, 100% { transform: translateX(0) scale(1); }
  50% { transform: translateX(-4px) scale(1.01); }
}

.aic-hint-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.aic-hint-close {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  margin-left: 2px;
  border-radius: 50%;
  color: #9aa3b2;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.aic-hint-close:hover {
  background: rgba(15, 23, 42, 0.07);
  color: #4b5563;
}

.aic-root.aic-dark .aic-hint {
  background: #1f2430;
  border-color: rgba(255, 255, 255, 0.09);
  color: #e5e7eb;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5);
}

.aic-root.aic-dark .aic-hint::after {
  background: #1f2430;
  border-top-color: rgba(255, 255, 255, 0.09);
  border-right-color: rgba(255, 255, 255, 0.09);
}

.aic-root.aic-dark .aic-hint-close {
  color: #94a3b8;
}

.aic-root.aic-dark .aic-hint-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #e2e8f0;
}

.aic-root.aic-open .aic-hint {
  display: none;
}

/* 面板 */
.aic-panel {
  position: fixed;
  right: 24px;
  bottom: 90px;
  bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  z-index: 9991;
  display: flex;
  flex-direction: column;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 130px);
  background: var(--aic-panel);
  border: 1px solid var(--aic-line);
  border-radius: 16px;
  box-shadow: var(--aic-shadow);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.aic-root.aic-open .aic-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.aic-root.aic-open .aic-launcher {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
}

/* 顶部 */
.aic-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--aic-line);
  background: linear-gradient(180deg, var(--aic-accent-soft), transparent);
  flex: 0 0 auto;
}

.aic-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--aic-accent);
  color: #fff;
  flex: 0 0 auto;
  overflow: hidden;
}

.aic-avatar.aic-has-avatar {
  background: #fff;
  box-shadow: 0 0 0 2px var(--aic-accent);
}

.aic-avatar svg {
  width: 19px;
  height: 19px;
  fill: currentColor;
}

.aic-avatar img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: top center;
  user-select: none;
}

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

.aic-head-text strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--aic-text);
  line-height: 1.4;
}

.aic-head-text span {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--aic-text-soft);
  line-height: 1.4;
}

.aic-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.14);
}

.aic-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--aic-text-soft);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.aic-close:hover {
  background: var(--aic-bot-bg);
  color: var(--aic-text);
}

/* 消息区 */
.aic-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px 8px;
  scrollbar-width: thin;
}

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

.aic-body::-webkit-scrollbar-thumb {
  background: var(--aic-line);
  border-radius: 3px;
}

.aic-msg {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  align-items: flex-start;
  animation: aic-in 0.22s ease both;
}

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

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

.aic-bubble {
  max-width: 82%;
  padding: 9px 12px;
  border-radius: 12px;
  word-break: break-word;
  overflow-wrap: anywhere;
  background: var(--aic-bot-bg);
  color: var(--aic-text);
  font-size: 13.5px;
  line-height: 1.68;
}

.aic-msg.aic-user .aic-bubble {
  background: var(--aic-accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.aic-msg.aic-bot .aic-bubble {
  border-bottom-left-radius: 4px;
}

.aic-bubble a {
  color: var(--aic-accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(79, 124, 255, 0.35);
}

.aic-msg.aic-user .aic-bubble a {
  color: #fff;
}

.aic-bubble p {
  margin: 0 0 6px;
}

.aic-bubble p:last-child {
  margin-bottom: 0;
}

.aic-bubble ul {
  margin: 4px 0;
  padding-left: 18px;
}

.aic-bubble li {
  margin: 2px 0;
}

.aic-bubble code {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.08);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
}

.aic-msg.aic-user .aic-bubble code {
  background: rgba(255, 255, 255, 0.2);
}

.aic-bubble pre {
  margin: 6px 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.06);
  overflow-x: auto;
}

.aic-bubble pre code {
  padding: 0;
  background: none;
}

.aic-err .aic-bubble {
  background: rgba(239, 68, 68, 0.1);
  color: #b91c1c;
}

.aic-root.aic-dark .aic-err .aic-bubble {
  color: #fca5a5;
}

.aic-root.aic-dark .aic-bubble a,
.aic-root.aic-dark .aic-refs a {
  color: #8fb0ff;
}

.aic-root.aic-dark .aic-bubble a {
  border-bottom-color: rgba(143, 176, 255, 0.4);
}

/* 参考文章 */
.aic-refs {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--aic-line);
}

.aic-refs-title {
  font-size: 11px;
  color: var(--aic-text-soft);
  margin-bottom: 4px;
}

.aic-refs a {
  display: block;
  padding: 4px 0;
  font-size: 12.5px;
  color: var(--aic-accent);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.aic-refs a:hover {
  text-decoration: underline;
}

/* 打字指示 */
.aic-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
}

.aic-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--aic-text-soft);
  animation: aic-bounce 1.2s infinite ease-in-out;
}

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

@keyframes aic-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* 快捷提问 */
.aic-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px 10px;
  flex: 0 0 auto;
}

.aic-chip {
  padding: 6px 10px;
  border: 1px solid var(--aic-line);
  border-radius: 999px;
  background: transparent;
  color: var(--aic-text-soft);
  font-size: 12px;
  line-height: 1.4;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.aic-chip:hover {
  border-color: var(--aic-accent);
  color: var(--aic-accent);
  background: var(--aic-accent-soft);
}

/* 输入区 */
.aic-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 8px;
  border-top: 1px solid var(--aic-line);
  flex: 0 0 auto;
  background: var(--aic-panel);
}

.aic-input {
  flex: 1 1 auto;
  min-height: 38px;
  max-height: 110px;
  padding: 9px 12px;
  border: 1px solid var(--aic-line);
  border-radius: 12px;
  background: var(--aic-bg);
  color: var(--aic-text);
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.5;
  resize: none;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.aic-input::placeholder {
  color: var(--aic-text-soft);
  opacity: 0.85;
}

.aic-input:focus {
  border-color: var(--aic-accent);
  box-shadow: 0 0 0 3px var(--aic-accent-soft);
}

.aic-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: none;
  border-radius: 11px;
  background: var(--aic-accent);
  color: #fff;
  cursor: pointer;
  flex: 0 0 auto;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.aic-send:hover { transform: translateY(-1px); }

.aic-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.aic-send svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.aic-note {
  padding: 0 14px 10px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--aic-text-soft);
  text-align: center;
  flex: 0 0 auto;
  opacity: 0.85;
}

/* 移动端全屏 */
@media (max-width: 520px) {
  .aic-panel {
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    height: 100dvh;
    border-radius: 0;
    border: none;
    transform: translateY(16px);
  }

  .aic-root.aic-open .aic-panel {
    transform: translateY(0);
  }

  .aic-launcher {
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    width: 48px;
    height: 48px;
  }

  .aic-hint {
    right: 72px;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    max-width: calc(100vw - 96px);
    padding: 8px 6px 8px 10px;
    font-size: 12px;
    gap: 4px;
  }

  .aic-head {
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
  }

  .aic-form {
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }
}

@media (prefers-reduced-motion: reduce) {
  .aic-panel,
  .aic-launcher,
  .aic-msg {
    transition: none;
    animation: none;
  }
}
