/* 社区智能助手「小悦」· 悬浮组件样式
 * v93.12 升级要点：
 *   ①主题跟随：全量改用站点皮肤变量（--c-primary / --c-surface / --c-text …），
 *     换肤（data-skin）时小悦自动同步，不再写死旧版品牌绿；
 *   ②IP 形象美化：透明底立绘 + 主题渐变底盘 + 多层柔光晕 + 高光，三态光晕改为
 *     主题色（待机/欢迎/反馈）；头像缩放到「面部居中」的构图；
 *   ③无障碍：:focus-visible 焦点环、[hidden] 生效、装饰元素 aria-hidden；
 *   ④prefers-reduced-motion：呼吸/摇摆/打字点动画全部可关闭；
 *   ⑤修 bug：.ai-fab.dragging 原 `opacity .92` 漏冒号（无效声明被丢弃）；
 *   ⑥暗色皮肤适配（变量自带反色，无需分叉选择器）。
 * 层级：z-index 260（低于登录门 300 / 弹窗 400 / 灯箱 9999，高于播放控件 250）。 */

.ai-root {
  /* ---- AI 局部变量（主题变量兜底，独立可调） ---- */
  --ai-primary:    var(--c-primary, #7FA38C);
  --ai-primary-2:  var(--c-primary-2, #9DB89F);
  --ai-primary-3:  var(--c-primary-3, #B7CBAE);
  --ai-soft:       var(--c-primary-soft, #eef3ec);
  --ai-accent:     var(--c-accent, #D29377);
  --ai-surface:    var(--c-surface, #fffdf9);
  --ai-surface-2:  var(--c-surface-2, #f1e9de);
  --ai-border:     var(--c-border, #ece2d4);
  --ai-border-2:   var(--c-border-2, #ddd0bd);
  --ai-text:       var(--c-text, #43382e);
  --ai-text-2:     var(--c-text-2, #6e6354);
  --ai-text-3:     var(--c-text-3, #a99c89);
  --ai-red:        var(--c-red, #c0584e);
  --ai-red-soft:   var(--c-red-soft, #f7e6e3);
  --ai-grad:       var(--grad-brand, linear-gradient(135deg, #8FB59C 0%, #A9C2A3 100%));
  --ai-shadow-lg:  var(--shadow-lg, 0 14px 40px rgba(90,70,50,.13));

  position: fixed;
  right: 14px;
  bottom: 10px;
  z-index: 260;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
.ai-root * { box-sizing: border-box; }

/* ============================================================
 * 悬浮球（小悦形象 · 主题跟随 + 柔光晕）
 * ============================================================ */
.ai-fab {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  /* 主题渐变底盘（立绘透明，底盘提供与皮肤一致的气泡感） */
  background: var(--ai-grad);
  box-shadow:
    0 8px 22px rgba(0, 0, 0, .16),
    0 2px 6px rgba(0, 0, 0, .08),
    0 0 0 2px rgba(255, 255, 255, .82),  /* 旧内核兜底 */
    0 0 0 2px color-mix(in srgb, var(--ai-surface) 85%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, .55);
  transition: box-shadow .3s ease, transform .25s cubic-bezier(.22, 1, .36, 1);
  animation: ai-breathe 3.6s ease-in-out infinite, ai-sway 6s ease-in-out infinite;
  isolation: isolate;
}
/* 内圈高光：让形象与底盘之间有「柔光亚克力」层次 */
.ai-fab::before {
  content: '';
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 26%, rgba(255,255,255,.92) 0%, rgba(255,255,255,.42) 34%, rgba(255,255,255,0) 68%);
  pointer-events: none;
  z-index: 1;
}
/* 外圈柔光晕：随状态换色，静态柔和呼吸 */
.ai-fab::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(127, 163, 140, .42) 0%, transparent 70%); /* 旧内核兜底 */
  background: radial-gradient(circle, color-mix(in srgb, var(--ai-primary) 42%, transparent) 0%, transparent 70%);
  opacity: .75;
  pointer-events: none;
  transition: background .35s ease, opacity .35s ease;
  z-index: -1;
}
.ai-fab img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* 方图→方框时 object-position 不产生位移，构图实际由下面的 transform 完成：
   * scale(1.14) + origin(50% 30%) 把面部推到圆内黄金区（经离屏模拟验证，
   * 顶饰仅轻微贴边、不切脸）。 */
  object-position: 50% 30%;
  transform: scale(1.14);
  transform-origin: 50% 30%;
  pointer-events: none;
  border-radius: 50%;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .18));
  transition: opacity .28s ease, transform .28s cubic-bezier(.22, 1, .36, 1);
  z-index: 2;
}
.ai-fab img.ai-fab-switching {
  opacity: 0;
  transform: scale(1.03);
}

/* ---- 每态光晕差异化（v93.12：改用主题色系） ---- */
/* 待机：主色柔光，静谧 */
.ai-fab.ai-fab-state-idle::after {
  background: radial-gradient(circle, rgba(127, 163, 140, .42) 0%, transparent 70%);
  background: radial-gradient(circle, color-mix(in srgb, var(--ai-primary) 42%, transparent) 0%, transparent 70%);
  opacity: .7;
}
/* 欢迎：暖橙点缀色，活泼亲切 */
.ai-fab.ai-fab-state-welcome {
  animation: ai-breathe 2.4s ease-in-out infinite, ai-sway 3.4s ease-in-out infinite;
}
.ai-fab.ai-fab-state-welcome::after {
  background: radial-gradient(circle, rgba(210, 147, 119, .55) 0%, transparent 70%);
  background: radial-gradient(circle, color-mix(in srgb, var(--ai-accent) 55%, transparent) 0%, transparent 70%);
  opacity: .95;
}
/* 反馈：柔红爱心色，与「比心」呼应 */
.ai-fab.ai-fab-state-feedback::after {
  background: radial-gradient(circle, rgba(192, 88, 78, .55) 0%, transparent 70%);
  background: radial-gradient(circle, color-mix(in srgb, var(--ai-red) 55%, transparent) 0%, transparent 70%);
  opacity: 1;
}

.ai-fab:hover { transform: scale(1.06); }
.ai-fab:active { transform: scale(.95); }
.ai-fab:focus-visible {
  outline: 3px solid var(--ai-accent);
  outline-offset: 3px;
}
.ai-fab.active {
  animation: none;
  box-shadow:
    0 4px 14px rgba(0, 0, 0, .18),
    inset 0 1px 0 rgba(255, 255, 255, .45);
}
.ai-fab.dragging {
  cursor: grabbing;
  animation: none !important;   /* 拖拽时暂停动画（v93.12 修：原声明漏冒号被丢弃） */
  opacity: .92;
}

/* ---------- 动画关键帧 ---------- */
@keyframes ai-breathe {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-4px) scale(1.04); }
}
@keyframes ai-sway {
  0%, 100% { transform: rotate(0deg); }
  25%      { transform: rotate(2.2deg); }
  75%      { transform: rotate(-2.2deg); }
}

/* ---------- 引导气泡 ---------- */
.ai-tip {
  position: absolute;
  bottom: 78px;
  right: -4px;
  background: var(--ai-surface);
  border: 1px solid var(--ai-border);
  border-radius: 16px;
  padding: 10px 18px;
  font-size: 13.5px;
  color: var(--ai-text-2);
  box-shadow: var(--ai-shadow-lg);
  white-space: nowrap;
  opacity: 0;
  transform: translateY(10px) scale(.92);
  transition: opacity .4s cubic-bezier(.22, 1, .36, 1), transform .4s cubic-bezier(.22, 1, .36, 1);
  pointer-events: none;
  z-index: 259;
  font-weight: 500;
  letter-spacing: .3px;
}
.ai-tip span { color: var(--ai-text-2); }
/* "小悦" 用主题点缀色高亮 —— IP 视觉标识 */
.ai-tip .ai-tip-name {
  color: var(--ai-accent);
  font-weight: 700;
  font-size: 1.06em;
}
.ai-tip.show { opacity: 1; transform: translateY(0) scale(1); }
/* 气泡小三角 */
.ai-tip i {
  position: absolute;
  bottom: -8px;
  right: 22px;
  width: 16px;
  height: 16px;
  background: var(--ai-surface);
  border-right: 1px solid var(--ai-border);
  border-bottom: 1px solid var(--ai-border);
  transform: rotate(45deg);
  border-radius: 0 0 3px 0;
}

/* ---------- 聊天面板（v93.14：fixed 定位，几何由 JS 接管） ---------- */
.ai-panel {
  position: fixed;
  left: 0;            /* 实际 left/top/width/height 由 JS(placePanel/拖拽/拉伸/最大化)接管 */
  top: 0;
  width: 360px;
  height: 520px;
  background: var(--ai-surface);
  color: var(--ai-text);
  border-radius: 16px;
  box-shadow: var(--ai-shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--ai-border);
  transform-origin: bottom right;                 /* 从悬浮球方向弹出 / 折叠 */
  animation: ai-panel-in .28s cubic-bezier(.34, 1.4, .5, 1);  /* 回弹进场 */
  will-change: left, top, width, height;
}
.ai-panel[hidden] { display: none; }
@keyframes ai-panel-in {
  from { opacity: 0; transform: translateY(14px) scale(.9); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- 八向自由拉伸手柄（四边 + 四角，置于面板内边缘，不被 overflow 裁切） ---------- */
.ai-rsz { position: absolute; z-index: 12; }
.ai-rsz.n  { top: 0;    left: 12px; right: 12px; height: 6px;  cursor: ns-resize; }
.ai-rsz.s  { bottom: 0; left: 12px; right: 12px; height: 6px;  cursor: ns-resize; }
.ai-rsz.e  { right: 0;  top: 12px; bottom: 12px; width: 6px;   cursor: ew-resize; }
.ai-rsz.w  { left: 0;   top: 12px; bottom: 12px; width: 6px;   cursor: ew-resize; }
.ai-rsz.ne { top: 0;    right: 0;  width: 16px; height: 16px;  cursor: nesw-resize; }
.ai-rsz.nw { top: 0;    left: 0;   width: 16px; height: 16px;  cursor: nwse-resize; }
.ai-rsz.se { bottom: 0; right: 0;  width: 16px; height: 16px;  cursor: nwse-resize; }
.ai-rsz.sw { bottom: 0; left: 0;   width: 16px; height: 16px;  cursor: nesw-resize; }
.ai-rsz:hover { background: color-mix(in srgb, var(--ai-primary) 22%, transparent); }
.ai-rsz.n:hover, .ai-rsz.s:hover { border-radius: 0 0 6px 6px; }
.ai-rsz.e:hover, .ai-rsz.w:hover { border-radius: 6px 0 0 6px; }

/* ---------- 最大化态（填满视口留 12px 边距，隐藏拉伸手柄） ---------- */
.ai-panel.max {
  border-radius: 10px;
  box-shadow: 0 18px 60px rgba(60, 45, 30, .22);
}
.ai-panel.max .ai-rsz { display: none; }

/* ---------- 面板头部 ---------- */
.ai-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--ai-grad);
  color: #fff;
  cursor: grab;
  flex-shrink: 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .12);
}
.ai-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; cursor: default; }
.ai-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #8ff0b0;
  box-shadow: 0 0 0 3px rgba(143, 240, 176, .35);
  flex: 0 0 auto;
}
.ai-head-ops { display: flex; gap: 4px; }
.ai-ic {
  width: 30px; height: 30px; border: none; background: rgba(255, 255, 255, .16);
  color: #fff; border-radius: 8px; cursor: pointer; font-size: 14px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.ai-ic:hover { background: rgba(255, 255, 255, .3); }
.ai-ic:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

/* ---------- 消息区 ---------- */
.ai-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  background: var(--ai-surface-2);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overscroll-behavior: contain;
}
.ai-msg { display: flex; align-items: flex-start; gap: 8px; max-width: 100%; }
.ai-msg.me { justify-content: flex-end; }
/* 小悦迷你头像（IP 强化：每条 AI 消息左侧） */
.ai-ava {
  flex: 0 0 auto;
  width: 28px; height: 28px; border-radius: 50%;
  overflow: hidden; margin-top: 2px;
  background: var(--ai-grad);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .14), 0 0 0 1.5px rgba(255, 255, 255, .85);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .14), 0 0 0 1.5px color-mix(in srgb, var(--ai-surface) 90%, transparent);
}
.ai-ava img {
  width: 100%; height: 100%; object-fit: cover;
  object-position: 50% 30%; transform: scale(1.14); transform-origin: 50% 30%;
  display: block;
}
.ai-bubble {
  max-width: 84%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  white-space: normal;
}
.ai-msg.ai .ai-bubble {
  background: var(--ai-surface);
  border: 1px solid var(--ai-border);
  border-bottom-left-radius: 4px;
  color: var(--ai-text);
}
.ai-msg.me .ai-bubble {
  background: var(--ai-grad);
  color: #fff;
  border-bottom-right-radius: 4px;
}
/* 轻量 markdown 渲染 */
.ai-bubble p { margin: 0 0 6px; }
.ai-bubble p:last-child { margin-bottom: 0; }
.ai-bubble ul { margin: 4px 0; padding-left: 18px; }
.ai-bubble li { margin: 2px 0; }
.ai-bubble blockquote {
  margin: 6px 0; padding: 6px 10px;
  border-left: 3px solid var(--ai-primary);
  background: rgba(127, 163, 140, .10);
  background: color-mix(in srgb, var(--ai-primary) 10%, transparent);
  color: var(--ai-text-2); border-radius: 0 6px 6px 0; font-size: 13px;
}
.ai-bubble strong { font-weight: 700; }
.ai-bubble a.ai-link { color: var(--ai-primary); text-decoration: underline; cursor: pointer; }
.ai-bubble a.ai-link:hover { opacity: .82; }
.ai-msg.me .ai-bubble a.ai-link { color: #eafff4; }

.ai-err { color: var(--ai-red) !important; background: var(--ai-red-soft) !important; border: 1px solid var(--ai-red) !important; }

/* 操作按钮（转人工 / 站内跳转） */
.ai-acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.ai-act {
  display: inline-block; padding: 5px 10px; font-size: 13px; line-height: 1.3;
  border-radius: 16px;
  background: rgba(127, 163, 140, .13);
  background: color-mix(in srgb, var(--ai-primary) 13%, transparent);
  color: var(--ai-primary);
  text-decoration: none; cursor: pointer;
  border: 1px solid rgba(127, 163, 140, .28);
  border: 1px solid color-mix(in srgb, var(--ai-primary) 28%, transparent);
}
.ai-act:hover { background: rgba(127, 163, 140, .24); background: color-mix(in srgb, var(--ai-primary) 24%, transparent); }
.ai-act.ghost { background: transparent; }

/* 打字光标 + 加载三点 */
.ai-caret { color: var(--ai-primary); font-weight: 700; }
.ai-typing { display: inline-flex; gap: 4px; align-items: center; }
.ai-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ai-primary-2, #b3c6bf); animation: ai-blink 1.2s infinite both; }
.ai-typing i:nth-child(2) { animation-delay: .2s; }
.ai-typing i:nth-child(3) { animation-delay: .4s; }
@keyframes ai-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- 快捷问题 ---------- */
.ai-quick { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 8px; background: var(--ai-surface-2); flex-shrink: 0; }
.ai-quick[hidden] { display: none; }
.ai-q {
  padding: 5px 11px; font-size: 12.5px; border-radius: 14px; cursor: pointer;
  background: var(--ai-surface); border: 1px solid var(--ai-border); color: var(--ai-text-2);
  transition: all .15s;
}
.ai-q:hover { background: var(--ai-soft); border-color: var(--ai-primary); color: var(--ai-primary); }
.ai-q:focus-visible { outline: 2px solid var(--ai-primary); outline-offset: 1px; }

/* ---------- 底部栏 ---------- */
.ai-foot { padding: 6px 12px 2px; background: var(--ai-surface-2); flex-shrink: 0; }
.ai-human {
  width: 100%; padding: 7px; font-size: 13px; cursor: pointer;
  background: var(--ai-surface); border: 1px dashed var(--ai-border-2); color: var(--ai-text-2);
  border-radius: 10px; transition: all .15s;
}
.ai-human:hover { background: var(--ai-soft); border-color: var(--ai-primary); color: var(--ai-primary); }

/* ---------- 输入框 ---------- */
.ai-input { display: flex; gap: 8px; padding: 8px 12px 12px; background: var(--ai-surface-2); border-top: 1px solid var(--ai-border); flex-shrink: 0; }
.ai-input textarea {
  flex: 1; resize: none; border: 1px solid var(--ai-border-2); border-radius: 12px; padding: 9px 11px;
  font-size: 14px; line-height: 1.4; max-height: 90px; font-family: inherit; outline: none;
  background: var(--ai-surface); color: var(--ai-text);
}
.ai-input textarea::placeholder { color: var(--ai-text-3); }
.ai-input textarea:focus {
  border-color: var(--ai-primary);
  box-shadow: 0 0 0 2px rgba(127, 163, 140, .22);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ai-primary) 18%, transparent);
}
.ai-send {
  flex: 0 0 auto; align-self: end; padding: 0 16px; height: 38px; border: none; border-radius: 12px;
  background: var(--ai-grad); color: #fff; font-size: 14px; cursor: pointer;
  transition: opacity .15s, transform .12s;
}
.ai-send:hover { opacity: .9; }
.ai-send:active { transform: scale(.97); }
.ai-send:disabled { opacity: .5; cursor: default; }

/* ---------- 转人工工单浮层 ---------- */
.ai-ticket {
  position: fixed; inset: 0; z-index: 400; background: rgba(20, 30, 26, .5);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.ai-ticket[hidden] { display: none; }
.ai-ticket-box {
  width: 360px; max-width: 100%; background: var(--ai-surface); color: var(--ai-text);
  border-radius: 16px; padding: 18px; box-shadow: 0 16px 50px rgba(0, 0, 0, .3);
}
.ai-ticket-h { font-size: 16px; font-weight: 700; margin-bottom: 12px; color: var(--ai-text); }
.ai-sel, .ai-tarea {
  width: 100%; border: 1px solid var(--ai-border-2); border-radius: 10px; padding: 9px 11px; font-size: 14px;
  font-family: inherit; margin-bottom: 10px; outline: none;
  background: var(--ai-surface); color: var(--ai-text);
}
.ai-sel:focus, .ai-tarea:focus {
  border-color: var(--ai-primary);
  box-shadow: 0 0 0 2px rgba(127, 163, 140, .22);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ai-primary) 18%, transparent);
}
.ai-tarea { min-height: 90px; resize: vertical; }
.ai-ticket-ops { display: flex; justify-content: flex-end; gap: 8px; }
.btn { padding: 8px 16px; border-radius: 10px; border: 1px solid var(--ai-border-2); background: var(--ai-surface); color: var(--ai-text); cursor: pointer; font-size: 14px; }
.btn:hover { background: var(--ai-surface-2); }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn.primary { background: var(--ai-grad); color: #fff; border: none; }
.btn.primary:hover { opacity: .92; }
.btn.primary:disabled { opacity: .55; cursor: default; }

/* ---------- 移动端适配 ---------- */
@media (max-width: 480px) {
  .ai-root { right: 8px; bottom: max(6px, env(safe-area-inset-bottom)); }
  .ai-panel {
    left: 10px; top: 10px;
    width: calc(100vw - 20px);
    height: calc(100vh - 86px);
    max-height: calc(100vh - 86px);
    border-radius: 14px;
    animation: none;
  }
  .ai-fab { width: 58px; height: 58px; }
  .ai-tip { bottom: 70px; right: -4px; font-size: 12px; padding: 7px 13px; }
}

/* ---------- 动效偏好：减少动态 ---------- */
@media (prefers-reduced-motion: reduce) {
  .ai-fab,
  .ai-fab.ai-fab-state-welcome {
    animation: none !important;
  }
  .ai-fab:hover,
  .ai-fab:active { transform: none; }
  .ai-fab img { transition: opacity .12s linear; }
  .ai-tip { transition: opacity .12s linear; transform: none; }
  .ai-panel { animation: none; transition: none !important; }
  .ai-typing i { animation: none; opacity: .6; }
  .ai-caret { display: none; }
}
