/* ============================================================
   aic.css — AI 智能客服（前台浮窗）
   设计原则：跟站点同一套金/墨色系统，纯自绘，不用任何默认外观。
   三端适配：手机端面板接近全屏、按钮更大、气泡更宽。
   ============================================================ */

.aic {
  --aic-gold: #c2913a;
  --aic-gold-lt: #e0b463;
  --aic-ink: #14171c;
  --aic-line: rgba(20, 23, 28, 0.1);
  --aic-shadow: 0 24px 60px rgba(16, 18, 22, 0.24);
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 900;
  font-family: var(--font-body, system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif);
}

/*
  拖动状态：拖动时禁掉动画与过渡，避免跟不上指针；
  同时提高层级，保证拖到任何位置都在最上层。
*/
.aic.is-dragging,
.aic.is-dragging * {
  transition: none !important;
  animation: none !important;
  user-select: none !important;
}
.aic.is-dragging {
  z-index: 9999;
}

/* ---------------- 浮动按钮 ---------------- */
.aic-fab {
  position: relative;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  cursor: grab;
  touch-action: none; /* 手机上允许拖动，不触发滚动 */
  color: #fff;
  background: linear-gradient(140deg, var(--aic-gold-lt), var(--aic-gold));
  box-shadow: 0 12px 28px rgba(194, 145, 58, 0.42);
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.22s;
}
.aic-fab:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 18px 36px rgba(194, 145, 58, 0.5);
}
.aic-fab:active {
  cursor: grabbing;
}
.aic.is-dragging .aic-fab {
  cursor: grabbing;
  transform: none;
}
/* 拖动时给一点「拿起来了」的反馈 */
.aic.is-dragging .aic-fab,
.aic.is-dragging .aic-panel {
  box-shadow: 0 28px 64px rgba(16, 18, 22, 0.34);
}
.aic-fab-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 11px;
  height: 11px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #d1554f;
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.2s, transform 0.2s;
}
.aic-fab-dot.is-on {
  opacity: 1;
  transform: scale(1);
}
/* 面板打开时隐藏按钮，避免压住面板 */
.aic.is-open .aic-fab {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
}

/* ---------------- 面板 ---------------- */
/*
  fixed + left/top 由 JS 设置（默认停在右下角）。
  面板框本身不吃指针事件，只有内部元素吃 —— 这样拖到别处也不会挡住下层按钮。
  拖动抓头部或底部边缘，跟一般聊天窗口的手感一致。
*/
.aic-panel {
  position: fixed;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  width: min(384px, calc(100vw - 44px));
  height: min(620px, calc(100vh - 120px));
  overflow: hidden;
  border: 1px solid var(--aic-line);
  border-radius: 20px;
  background: #fff;
  box-shadow: var(--aic-shadow);
  opacity: 0;
  transform: translateY(14px) scale(0.97);
  transform-origin: 100% 100%;
  pointer-events: none;
  transition: opacity 0.24s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.aic.is-open .aic-panel {
  opacity: 1;
  transform: none;
}
/* 只有内部元素接收点击，面板框透明穿透 */
.aic.is-open .aic-panel > * {
  pointer-events: auto;
}

/* ---------------- 头部 ---------------- */
.aic-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  flex: none;
  padding: 14px 14px 14px 16px;
  color: #fff;
  background: linear-gradient(135deg, #1c2027, #2b313a);
  cursor: grab;       /* 拖这里可以移动整个客服窗口 */
  touch-action: none;
  user-select: none;
}
.aic.is-dragging .aic-head {
  cursor: grabbing;
}
/* 提醒用户这里可以拖 */
.aic-head::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 8px;
  width: 34px;
  height: 3px;
  margin-left: -17px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.22);
}
.aic-avatar {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 12px;
  object-fit: cover;
}
.aic-avatar--text {
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, var(--aic-gold-lt), var(--aic-gold));
  color: #241a04;
  font-weight: 800;
  font-size: 19px;
}
.aic-head-txt {
  flex: 1;
  min-width: 0;
}
.aic-head-txt b {
  display: block;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.aic-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.62);
}
.aic-status i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4bd07d;
  box-shadow: 0 0 0 3px rgba(75, 208, 125, 0.22);
}
.aic-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: none;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.72);
  background: transparent;
  transition: background 0.18s, color 0.18s;
}
.aic-icon:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

/* ---------------- 对话区 ---------------- */
.aic-body {
  flex: 1;
  min-height: 0;
  padding: 16px 14px 8px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: linear-gradient(180deg, #fbfaf8, #f6f4f0);
}
.aic-body::-webkit-scrollbar {
  width: 6px;
}
.aic-body::-webkit-scrollbar-thumb {
  border-radius: 99px;
  background: rgba(20, 23, 28, 0.16);
}

.aic-msg {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 14px;
}
.aic-msg.is-me {
  flex-direction: row-reverse;
}
.aic-mini {
  width: 28px;
  height: 28px;
  flex: none;
  margin-top: 2px;
  border-radius: 9px;
  object-fit: cover;
}
.aic-mini--text {
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, var(--aic-gold-lt), var(--aic-gold));
  color: #241a04;
  font-size: 13px;
  font-weight: 800;
}
/*
  人工客服（后台回复，role=agent）的样式。
  ------------------------------------------------------------
  用户反馈：「收到前台AI客服的消息现在全部是自动回复，没有人工回复的功能，
            有些自动回复不了的要人工去处理回复」。
  人工回复要和 AI 明显不同：头像换成「人」、气泡描金边、加一个「人工客服」标签，
  访客一眼能看出「这是真人在回我」，而不是又一句机器回复。
*/
.aic-mini--agent {
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, #3f4753, #22272e);
  color: #f4e2bd;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}
.aic-msg.is-agent .aic-bubble {
  border-color: rgba(194, 145, 58, 0.5);
  background: linear-gradient(180deg, #fffdf7, #fff8ea);
  box-shadow: 0 1px 2px rgba(194, 145, 58, 0.12);
}
.aic-agent-tag {
  display: inline-block;
  margin-bottom: 5px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(194, 145, 58, 0.16);
  color: #8a621c;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

/* ---- 引用回复：人工回复里显示「在回哪一句」 ---- */
.aic-quote {
  margin-bottom: 7px;
  padding: 5px 9px;
  border-left: 3px solid rgba(194, 145, 58, 0.55);
  border-radius: 0 7px 7px 0;
  background: rgba(194, 145, 58, 0.09);
  font-size: 12px;
  line-height: 1.55;
  color: #6b5a33;
}
.aic-quote b {
  margin-right: 5px;
  color: #8a621c;
}
.aic-quote-gone {
  color: #9aa2ac;
  font-style: italic;
}

/* ---- 未读徽章（人工回复）：访客一眼知道有没有新回复 ----
   用户反馈：「前台收到回复应该有个提示徽章访客才知道有没有收到回复」。
   小红点太弱，这里用带数字的红色徽章。 */
.aic-fab-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #d9433c;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 0 0 2px #fff;
  pointer-events: none;
}
.aic-fab-badge[hidden] {
  display: none;
}
/* 有未读时按钮轻轻呼吸，别太吵 */
.aic-fab.has-unread {
  animation: aic-nudge 2.4s ease-in-out infinite;
}
@keyframes aic-nudge {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}
@media (prefers-reduced-motion: reduce) {
  .aic-fab.has-unread { animation: none; }
}

/* 面板里「人工客服回复了 · 点击查看」的胶囊 */
.aic-pill {
  display: block;
  width: calc(100% - 28px);
  margin: 0 14px 8px;
  padding: 8px 12px;
  border: 1px solid rgba(194, 145, 58, 0.4);
  border-radius: 999px;
  background: linear-gradient(180deg, #fffdf7, #fff6e6);
  color: #8a621c;
  font-size: 12.5px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  box-shadow: 0 2px 8px rgba(194, 145, 58, 0.16);
}
.aic-pill:hover {
  background: #fff3dc;
}
.aic-pill[hidden] {
  display: none;
}
.aic-bubble {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.72;
  word-break: break-word;
  background: #fff;
  color: #2b313a;
  border: 1px solid var(--aic-line);
  border-top-left-radius: 5px;
  box-shadow: 0 2px 8px rgba(16, 18, 22, 0.05);
}
.aic-msg.is-me .aic-bubble {
  border-color: transparent;
  border-top-left-radius: 14px;
  border-top-right-radius: 5px;
  background: linear-gradient(135deg, #2b313a, #1c2027);
  color: #fff;
}

/* 打字指示 */
.aic-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  height: 18px;
}
.aic-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--aic-gold);
  animation: aic-bounce 1.1s infinite ease-in-out;
}
.aic-typing i:nth-child(2) {
  animation-delay: 0.16s;
}
.aic-typing i:nth-child(3) {
  animation-delay: 0.32s;
}
@keyframes aic-bounce {
  0%,
  70%,
  100% {
    transform: translateY(0);
    opacity: 0.42;
  }
  35% {
    transform: translateY(-4px);
    opacity: 1;
  }
}
/* 光标：正在逐字输出时跟在文字后面 */
.aic-stream::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 13px;
  margin-left: 2px;
  vertical-align: -2px;
  background: var(--aic-gold);
  animation: aic-caret 0.9s steps(1) infinite;
}
.aic-msg.is-me .aic-stream::after {
  display: none;
}
@keyframes aic-caret {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

/* ---------------- 留资表单 ---------------- */
.aic-lead {
  margin: 4px 0 14px;
  padding: 13px;
  border: 1px solid var(--aic-line);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 2px 10px rgba(16, 18, 22, 0.05);
}
.aic-lead-t {
  margin-bottom: 9px;
  font-size: 13px;
  font-weight: 700;
  color: var(--aic-ink);
}
.aic-lead-i {
  display: block;
  width: 100%;
  height: 40px;
  margin-bottom: 8px;
  padding: 0 12px;
  border: 1px solid var(--aic-line);
  border-radius: 10px;
  background: #fbfaf8;
  color: var(--aic-ink);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  appearance: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}
.aic-lead-i:focus {
  border-color: var(--aic-gold);
  box-shadow: 0 0 0 3px rgba(194, 145, 58, 0.14);
}
.aic-lead-b {
  width: 100%;
  height: 42px;
  border: 0;
  border-radius: 11px;
  cursor: pointer;
  color: #fff;
  font-size: 13.5px;
  font-weight: 700;
  font-family: inherit;
  background: linear-gradient(135deg, var(--aic-gold-lt), var(--aic-gold));
  box-shadow: 0 6px 16px rgba(194, 145, 58, 0.3);
  transition: transform 0.18s, box-shadow 0.18s;
}
.aic-lead-b:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(194, 145, 58, 0.38);
}
.aic-lead-e {
  min-height: 16px;
  margin-top: 6px;
  font-size: 12px;
  color: #d1554f;
}

/* ---------------- 快捷问题 ---------------- */
/*
  快捷问题一行横向滚动。
  要点：
    · overflow-x: auto —— 放不下就左右滑，不换行、不挤扁
    · 子项 flex: none + nowrap —— 每个 chip 保持完整宽度
    · 隐藏滚动条 + 右边缘渐隐 —— 手机上不占高度，同时暗示「还能往右滑」
  注意：**不要加 scroll-snap**。加了之后点一个 chip 浏览器会把它居中，
  再配合吸附，手感像「自己跳走」，用户反馈过「想点前面的就回不去了」。
  （真正的根因是 AI 追问建议覆盖了原问题，已在 ai.js 修掉；
    这里也把吸附去掉，避免任何自动跳动的观感。）
*/
.aic-quick {
  display: flex;
  gap: 7px;
  flex: none;
  padding: 9px 14px;
  overflow-x: auto;
  overflow-y: hidden;
  border-top: 1px solid var(--aic-line);
  background: #fff;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  /* 右边缘渐隐，提示「右边还有内容可以滑」 */
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent);
  mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent);
}
.aic-quick::-webkit-scrollbar {
  display: none;
}
/* 「追问」分隔：把后台配置的问题和 AI 的追问建议分开，一眼看出区别 */
.aic-quick-sep {
  flex: none;
  align-self: center;
  padding: 0 2px;
  font-size: 11px;
  color: var(--aic-gold);
  font-weight: 700;
  letter-spacing: 0.04em;
  opacity: 0.75;
}

/*
  左右箭头按钮。
  ------------------------------------------------------------
  为什么必须要它：这一行一直是 overflow-x: auto，但滚动条被隐藏了，
  桌面上又没有手势可用（Shift+滚轮 / 拖动基本没人会），
  结果用户只看到 3 个问题，还以为「只能看到部分内容」（提过多次）。
  箭头用 position: sticky 钉在容器两端，chip 从它下面滑过去；
  内容不超出时 JS 会把它们藏起来，不会白占位置。
*/
.aic-quick-nav {
  flex: none;
  position: sticky;
  z-index: 2;
  align-self: center;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--aic-line);
  border-radius: 50%;
  background: #fff;
  color: #4a515b;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(16, 18, 22, 0.1);
  transition: all 0.18s;
}
.aic-quick-nav.is-prev {
  left: -2px;
  margin-right: 1px;
}
.aic-quick-nav.is-next {
  right: -2px;
  margin-left: 1px;
}
.aic-quick-nav:hover {
  border-color: var(--aic-gold);
  color: var(--aic-gold);
  background: rgba(194, 145, 58, 0.08);
}
.aic-quick-nav[hidden] {
  display: none;
}
.aic-chip {
  flex: none;
  padding: 7px 12px;
  border: 1px solid var(--aic-line);
  border-radius: 99px;
  cursor: pointer;
  color: #4a515b;
  font-size: 12.5px;
  font-family: inherit;
  background: #fbfaf8;
  white-space: nowrap;
  transition: all 0.18s;
}
.aic-chip:hover {
  border-color: var(--aic-gold);
  color: var(--aic-gold);
  background: rgba(194, 145, 58, 0.07);
}
.aic-chip.is-handoff {
  border-color: rgba(194, 145, 58, 0.4);
  color: var(--aic-gold);
  font-weight: 600;
}
/*
  AI 的追问建议：视觉上比后台配置的问题「轻」一点，
 一眼能分辨「哪些是我预设的，哪些是 AI 顺着刚才的话给的」。
*/
.aic-chip.is-followup {
  border-style: dashed;
  color: #5a6371;
  background: #fff;
}

/* ---------------- 输入区 ---------------- */
.aic-foot {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex: none;
  padding: 10px 14px 6px;
  background: #fff;
}
.aic-input {
  flex: 1;
  min-height: 42px;
  max-height: 96px;
  padding: 11px 13px;
  border: 1px solid var(--aic-line);
  border-radius: 12px;
  background: #fbfaf8;
  color: var(--aic-ink);
  font-size: 13.5px;
  line-height: 1.5;
  font-family: inherit;
  resize: none;
  outline: none;
  appearance: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}
.aic-input:focus {
  border-color: var(--aic-gold);
  box-shadow: 0 0 0 3px rgba(194, 145, 58, 0.14);
}
.aic-input::placeholder {
  color: #9aa2ad;
}
.aic-send {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: none;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, var(--aic-gold-lt), var(--aic-gold));
  box-shadow: 0 6px 16px rgba(194, 145, 58, 0.28);
  transition: transform 0.18s;
}
.aic-send:hover {
  transform: translateY(-1px);
}
.aic-send:active {
  transform: scale(0.95);
}
.aic-foot-tip {
  flex: none;
  padding: 0 14px 10px;
  font-size: 11px;
  color: #9aa2ad;
  background: #fff;
}
.aic-link {
  padding: 0;
  border: 0;
  cursor: pointer;
  color: var(--aic-gold);
  font-size: 11px;
  font-family: inherit;
  background: none;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---------------- 手机 / 窄屏 ---------------- */
@media (max-width: 600px) {
  .aic {
    right: 14px;
    bottom: 14px;
  }
  .aic-fab {
    width: 52px;
    height: 52px;
  }
  /*
    手机上面板接近全屏，位置同样由 JS 的 left/top 决定；
    这里只收窄与四周的间距，避免贴边。
    高度用 dvh：手机浏览器的 vh 是「地址栏收起时」的高度，
    用 vh 算出来的面板会比实际可见区域高，底部输入框容易被顶到屏幕外。
    先写 vh 兜底，再写 dvh 给支持的浏览器覆盖。
  */
  .aic-panel {
    width: min(384px, calc(100vw - 16px));
    height: min(78vh, 560px);
    height: min(78dvh, 560px);
    border-radius: 18px;
  }
  .aic-bubble {
    max-width: 86%;
    font-size: 14px;
  }
  .aic-input {
    min-height: 44px;
    font-size: 15px; /* 小于 16px 在 iOS 上会触发缩放 */
  }
  .aic-lead-i {
    height: 44px;
    font-size: 15px;
  }
  .aic-chip {
    padding: 8px 13px;
    font-size: 13px;
  }
}
@media (max-height: 560px) {
  .aic-panel {
    height: calc(100vh - 40px);
  }
}
/* 用户系统设置了「减少动效」时，去掉动画 */
@media (prefers-reduced-motion: reduce) {
  .aic-fab,
  .aic-panel,
  .aic-chip,
  .aic-send {
    transition: none;
  }
  .aic-typing i {
    animation: none;
  }
  .aic-stream::after {
    animation: none;
  }
}

/* ============================================================
   「以上是您上次的对话记录」
   ------------------------------------------------------------
   刷新后会把上次的对话重画出来，中间加一条分隔提示，
   让访客知道上面那些不是刚说的。
   ============================================================ */
.aic-restored {
  margin: 10px 0 4px;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-soft, #8b939c);
  letter-spacing: .02em;
}
.aic-restored::before,
.aic-restored::after {
  content: "";
  display: inline-block;
  width: 26px;
  height: 1px;
  margin: 0 8px;
  vertical-align: middle;
  background: currentColor;
  opacity: .35;
}
