/* ============================================================
 *  AI 智能客服样式（PC 悬浮 + 移动端手势）
 *  注意：
 *   - 本模块默认零 DOM，触发后才追加
 *   - 使用统一前缀 aics- 避免污染页面样式
 *   - 响应式：>= 768px PC 模式；< 768px 移动端全屏
 * ============================================================ */

/* ---------- 根容器（隐藏态，触发激活后移除） ---------- */
#aics-root { all: unset; }
#aics-root *, #aics-root *::before, #aics-root *::after { box-sizing: border-box; }

/* ---------- PC 悬浮召唤按钮（固定右下角，移动端隐藏） ----------
   用户要求：不使用传统圆形头像框，直接展示人像（圆角矩形，自然裁剪出客服制服+头部）*/
#aics-fab {
  position: fixed;
  right: 20px;
  bottom: 96px;
  width: 62px;
  height: 72px;
  border-radius: 18px 18px 22px 22px / 20px 20px 26px 26px;
  background: #fff;
  color: #fff;
  box-shadow: 0 10px 28px rgba(99,102,241,0.35), 0 4px 14px rgba(0,0,0,0.14);
  display: flex;
  align-items: stretch;
  justify-content: center;
  cursor: pointer;
  z-index: 2147483000;
  transition: transform .2s ease, box-shadow .2s ease, opacity .2s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overflow: visible;
  padding: 0;
  border: 2px solid #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
#aics-fab:hover { transform: translateY(-3px) scale(1.04); box-shadow: 0 16px 42px rgba(99,102,241,.44), 0 6px 18px rgba(0,0,0,.16); }
#aics-fab:active { transform: scale(.96); }
#aics-fab svg { width: 26px; height: 26px; }
#aics-fab img { width: 100%; height: 100%; display: block; object-fit: cover; object-position: top center; border-radius: inherit; }
#aics-fab[data-active="1"] { opacity: 0; pointer-events: none; transform: scale(.85); }

/* 脉冲红点（可选提示小动效） */
#aics-fab::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 0 0 rgba(239,68,68,.6);
  animation: aics-pulse 2s infinite;
}
@keyframes aics-pulse {
  0% { box-shadow: 0 0 0 0 rgba(239,68,68,.55); }
  70% { box-shadow: 0 0 0 10px rgba(239,68,68,0); }
  100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); }
}

/* ---------- PC 悬浮面板（< md 隐藏，切到全屏移动端模式） ---------- */
#aics-panel {
  position: fixed;
  right: 20px;
  bottom: 96px;
  width: min(380px, calc(100vw - 40px));
  height: min(600px, calc(100vh - 180px));
  background: #ffffff;
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.18), 0 8px 24px rgba(15, 23, 42, 0.08);
  z-index: 2147483001;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: #0f172a;
  transform-origin: bottom right;
  animation: aics-pop .22s ease-out both;
}
#aics-panel[data-open="1"] { display: flex; }
@keyframes aics-pop {
  from { opacity: 0; transform: translateY(12px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* 顶部条 */
.aics-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: linear-gradient(135deg, #4f46e5 0%, #6366f1 50%, #8b5cf6 100%);
  color: #fff;
  flex: 0 0 auto;
}
.aics-head .aics-ava {
  width: 42px; height: 50px; border-radius: 14px 14px 18px 18px / 16px 16px 20px 20px;
  background: #fff;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  border: 2px solid #ffffff;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.12);
}
.aics-head .aics-ava img { width: 100%; height: 100%; object-fit: cover; object-position: top center; display: block; border-radius: inherit; }
.aics-head .aics-title { font-weight: 600; font-size: 15px; line-height: 1.2; }
.aics-head .aics-sub { font-size: 11px; opacity: .85; margin-top: 2px; }
.aics-head .aics-head-spacer { flex: 1; }
.aics-head .aics-close {
  width: 28px; height: 28px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: #fff; background: rgba(255,255,255,.14);
  transition: background .15s; border: 0; padding: 0;
}
.aics-head .aics-close:hover { background: rgba(255,255,255,.26); }
.aics-head .aics-voice {
  width: 28px; height: 28px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: #fff; background: rgba(255,255,255,.14);
  transition: background .15s, transform .12s; border: 0; padding: 0;
  margin-right: 6px;
}
.aics-head .aics-voice:hover { background: rgba(255,255,255,.26); transform: translateY(-1px); }
.aics-head .aics-voice[aria-pressed="false"] { opacity: .78; }
@media (max-width: 640px) {
  .aics-head .aics-voice { margin-right: 4px; }
}

/* 消息列表 */
.aics-messages {
  flex: 1 1 auto;
  padding: 14px 14px 10px;
  overflow-y: auto;
  background:
    radial-gradient(1200px 60px at 0% 0%, rgba(99,102,241,.05), transparent 60%),
    #f8fafc;
  scroll-behavior: smooth;
}
.aics-messages::-webkit-scrollbar { width: 6px; }
.aics-messages::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 3px; }

.aics-msg-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  align-items: flex-end;
  animation: aics-fade-in .18s ease-out both;
}
@keyframes aics-fade-in { from { opacity: 0; transform: translateY(4px);} to {opacity:1; transform:none;} }
.aics-msg-row.aics-me { justify-content: flex-end; }

.aics-bubble {
  max-width: 82%;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.aics-ai .aics-bubble {
  background: #fff;
  color: #0f172a;
  border: 1px solid #eef2f7;
  border-bottom-left-radius: 4px;
}
.aics-me .aics-bubble {
  background: linear-gradient(135deg, #6366f1, #818cf8);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.aics-ai .aics-chip {
  display: inline-block;
  padding: 1px 6px;
  margin-left: 6px;
  border-radius: 999px;
  font-size: 10px;
  background: #eef2ff;
  color: #4f46e5;
  vertical-align: middle;
}
.aics-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px 8px;
  margin-top: -2px;
}
.aics-quick button {
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #4f46e5;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}
.aics-quick button:hover { background: #eef2ff; border-color: #c7d2fe; }

/* 输入区 */
.aics-input-row {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 12px;
  background: #fff;
  border-top: 1px solid #f1f5f9;
}
.aics-input-row textarea {
  flex: 1;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  max-height: 120px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
  color: inherit;
}
.aics-input-row textarea:focus {
  border-color: #818cf8;
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.aics-send {
  border: 0;
  padding: 0 16px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: transform .12s, opacity .12s;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 6px;
}
.aics-send:hover { opacity: .92; }
.aics-send:active { transform: scale(.97); }
.aics-send:disabled { opacity: .55; cursor: not-allowed; }

/* 打字机点点 */
.aics-typing { display: inline-flex; gap: 4px; align-items: center; }
.aics-typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: #94a3b8; display: inline-block;
  animation: aics-dot 1.2s infinite ease-in-out;
}
.aics-typing i:nth-child(2) { animation-delay: .15s; }
.aics-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes aics-dot {
  0%, 80%, 100% { transform: scale(.7); opacity: .4; }
  40% { transform: scale(1); opacity: 1; }
}

/* 移动端全屏遮罩（< 768px） */
#aics-mobile-shade {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 2147483002;
  display: none;
  align-items: flex-end;
  justify-content: center;
  animation: aics-shade-fade .18s ease-out both;
}
#aics-mobile-shade[data-open="1"] { display: flex; }
@keyframes aics-shade-fade { from {opacity:0;} to {opacity:1;} }

#aics-mobile-panel {
  width: 100%;
  height: 92vh;
  background: #fff;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 2147483003;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: #0f172a;
  animation: aics-slide-up .24s ease-out both;
}
#aics-mobile-panel[data-open="1"] { display: flex; }
@keyframes aics-slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* 手势提示轻提示 toast */
#aics-toast {
  position: fixed;
  left: 50%;
  top: 28%;
  transform: translateX(-50%);
  padding: 10px 18px;
  background: rgba(15, 23, 42, 0.86);
  color: #fff;
  border-radius: 10px;
  font-size: 13px;
  z-index: 2147483004;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
#aics-toast[data-show="1"] { opacity: 1; }

/* ---------- 响应式断点：移动端（< 768px） ---------- */
@media (max-width: 767.98px) {
  /* 移动端隐藏 PC 悬浮 FAB，避免和手势冲突，保持零打扰 */
  #aics-fab { display: none !important; }
  /* 移动端隐藏 PC 面板 */
  #aics-panel { display: none !important; }
  #aics-panel[data-open="1"] { display: none !important; }
}
/* ≥ 768：PC 模式，不显示移动端遮罩/面板 */
@media (min-width: 768px) {
  #aics-mobile-shade { display: none !important; }
  #aics-mobile-panel { display: none !important; }
}
