/*
 * LinsGeek ERP —— AI 助理：每个页面右下角的聊天框（配合 61-ai-assistant.js）
 * 颜色、圆角、阴影沿用帮助卡片（21-side-help.css）。
 */

/* ---------- 入口：悬浮按钮组里的按钮 ---------- */
/* 外观沿用原悬浮按钮的 scoped 样式；下面是兜底 */
.layout-right-quick-actions .lg-ai-btn {
  width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: #0d7b6d; color: #fff; cursor: pointer;
}
.layout-right-quick-actions .lg-ai-btn,
.layout-right-quick-actions .lg-ai-btn.is-on { background: #0d7b6d !important; color: #fff !important; }
.layout-right-quick-actions .lg-ai-btn:hover { background: #0a6a5e !important; }
.layout-right-quick-actions .lg-ai-btn svg,
.layout-right-quick-actions .lg-ai-btn svg * { color: #fff !important; stroke: #fff !important; }
.layout-right-quick-actions .lg-ai-btn svg,
#lg-ai-fab svg {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- 入口：单独的圆形按钮（窄屏，或页面没有悬浮按钮组） ---------- */
#lg-ai-fab {
  position: fixed; z-index: 990; right: 16px; bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  width: 52px; height: 52px; padding: 0; border: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: #0d7b6d; color: #fff; cursor: pointer;
  box-shadow: 0 8px 22px rgba(13, 123, 109, .34), 0 2px 6px rgba(15, 35, 52, .12);
  transition: transform .14s ease, background .14s ease;
}
#lg-ai-fab[hidden] { display: none; }
#lg-ai-fab:hover { background: #0a6a5e; }
#lg-ai-fab:active { transform: scale(.94); }
#lg-ai-fab svg { width: 26px; height: 26px; }
/* 聊天框打开时（窄屏是整块面板）圆形按钮让位 */
body.lg-ai-open #lg-ai-fab { display: none; }

/* ---------- 聊天面板 ---------- */
#lg-ai-pop {
  position: fixed; z-index: 1000; right: 72px; bottom: 20px;
  width: 384px; max-width: calc(100vw - 96px);
  height: 580px; max-height: calc(100vh - 40px);
  display: flex; flex-direction: column; overflow: hidden;
  background: #fff; color: #1f2a37;
  border: 1px solid #e3e8ee; border-radius: 14px;
  box-shadow: 0 18px 48px rgba(15, 35, 52, .18), 0 2px 8px rgba(15, 35, 52, .06);
  font-size: 14px; line-height: 1.5;
  opacity: 0; visibility: hidden; pointer-events: none;
  transform: translateY(10px) scale(.98); transform-origin: right bottom;
  transition: opacity .16s ease, transform .16s ease, visibility 0s linear .16s;
}
#lg-ai-pop.is-open {
  opacity: 1; visibility: visible; pointer-events: auto; transform: none;
  transition: opacity .16s ease, transform .16s ease;
}
/* 悬浮按钮组不可见（汉堡菜单模式）：贴右边 */
body.lg-compact-nav #lg-ai-pop { right: 16px; max-width: calc(100vw - 32px); }
#lg-ai-pop svg {
  fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none;
}

/* 标题栏 */
#lg-ai-pop .lg-ai-hd {
  display: flex; align-items: center; gap: 10px; flex: none;
  padding: 12px 10px 12px 14px; background: #0d7b6d; color: #fff;
}
#lg-ai-pop .lg-ai-hd-ico {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center; background: rgba(255, 255, 255, .16);
}
#lg-ai-pop .lg-ai-hd-ico svg { width: 20px; height: 20px; }
#lg-ai-pop .lg-ai-hd-t { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#lg-ai-pop .lg-ai-hd-t strong { font-size: 15px; font-weight: 700; line-height: 1.25; }
#lg-ai-pop .lg-ai-hd-t small {
  font-size: 12px; opacity: .82; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#lg-ai-pop .lg-ai-ib {
  width: 32px; height: 32px; padding: 0; border: 0; border-radius: 8px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: transparent; color: #fff; cursor: pointer;
}
#lg-ai-pop .lg-ai-ib:hover, #lg-ai-pop .lg-ai-ib:focus-visible { background: rgba(255, 255, 255, .18); outline: none; }
#lg-ai-pop .lg-ai-ib svg { width: 18px; height: 18px; }

/* 消息区 */
#lg-ai-pop .lg-ai-bd {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 14px 12px 8px; background: #f6f8fa;
  display: flex; flex-direction: column; gap: 10px;
}
#lg-ai-pop .lg-ai-m { display: flex; flex-direction: column; align-items: flex-start; max-width: 100%; }
#lg-ai-pop .lg-ai-m.is-me { align-items: flex-end; }
#lg-ai-pop .lg-ai-b {
  max-width: 88%; padding: 9px 12px; border-radius: 14px 14px 14px 4px;
  background: #fff; border: 1px solid #e3e8ee; color: #1f2a37;
  overflow-wrap: anywhere; word-break: break-word;
}
#lg-ai-pop .lg-ai-m.is-me .lg-ai-b {
  background: #0d7b6d; border-color: #0d7b6d; color: #fff; border-radius: 14px 14px 4px 14px;
}
#lg-ai-pop .lg-ai-b p { margin: 0; }
#lg-ai-pop .lg-ai-b p + p, #lg-ai-pop .lg-ai-b ul + p, #lg-ai-pop .lg-ai-b p + ul { margin-top: 6px; }
#lg-ai-pop .lg-ai-b ul { margin: 0; padding-left: 18px; list-style: disc; }
#lg-ai-pop .lg-ai-b li { margin: 2px 0; }
#lg-ai-pop .lg-ai-b strong { font-weight: 700; }

/* 引用的帮助文章 */
#lg-ai-pop .lg-ai-src { margin-top: 8px; padding-top: 8px; border-top: 1px solid #eef1f4; display: flex; flex-direction: column; gap: 2px; }
#lg-ai-pop .lg-ai-src > span { font-size: 12px; color: #7a8594; }
#lg-ai-pop .lg-ai-src a {
  display: flex; align-items: center; gap: 6px; margin: 0 -6px; padding: 4px 6px; border-radius: 8px;
  color: #0d7b6d; text-decoration: none; font-size: 13px;
}
#lg-ai-pop .lg-ai-src a:hover, #lg-ai-pop .lg-ai-src a:focus-visible { background: #eef7f5; outline: none; }
#lg-ai-pop .lg-ai-src a svg { width: 15px; height: 15px; }
#lg-ai-pop .lg-ai-src a em { font-style: normal; flex: 1; min-width: 0; }

/* ---------- 人工客服 ---------- */
/* 按钮上的红点：面板关着时客服回复了 */
.lg-ai-btn.has-new, #lg-ai-fab.has-new { position: relative; }
.lg-ai-btn.has-new::after, #lg-ai-fab.has-new::after {
  content: ""; position: absolute; top: 2px; right: 2px; width: 10px; height: 10px; border-radius: 50%;
  background: #e5484d; border: 2px solid #fff; box-sizing: content-box;
}
/* 客服的消息：名字 + 浅绿气泡，和 AI 的白气泡区分开 */
#lg-ai-pop .lg-ai-who {
  display: flex; align-items: center; gap: 4px; margin: 0 0 3px 4px; font-size: 12px; color: #0d7b6d; font-weight: 600;
}
#lg-ai-pop .lg-ai-who svg { width: 14px; height: 14px; }
#lg-ai-pop .lg-ai-m.is-agent .lg-ai-b { background: #eef7f5; border-color: #cfe6e1; }
/* 系统提示（已转人工、人工已结束、AI 暂时没响应……）：居中的小字 */
#lg-ai-pop .lg-ai-sys {
  align-self: center; max-width: 92%; padding: 6px 12px; border-radius: 10px;
  background: #e9eef2; color: #55606e; font-size: 12px; line-height: 1.45; text-align: center;
}
#lg-ai-pop .lg-ai-sys p { margin: 0; }
/* 转人工按钮（AI 答不了时出现在回答 / 提示下面） */
#lg-ai-pop .lg-ai-tohuman,
#lg-ai-pop .lg-ai-sys button {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; padding: 6px 12px;
  border: 1px solid #0d7b6d; border-radius: 999px; background: #fff; color: #0d7b6d;
  font: inherit; font-size: 13px; cursor: pointer;
}
#lg-ai-pop .lg-ai-tohuman:hover, #lg-ai-pop .lg-ai-sys button:hover,
#lg-ai-pop .lg-ai-tohuman:focus-visible, #lg-ai-pop .lg-ai-sys button:focus-visible { background: #0d7b6d; color: #fff; outline: none; }
#lg-ai-pop .lg-ai-tohuman svg, #lg-ai-pop .lg-ai-sys button svg { width: 15px; height: 15px; }
/* 输入框上面那一行：随时可点的「转人工」/「结束人工」 */
#lg-ai-pop .lg-ai-bar {
  flex: none; display: flex; justify-content: flex-end; padding: 6px 12px 0; background: #fff; border-top: 1px solid #eef1f4;
}
#lg-ai-pop .lg-ai-bar button {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border: 0; border-radius: 8px;
  background: transparent; color: #0d7b6d; font: inherit; font-size: 12px; cursor: pointer;
}
#lg-ai-pop .lg-ai-bar button:hover, #lg-ai-pop .lg-ai-bar button:focus-visible { background: #eef7f5; outline: none; }
#lg-ai-pop .lg-ai-bar button svg { width: 15px; height: 15px; }
#lg-ai-pop.is-human .lg-ai-bar button { color: #7a8594; }
#lg-ai-pop .lg-ai-bar + .lg-ai-ft { border-top: 0; padding-top: 6px; }

/* 有帮助 / 没帮助 */
#lg-ai-pop .lg-ai-fb { display: flex; gap: 2px; margin: 3px 0 0 4px; }
#lg-ai-pop .lg-ai-fb button {
  width: 26px; height: 26px; padding: 0; border: 0; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; color: #94a0ae; cursor: pointer;
}
#lg-ai-pop .lg-ai-fb button:hover, #lg-ai-pop .lg-ai-fb button:focus-visible { background: #e9eef2; color: #0d7b6d; outline: none; }
#lg-ai-pop .lg-ai-fb button svg { width: 15px; height: 15px; }
#lg-ai-pop .lg-ai-fb button.is-down svg { transform: rotate(180deg); }
#lg-ai-pop .lg-ai-fb.is-done { font-size: 12px; color: #7a8594; }

/* 开场的快捷问题 */
#lg-ai-pop .lg-ai-chips { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
#lg-ai-pop .lg-ai-chips button {
  max-width: 100%; padding: 7px 12px; border: 1px solid #b9ddd6; border-radius: 999px;
  background: #fff; color: #0d7b6d; font: inherit; font-size: 13px; text-align: left; cursor: pointer;
}
#lg-ai-pop .lg-ai-chips button:hover, #lg-ai-pop .lg-ai-chips button:focus-visible { background: #eef7f5; border-color: #0d7b6d; outline: none; }

/* 正在回答 */
#lg-ai-pop .lg-ai-typing { display: flex; align-items: center; gap: 4px; padding: 13px 14px; }
#lg-ai-pop .lg-ai-typing i {
  width: 6px; height: 6px; border-radius: 50%; background: #94a0ae;
  animation: lg-ai-dot 1.1s infinite ease-in-out;
}
#lg-ai-pop .lg-ai-typing i:nth-child(2) { animation-delay: .15s; }
#lg-ai-pop .lg-ai-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes lg-ai-dot { 0%, 60%, 100% { opacity: .35; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }

/* 发送失败 */
#lg-ai-pop .lg-ai-err {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px;
  background: #fdecec; color: #a12626; font-size: 13px;
}
#lg-ai-pop .lg-ai-err span { flex: 1; }
#lg-ai-pop .lg-ai-err button {
  flex: none; padding: 4px 10px; border: 1px solid #e3a9a9; border-radius: 8px;
  background: #fff; color: #a12626; font: inherit; font-size: 13px; cursor: pointer;
}

/* 输入区 */
#lg-ai-pop .lg-ai-ft {
  display: flex; align-items: flex-end; gap: 8px; flex: none; margin: 0;
  padding: 10px 10px 6px 12px; background: #fff; border-top: 1px solid #eef1f4;
}
#lg-ai-pop .lg-ai-ft textarea {
  flex: 1; min-width: 0; height: 40px; min-height: 40px; max-height: 112px; resize: none;
  padding: 9px 12px; border: 1px solid #d5dce3; border-radius: 12px; outline: none;
  background: #fff; color: #1f2a37; font: inherit; line-height: 1.45; box-sizing: border-box;
}
#lg-ai-pop .lg-ai-ft textarea:focus { border-color: #0d7b6d; box-shadow: 0 0 0 3px rgba(13, 123, 109, .14); }
#lg-ai-pop .lg-ai-send {
  width: 40px; height: 40px; padding: 0; border: 0; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: #0d7b6d; color: #fff; cursor: pointer;
}
#lg-ai-pop .lg-ai-send:hover { background: #0a6a5e; }
#lg-ai-pop .lg-ai-send:disabled { background: #c9d3da; cursor: default; }
#lg-ai-pop .lg-ai-send svg { width: 20px; height: 20px; }
#lg-ai-pop .lg-ai-note {
  flex: none; margin: 0; padding: 0 12px 8px; background: #fff;
  font-size: 11px; line-height: 1.4; color: #94a0ae; text-align: center;
}

/* ---------- 图片 ---------- */
/* 输入框左边的选图按钮 */
#lg-ai-pop .lg-ai-att {
  width: 40px; height: 40px; padding: 0; border: 0; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: transparent; color: #7a8594; cursor: pointer;
}
#lg-ai-pop .lg-ai-att:hover, #lg-ai-pop .lg-ai-att:focus-visible { background: #eef7f5; color: #0d7b6d; outline: none; }
#lg-ai-pop .lg-ai-att svg { width: 22px; height: 22px; }
/* 选好还没发的图片：输入框上面的小预览，右上角可以去掉 */
#lg-ai-pop .lg-ai-pend { flex: none; position: relative; align-self: flex-start; margin: 8px 12px 0; }
#lg-ai-pop .lg-ai-pend[hidden] { display: none; }
#lg-ai-pop .lg-ai-pend img { display: block; max-width: 120px; max-height: 90px; border-radius: 8px; border: 1px solid #d5dce3; }
#lg-ai-pop .lg-ai-pend button {
  position: absolute; top: -8px; right: -8px; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; background: #1f2a37; color: #fff; cursor: pointer;
}
#lg-ai-pop .lg-ai-pend button svg { width: 12px; height: 12px; stroke-width: 2.4; }
#lg-ai-pop .lg-ai-pend + .lg-ai-ft { border-top: 0; }
/* 消息里的图片：缩略显示，点开看原图 */
#lg-ai-pop .lg-ai-img { display: block; padding: 0; border: 0; background: none; cursor: zoom-in; }
#lg-ai-pop .lg-ai-img img { display: block; max-width: 100%; max-height: 220px; border-radius: 8px; background: #eef1f4; }
#lg-ai-pop .lg-ai-img + p { margin-top: 6px; }

/* ---------- 窄屏：占满屏幕下方的面板 ---------- */
#lg-ai-pop.is-sheet {
  left: 0; right: 0; bottom: 0; top: auto; width: auto; max-width: none;
  height: 88vh; height: 88dvh; max-height: none;
  border-radius: 16px 16px 0 0; border-width: 1px 0 0;
  box-shadow: 0 -12px 40px rgba(15, 35, 52, .22);
  transform: translateY(24px); transform-origin: center bottom;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
#lg-ai-pop.is-sheet.is-open { transform: none; }
/* 手机上输入框字号不小于 16px，否则 iOS 聚焦时会放大页面 */
#lg-ai-pop.is-sheet .lg-ai-ft textarea { font-size: 16px; }

@media (prefers-reduced-motion: reduce) {
  #lg-ai-pop, #lg-ai-pop.is-open, #lg-ai-fab { transition: none; }
  #lg-ai-pop .lg-ai-typing i { animation: none; }
}
