/* AI 在线客服 悬浮窗（自写，无第三方依赖，支持深色模式与移动端全屏） */
.wj-kf,
.wj-kf * {
  box-sizing: border-box;
}
.wj-kf {
  --kf-accent: #3b82f6;
  --kf-accent-2: #2563eb;
  --kf-accent-soft: rgba(59, 130, 246, .08);
  --kf-accent-line: rgba(59, 130, 246, .22);
  --kf-bg: #ffffff;
  --kf-fg: #1f2937;
  --kf-border: #e5e7eb;
  --kf-muted: #6b7280;
  --kf-user-bg: var(--kf-accent);
  --kf-user-fg: #ffffff;
  --kf-bot-bg: #f3f4f6;
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--kf-fg);
}

/* 悬浮按钮 */
.wj-kf-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--kf-accent);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
  transition: transform .15s ease, background .15s ease;
}
.wj-kf-btn:hover {
  background: var(--kf-accent-2);
  transform: translateY(-2px);
}
.wj-kf-btn svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
}

/* 聊天面板 */
.wj-kf-panel {
  position: absolute;
  right: 0;
  bottom: 66px;
  width: 360px;
  max-width: calc(100vw - 40px);
  height: 520px;
  max-height: calc(100vh - 100px);
  background: var(--kf-bg);
  border: 1px solid var(--kf-border);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(.98);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.wj-kf-panel.wj-kf-open {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.wj-kf-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--kf-accent);
  color: #fff;
}
.wj-kf-head .wj-kf-title {
  font-weight: 600;
}
.wj-kf-head .wj-kf-id {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.wj-kf-head .wj-kf-avatar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .2);
  overflow: hidden;
}
.wj-kf-head .wj-kf-avatar svg {
  width: 20px;
  height: 20px;
  fill: #fff;
}
.wj-kf-head .wj-kf-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.wj-kf-head .wj-kf-names {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}
.wj-kf-head .wj-kf-subtitle {
  font-size: 11px;
  opacity: .85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wj-kf-head .wj-kf-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  opacity: .85;
  padding: 2px;
}
.wj-kf-head .wj-kf-close:hover { opacity: 1; }
.wj-kf-head .wj-kf-close svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.wj-kf-head .wj-kf-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.wj-kf-head .wj-kf-head-handoff {
  background: none;
  border: 1px solid rgba(255, 255, 255, .55);
  color: #fff;
  padding: 2px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.wj-kf-head .wj-kf-head-handoff:hover { background: rgba(255, 255, 255, .16); }

/* 消息区 */
.wj-kf-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  background: var(--kf-bg);
}
.wj-kf-msg {
  max-width: 82%;
  margin-bottom: 10px;
  padding: 9px 12px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.wj-kf-msg.wj-kf-user {
  margin-left: auto;
  background: var(--kf-user-bg);
  color: var(--kf-user-fg);
  border-bottom-right-radius: 4px;
}
.wj-kf-msg.wj-kf-bot {
  margin-right: auto;
  background: var(--kf-bot-bg);
  color: var(--kf-fg);
  border-bottom-left-radius: 4px;
}
.wj-kf-msg .wj-kf-tag {
  display: inline-block;
  margin-top: 4px;
  font-size: 11px;
  padding: 0 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, .2);
}
.wj-kf-msg.wj-kf-bot .wj-kf-tag {
  background: var(--kf-accent);
  color: #fff;
}

/* 欢迎卡片：起始对话 + 常见问题 */
.wj-kf-welcome {
  margin-bottom: 12px;
  padding: 12px 14px;
  background: var(--kf-bot-bg);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
}
.wj-kf-welcome-text {
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 8px;
}
.wj-kf-faq-title {
  font-size: 12px;
  color: var(--kf-muted);
  margin: 4px 0 6px;
}
.wj-kf-faq-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
  width: 100%;
  text-align: left;
  margin-bottom: 6px;
  padding: 7px 10px;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  background: #fff7ed;
  color: #7c2d12;
  cursor: pointer;
  font-size: 13px;
}
.wj-kf-faq-item:last-child { margin-bottom: 0; }
.wj-kf-faq-item:hover {
  border-color: #fb923c;
  background: #ffedd5;
}
.wj-kf-faq-no {
  flex: none;
  font-weight: 600;
  color: #ea580c;
}

/* 非服务时间提示 */
.wj-kf-offline {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fef3c7;
  color: #92400e;
  font-size: 13px;
}

/* 输入中 */
.wj-kf-typing {
  display: inline-flex;
  gap: 4px;
  padding: 12px 14px;
}
.wj-kf-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--kf-muted);
  animation: wjKfBlink 1.2s infinite;
}
.wj-kf-typing span:nth-child(2) { animation-delay: .2s; }
.wj-kf-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes wjKfBlink {
  0%, 60%, 100% { opacity: .3; }
  30% { opacity: 1; }
}

/* 转人工表单 */
.wj-kf-form {
  padding: 14px 16px;
  display: none;
}
.wj-kf-form.wj-kf-open { display: block; }
.wj-kf-form input,
.wj-kf-form textarea {
  width: 100%;
  margin-bottom: 8px;
  padding: 8px 10px;
  border: 1px solid var(--kf-border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--kf-bg);
  color: var(--kf-fg);
}
.wj-kf-form .wj-kf-row {
  display: flex;
  gap: 8px;
}
.wj-kf-form button {
  width: 100%;
  padding: 9px;
  border: none;
  border-radius: 8px;
  background: var(--kf-accent);
  color: #fff;
  cursor: pointer;
}
.wj-kf-form button:hover { background: var(--kf-accent-2); }

/* 底部输入区 */
.wj-kf-foot {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--kf-border);
  background: var(--kf-bg);
}
.wj-kf-foot textarea {
  flex: 1;
  resize: none;
  height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--kf-border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--kf-bg);
  color: var(--kf-fg);
}
.wj-kf-foot button {
  padding: 0 16px;
  border: none;
  border-radius: 8px;
  background: var(--kf-accent);
  color: #fff;
  cursor: pointer;
}
.wj-kf-foot button:hover { background: var(--kf-accent-2); }
.wj-kf-foot button:disabled { opacity: .6; cursor: not-allowed; }

.wj-kf-toolbar {
  padding: 6px 12px;
  border-top: 1px solid var(--kf-border);
  background: var(--kf-bg);
  display: none;
}
.wj-kf-toolbar.wj-kf-open { display: flex; }
.wj-kf-toolbar button {
  background: none;
  border: none;
  color: var(--kf-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 8px;
}
.wj-kf-toolbar button:hover { color: var(--kf-accent); }

/* 移动端全屏 */
@media (max-width: 576px) {
  .wj-kf-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    border-radius: 0;
    bottom: 0;
  }
}

/* 深色模式 */
@media (prefers-color-scheme: dark) {
  .wj-kf {
    --kf-bg: #1f2937;
    --kf-fg: #f3f4f6;
    --kf-border: #374151;
    --kf-muted: #9ca3af;
    --kf-bot-bg: #374151;
  }
}
