/* AI 客服悬浮窗（前台独立样式，全部 aic- 前缀避免冲突） */

/* ===== 悬浮球 ===== */
/* 尺寸全部由 --aic-ball-scale（后台「图标设置 - 显示倍率」，0.5~4）换算，
   未下发该变量时按 1 倍处理，即桌面 68px / 移动端 60px */
.aic-ball {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: calc(68px * var(--aic-ball-scale, 1));
  height: calc(68px * var(--aic-ball-scale, 1));
  border-radius: 50%;
  border: none;
  cursor: pointer;
  z-index: 99999;
  background: linear-gradient(135deg, #1a73e8, #0b47ad);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(26, 115, 232, 0.45);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.aic-ball:hover {
  transform: scale(1.06);
  box-shadow: 0 8px 26px rgba(26, 115, 232, 0.55);
}
.aic-ball svg {
  width: calc(34px * var(--aic-ball-scale, 1));
  height: calc(34px * var(--aic-ball-scale, 1));
  fill: currentColor;
}
/* 自定义图标（后台「图标设置」上传/填写的图片地址）：图片铺满悬浮球，不保留蓝色底 */
.aic-ball--custom {
  background: transparent;
  box-shadow: none;
  overflow: hidden;
}
.aic-ball--custom:hover {
  transform: scale(1.06);
  box-shadow: none;
}
.aic-ball img.aic-ball-icon {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

/* ===== 对话窗 ===== */
/* 右侧停靠式侧栏：贴死右边缘、上下通顶到底（对齐参考稿），不再是悬浮圆角卡片 */
.aic-window {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 100vw;
  background: #fff;
  border-radius: 0;
  box-shadow: -12px 0 40px rgba(15, 46, 87, 0.18);
  z-index: 99999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}
.aic-window[hidden] {
  display: none;
}

/* ===== 全屏页面模式（page.html / web-view / iframe 整页嵌入） ===== */
/* html 根节点由 ai-chat.js 在 PAGE_MODE 下加 aic-page-mode 类，聊天窗铺满整屏 */
.aic-page-mode .aic-window {
  left: 0;
  width: 100vw;
  max-width: 100vw;
  box-shadow: none;
}

/* 头部 */
.aic-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  /* 浅色渐变头部（白 → 淡蓝），文字用深色 */
  background: linear-gradient(180deg, #f5faff 0%, #dcecfd 100%);
  border-bottom: 1px solid #e3eef9;
  color: #1f2937;
}
.aic-title {
  font-size: 14px;
  font-weight: 600;
  color: #1f2937;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.aic-title .aic-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.25);
}
/* 头部客服头像：与悬浮球同一张自定义图标 */
.aic-title img.aic-title-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
  flex-shrink: 0;
}
.aic-title .aic-title-icon svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}
.aic-close {
  background: transparent;
  border: none;
  color: #5f6368;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}
.aic-close:hover {
  background: rgba(31, 41, 55, 0.08);
}

/* 头部按钮组（新会话 / 关闭） */
.aic-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.aic-icon-btn {
  background: transparent;
  border: none;
  color: #5f6368;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 6px;
}
.aic-icon-btn:hover {
  background: rgba(31, 41, 55, 0.08);
}
.aic-icon-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  display: block;
}
.aic-icon-btn[hidden] {
  display: none;
}

/* 转人工兜底条 */
.aic-human {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  font-size: 12px;
  color: #5f6368;
  background: #f1f3f4;
  border-top: 1px solid #e8eaed;
}
.aic-human[hidden] {
  display: none;
}
.aic-human .aic-link {
  font-size: 12px;
}

/* 快捷问题 */
.aic-quick {
  align-self: stretch;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 0;
}
.aic-quick-title {
  width: 100%;
  font-size: 12px;
  color: #9aa0a6;
}
.aic-quick-item {
  border: 1px solid #d2e3fc;
  background: #fff;
  color: #1a73e8;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.aic-quick-item:hover {
  background: #e8f0fe;
}

/* 赞踩操作 */
.aic-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
.aic-action {
  border: none;
  background: transparent;
  color: #9aa0a6;
  font-size: 12px;
  cursor: pointer;
  padding: 0;
}
.aic-action:hover {
  color: #1a73e8;
}
.aic-action.active {
  color: #1a73e8;
  font-weight: 600;
}

/* Markdown 渲染（AI 气泡内） */
.aic-ai .aic-p {
  margin: 0 0 4px;
  white-space: pre-wrap;
}
.aic-ai .aic-p:last-child {
  margin-bottom: 0;
}
.aic-ai .aic-list {
  margin: 4px 0;
  padding-left: 20px;
}
.aic-ai .aic-list li {
  margin: 2px 0;
}
.aic-ai .aic-code-inline {
  font-family: Consolas, Monaco, monospace;
  font-size: 12.5px;
  background: rgba(27, 31, 35, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
}
.aic-ai .aic-code-block {
  margin: 6px 0;
  padding: 8px 10px;
  background: #1e1e1e;
  color: #d4d4d4;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre;
}
.aic-ai .aic-code-block code {
  font-family: Consolas, Monaco, monospace;
}

/* 转人工：入口常驻输入区，避免访客问不到答案时无从求助 */
.aic-human-btn {
  flex: 0 0 auto;
  height: 38px;
  padding: 0 10px;
  border: 1px solid #1a73e8;
  border-radius: 8px;
  background: #fff;
  color: #1a73e8;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.aic-human-btn:hover {
  background: #f0f5ff;
}
.aic-human-btn[hidden] {
  display: none;
}

/* 发送中（可点击停止） */
.aic-send.is-stop {
  background: #5f6368;
}
.aic-send.is-stop:hover {
  background: #3c4043;
}

/* 消息区 */
.aic-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px 12px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* AI 消息分组：头像 + 客服名称 + 气泡列（连续的客服侧消息共用一个头像） */
.aic-group {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: 92%;
}
.aic-group-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: linear-gradient(135deg, #4f95ff, #1a73e8);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.aic-group-avatar svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}
.aic-group-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.aic-group-name {
  font-size: 12px;
  line-height: 1.2;
  color: #8a97a8;
}
.aic-group-bubbles {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}
.aic-group-bubbles .aic-bubble {
  max-width: 100%;
}

/* 气泡 */
.aic-bubble {
  max-width: 82%;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.aic-user {
  align-self: flex-end;
  background: linear-gradient(135deg, #4f95ff, #1a73e8);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.aic-ai {
  align-self: flex-start;
  background: #e8f2fe;
  color: #1f2937;
  border-bottom-left-radius: 4px;
}
.aic-error {
  background: #fdecec;
  color: #d93025;
}
/* 欢迎语：无底色的纯文本，跟在头像/名称下方（对齐截图里的问候样式） */
.aic-welcome {
  align-self: flex-start;
  background: transparent;
  padding: 2px 0;
  color: #4b5563;
}

/* AI 回复中的可点击链接 */
.aic-link {
  color: #1a73e8;
  text-decoration: underline;
  word-break: break-all;
}
.aic-link:visited {
  color: #1a73e8;
}

/* 打字光标 */
.aic-typing::after {
  content: "▍";
  display: inline-block;
  color: #1a73e8;
  animation: aic-blink 0.9s steps(1) infinite;
}
@keyframes aic-blink {
  50% {
    opacity: 0;
  }
}

/* 底部输入区 */
.aic-footer {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid #e8eaed;
  background: #fff;
}
.aic-input {
  flex: 1 1 auto;
  height: 38px;
  padding: 0 12px;
  border: 1px solid #dadce0;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  color: #333;
  min-width: 0;
}
.aic-input:focus {
  border-color: #1a73e8;
}
.aic-send {
  flex: 0 0 auto;
  height: 38px;
  padding: 0 16px;
  border: none;
  border-radius: 8px;
  background: #1a73e8;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}
.aic-send:hover {
  background: #1660c4;
}
.aic-send:disabled {
  background: #9dc0f0;
  cursor: not-allowed;
}

/* ===== 留资卡 / 工单表单 ===== */
.aic-form {
  align-self: stretch;
  background: #fff;
  border: 1px solid #e8eaed;
  border-radius: 10px;
  padding: 12px;
  margin-top: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
}
.aic-form-title {
  font-size: 13px;
  font-weight: 600;
  color: #174ea6;
  margin-bottom: 10px;
}
.aic-form-row {
  margin-bottom: 10px;
}
.aic-form-row[hidden] {
  display: none;
}
.aic-form-label {
  display: block;
  font-size: 12px;
  color: #5f6368;
  margin-bottom: 4px;
}
.aic-form-input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 1px solid #dadce0;
  border-radius: 8px;
  font-size: 13px;
  color: #333;
  outline: none;
  resize: vertical;
  font-family: inherit;
}
.aic-form-input:focus {
  border-color: #1a73e8;
}
.aic-form-code {
  display: flex;
  gap: 8px;
  align-items: center;
}
.aic-form-code .aic-form-input {
  flex: 1 1 auto;
}
.aic-form-captcha {
  height: 34px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid #e8eaed;
  background: #fff;
}
.aic-form-tip {
  min-height: 18px;
  font-size: 12px;
  color: #d93025;
  margin-bottom: 6px;
}
.aic-form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.aic-form-submit {
  border: none;
  border-radius: 8px;
  background: #1a73e8;
  color: #fff;
  font-size: 13px;
  padding: 7px 14px;
  cursor: pointer;
}
.aic-form-submit:disabled {
  background: #9dc0f0;
  cursor: not-allowed;
}
.aic-form-cancel {
  border: 1px solid #dadce0;
  border-radius: 8px;
  background: #fff;
  color: #5f6368;
  font-size: 13px;
  padding: 7px 14px;
  cursor: pointer;
}
.aic-form-cancel[hidden] {
  display: none;
}
.aic-form-forget-row {
  margin-bottom: 8px;
  font-size: 12px;
  line-height: 1.5;
  color: #5f6368;
}
.aic-form-forget-row[hidden] {
  display: none;
}
.aic-form-forget {
  border: none;
  background: none;
  padding: 0;
  color: #1a73e8;
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
}

/* 系统回执气泡（留资成功 / 工单回执） */
.aic-system {
  align-self: flex-start;
  background: #e8f0fe;
  color: #174ea6;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  border-top-left-radius: 2px;
}

/* 工单时间线 */
.aic-timeline {
  margin-top: 10px;
  border-left: 2px solid #c6dafc;
  padding-left: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.aic-timeline-item {
  font-size: 12.5px;
  color: #333;
}
.aic-timeline-role {
  font-weight: 600;
  color: #174ea6;
  margin-right: 6px;
}
.aic-timeline-time {
  color: #9aa0a6;
  font-size: 11px;
}
.aic-timeline-content {
  margin-top: 2px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ===== 移动端 ===== */
@media (max-width: 480px) {
  .aic-ball {
    right: 16px;
    bottom: 16px;
    width: calc(60px * var(--aic-ball-scale, 1));
    height: calc(60px * var(--aic-ball-scale, 1));
  }
  .aic-ball svg {
    width: calc(30px * var(--aic-ball-scale, 1));
    height: calc(30px * var(--aic-ball-scale, 1));
  }
  .aic-window {
    /* 移动端同样贴边停靠：右侧通栏、上下通顶 */
    width: 100vw;
  }
}
