/*!
 * AI 智能助手 —— 前台 / 后台共用的样式
 *
 * 以前台/后台任意一方引入都能正常工作：
 * 依赖的 CSS 变量在下面做了兜底定义，
 * 避免在没定义这些变量的页面（如前台）出现样式错乱。
 *
 * 【设计基调】
 *   1. 统一「一套绿」：项目主色是 #00c250（品牌绿），
 *      之前这里用青绿 #0f766e、面板头用 #00c250，两套绿打架。
 *      现在统一到品牌绿族：#00c250（主色）/ #067a38（可读的文字绿）。
 *   2. 消息层级靠「底色 + 竖条」区分，而不是靠一堆类型标签：
 *        AI 回复 -> 白底 + 绿色竖条
 *        私聊    -> 白底 + 琥珀竖条
 *        系统/错误 -> 红底
 *        自己    -> 浅绿实底
 *   3. 字号回到可读区间（13.5px），不再用 12px + 300 字重 + 浅灰。
 *
 * 【作用域】
 *   聊天相关的变量定义在 .chat-scope / .chat-discussion 上，
 *   避免覆盖宿主页面的 :root（后台管理页自己定义了一套 --wp-* 变量）。
 */

/* ============ 聊天作用域变量（前台面板 / 后台 AI 智能助手都加 .chat-scope） ============ */
/* 作用域说明：
   - 变量挂在 .ai-panel（前台）/ .wp-room（后台）/ .chat-body / .chat-discussion 上，
     这些是**聊天专用**的容器，不会污染宿主页面的 :root；
   - 变量名用 --chat-* 前缀，与后台模板里自己的 --wp-* 完全隔离，
     避免两套主题互相覆盖（后台房间头是青绿、前台面板是品牌绿）。 */
.ai-panel,
.wp-room,
.chat-body,
.chat-discussion {
  --chat-primary: #00c250;
  --chat-primary-dark: #067a38;
  --chat-primary-soft: #22d366;

  --chat-text: #1f2937;
  --chat-text-body: #374151;      /* 正文（对比度 >= 7:1） */
  --chat-text-soft: #6b7280;      /* 次要说明 */
  --chat-text-mute: #9aa3b2;      /* 时间戳等弱化信息 */

  --chat-border: #e6ecea;
  --chat-border-soft: #eef2f1;

  --chat-bg: #f4f7f6;

  --chat-radius: 14px;
  --chat-radius-sm: 10px;

  --chat-shadow-1: 0 1px 2px rgba(16, 24, 40, .04), 0 6px 18px rgba(16, 24, 40, .05);
  --chat-shadow-2: 0 4px 12px rgba(16, 24, 40, .08), 0 18px 44px rgba(16, 24, 40, .10);

  /* 统一字体栈（与站内其它页面的 body 字体保持一致） */
  --chat-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --chat-font-mono: "SF Mono", Consolas, Monaco, "Courier New", "Microsoft YaHei", monospace;

  --chat-ai-bar: linear-gradient(180deg, #22d366 0%, #00c250 60%, #00a843 100%);
  --chat-private-bar: linear-gradient(180deg, #fbbf24 0%, #f59e0b 100%);
}

/* ============ 消息列表 ============ */
.chat-discussion {
  background: var(--chat-bg);
  padding: 10px 10px 12px;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  flex: 1;
  min-height: 0;
  font-family: var(--chat-font);
  -webkit-overflow-scrolling: touch;
}
.chat-discussion::-webkit-scrollbar { width: 8px; }
.chat-discussion::-webkit-scrollbar-thumb {
  background: #cfded9;
  border-radius: 8px;
}
.chat-discussion::-webkit-scrollbar-thumb:hover { background: #b3c8c1; }

/* 消息区外层容器：用于挂「回到最新」悬浮按钮 */
.chat-body {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.chat-body > .chat-discussion {
  flex: 1 1 auto;
  min-height: 0;
}

/* ============ 日期分隔条 ============ */
.chat-day-sep {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 5px 0 10px;
  font-size: 10px;
  color: var(--chat-text-mute);
  user-select: none;
}
.chat-day-sep::before,
.chat-day-sep::after {
  content: "";
  height: 1px;
  flex: 1;
  max-width: 60px;
  background: var(--chat-border);
}
.chat-day-sep span {
  padding: 0 10px;
  letter-spacing: .3px;
}

/* ============ 气泡布局（无头像） ============ */
.chat-message {
  display: flex;
  margin-bottom: 8px;
  animation: wpFadeIn .22s ease;
}
@keyframes wpFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* 左：他人 / AI / 系统　右：自己 */
.chat-message.left  { justify-content: flex-start; }
.chat-message.right { justify-content: flex-end; }

/* 气泡本体 */
.chat-message .message {
  position: relative;
  max-width: 92%;
  min-width: 0;
  background: #fff;
  border: 1px solid var(--chat-border);
  border-radius: 4px 14px 14px 14px;
  padding: 7px 10px;
  box-shadow: var(--chat-shadow-1);
  word-break: break-word;
}

/* 自己的气泡：靠右，浅绿实底 */
.chat-message.right .message {
  max-width: 84%;
  background: #e4f7ec;
  border-color: #bfe8d0;
  border-radius: 14px 4px 14px 14px;
}

/* 气泡上方的「用户名 + 时间 + 类型标签」一行 */
.chat-message .message .message-author {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--chat-text);
  margin-right: 8px;
}
.message-date {
  font-size: 10px;
  color: var(--chat-text-mute);
  font-variant-numeric: tabular-nums;
}

/* 「不收费」角标（历史遗留样式，咨询模式已改为按 token 计费） */
.ai-free-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: 8px;
  font-size: 9px;
  line-height: 15px;
  color: var(--chat-primary-dark);
  background: #dcfce7;
  border: 1px solid #a7f3c4;
  vertical-align: middle;
}

/* 气泡正文 */
.message-content {
  display: block;
  margin-top: 3px;
  font-family: var(--chat-font);
  font-size: 12px;
  line-height: 1.62;
  color: var(--chat-text-body);
  overflow-x: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chat-message.right .message-content { color: #14532d; }

/* ============ 消息类型分层：底色 + 竖条 ============ */
/*
 * AI 回复：白底 + 左侧主色竖条 —— 比整块绿底更清爽、也更「产品化」，
 * 同时让 AI 的长文本阅读负担下降。
 */
.chat-message.left.ai-reply .message,
.chat-message.left.ai-round .message {
  background: #fff;
  border-color: var(--chat-border);
  padding-left: 12px;
}
.chat-message.left.ai-reply .message::before,
.chat-message.left.ai-round .message::before {
  content: "";
  position: absolute;
  left: 0;
  top: -1px;
  bottom: -1px;
  width: 3px;
  border-radius: 3px 0 0 3px;
  background: var(--chat-ai-bar);
}

/* 私聊（收到的）：白底 + 琥珀竖条，与 AI 区分 */
.chat-message.left[data-msg-type="private"] .message {
  background: #fff;
  border-color: var(--chat-border);
  padding-left: 12px;
}
.chat-message.left[data-msg-type="private"] .message::before {
  content: "";
  position: absolute;
  left: 0;
  top: -1px;
  bottom: -1px;
  width: 3px;
  border-radius: 3px 0 0 3px;
  background: var(--chat-private-bar);
}

/* 作者名配色：AI 绿、私聊琥珀，与竖条呼应 */
.chat-message.left.ai-reply .message .message-author,
.chat-message.left.ai-round .message .message-author {
  color: var(--chat-primary-dark);
}
.chat-message.left[data-msg-type="private"] .message .message-author {
  color: #b45309;
}

/* 错误日志消息（仅 root 可见） */
.chat-message.system .message {
  background: #fff7f5;
  border-color: #ffd9cf;
  box-shadow: 0 2px 8px rgba(239, 68, 68, .08);
}
.chat-message.system .message .message-author { color: #b91c1c; }
.msg-type-tag[data-type="error"] { background: #fee2e2; color: #b91c1c; }
.msg-type-tag[data-type="success"] { background: #dcfce7; color: #15803d; }
.message-content.error-log {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--chat-font-mono);
  font-size: 10.5px;
  line-height: 1.55;
  color: #7f1d1d;
  max-height: 220px;
  overflow: auto;
  margin-top: 6px;
}
.message-content.error-log pre {
  margin: 0;
  font-family: inherit;
  font-size: inherit;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ============ 类型标签 ============ */
.msg-type-tag {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 9.5px;
  font-weight: 700;
  margin-right: 2px;
  vertical-align: 1px;
  letter-spacing: .2px;
}
.msg-type-tag[data-type="public"]  { background: #eef1f6; color: #64748b; }
.msg-type-tag[data-type="private"] { background: #fff3e0; color: #e65100; }
.msg-type-tag[data-type="ai"]      { background: #dcfce7; color: var(--chat-primary-dark); }
.msg-type-tag[data-type="vip"]     { background: #fdeecd; color: #b45309; }

/* ============ 进度提示（AI 执行进度）：瞬时状态，只保留一个节点并原地更新 ============ */
.progress-hint {
  color: var(--chat-text-soft) !important;
  font-style: italic;
  font-size: 0.92em;
}
.progress-msg .message {
  background: #fff;
  border: 1px dashed #d8e2df;
  border-radius: 12px;
  padding: 6px 9px;
  animation: wpFadeIn .2s ease;
}
.progress-msg .message-author,
.progress-msg .message-date {
  opacity: .75;
}

/* ============ AI 回复折叠（展开全部 / 收起） ============ */
.ai-expand-btn {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 10px;
  border: 1px solid var(--chat-primary-soft);
  border-radius: 999px;
  background: #f0fdf4;
  color: var(--chat-primary-dark);
  font-size: 10.5px;
  line-height: 1.7;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  -webkit-tap-highlight-color: transparent;
}
.ai-expand-btn:hover {
  background: var(--chat-primary);
  border-color: var(--chat-primary);
  color: #fff;
}

/* 完整内容藏在隐藏元素里（展开时把它显示到 .message-content） */
.chat-message .ai-full-text[hidden] { display: none; }

/* ============ AI 轮次盒子 ============ */
/* 一次提问触发的**所有** AI 回复合并到一个盒子里：
   折叠时只显示最后一条（通常是结论），展开才看到整个排查过程。 */
.ai-round-count {
  font-size: 10.5px;
  color: var(--chat-text-mute);
  margin-left: 6px;
}
.ai-round-body {
  margin-top: 4px;
}
/* 每条回复是盒子里的一个独立块 */
.ai-round-part {
  padding: 2px 0;
}
.ai-round-part + .ai-round-part {
  border-top: 1px dashed var(--chat-border);
  margin-top: 6px;
  padding-top: 6px;
}
/* 每块左上角的小时间戳（只在展开时显示，避免折叠状态太挤） */
.ai-round-part-time {
  font-size: 10px;
  color: var(--chat-text-mute);
  margin-bottom: 2px;
  font-variant-numeric: tabular-nums;
}
.ai-round-part-text {
  word-break: break-word;
  font-family: var(--chat-font);
  font-size: 12px;
  line-height: 1.62;
  color: var(--chat-text-body);
}
/* 折叠状态下，除最后一条外的都隐藏 */
.ai-round-part-hidden {
  display: none;
}
/* 折叠状态只留最后一条时，不需要分隔线 */
.ai-round[data-collapsed="1"] .ai-round-part + .ai-round-part {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}

/* ============ Markdown 渲染 ============ */
/*
 * AI 回答里大量是命令与代码，统一做轻量 Markdown 渲染：
 *   - 围栏代码块 -> 深色 <pre>，等宽字体，可横向滚动
 *   - 行内 code  -> 浅灰底小字
 *   - 列表 / 标题 / 引用 / 粗体 / 链接
 *
 * ⚠️ 安全：所有内容先做 HTML 转义，再做规则替换，
 *    绝不允许原始 HTML 进入 DOM。
 */
/*
 * .ai-md 容器：**不能**继承 .message-content 的 white-space: pre-wrap。
 *
 * 原因：pre-wrap 会把源码里的换行/缩进原样保留，
 * 而 Markdown 渲染已经用 <div>/<br> 表达结构了，
 * 两者叠加会出现大片空白、行间多出空隙。
 * 所以 .ai-md 改成 normal，靠渲染出来的标签控制结构。
 */
.ai-md {
  white-space: normal;
}
.ai-md-pre {
  margin: 8px 0 4px;
  padding: 10px 12px;
  /* 浅色底：AI 的回复里大量是命令 / 代码，
     深色底（原来是 #0f172a）在浅色聊天界面里非常突兀、也看不清。
     改成浅灰底 + 深色文字，等宽字体不变。 */
  background: #eef1f6;
  color: #1f2937;
  border: 1px solid #dde3ea;
  border-radius: var(--chat-radius-sm);
  font-family: var(--chat-font-mono);
  font-size: 11px;
  line-height: 1.55;
  overflow-x: auto;
  white-space: pre;
  word-break: normal;
  -webkit-overflow-scrolling: touch;
}
.ai-md-pre code {
  font-family: inherit;
  font-size: inherit;
  background: none;
  padding: 0;
  color: inherit;
}
.ai-md-code {
  font-family: var(--chat-font-mono);
  font-size: .88em;
  padding: 0 4px;
  margin: 0 1px;
  border-radius: 4px;
  background: #eef2f1;
  color: #0f172a;
  overflow-wrap: anywhere;
}
.chat-message.right .ai-md-code {
  background: rgba(0, 0, 0, .06);
}
.ai-md-list {
  margin: 4px 0;
  padding-left: 17px;
}
.ai-md-list li { margin: 2px 0; }
.ai-md-h {
  margin: 8px 0 3px;
  font-weight: 700;
  color: var(--chat-text);
}
/* Markdown 标题层级（h1~h4）：
   层级差异用 class 表达，不写行内 style，
   这样前台小面板缩放时能直接用 CSS 覆盖。 */
.ai-md-h1 { font-size: 13px; }
.ai-md-h2 { font-size: 12.5px; }
.ai-md-h3 { font-size: 12px; }
.ai-md-h4 { font-size: 11.5px; }
.ai-md-quote {
  margin: 4px 0;
  padding: 1px 0 1px 8px;
  border-left: 3px solid var(--chat-border);
  color: var(--chat-text-soft);
}
.ai-md-hr {
  margin: 7px 0;
  border: none;
  border-top: 1px solid var(--chat-border);
}
.ai-md-link {
  color: var(--chat-primary-dark);
  text-decoration: underline;
  word-break: break-all;
}

/* ============ 输入区 ============ */
.chat-input-wrap {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  border-top: 1px solid var(--chat-border);
  background: #fbfdfc;
  padding: 8px 10px 9px;
  flex-shrink: 0;
  font-family: var(--chat-font);
}
.chat-input-box {
  position: relative;
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--chat-border);
  border-radius: 10px;
  padding: 0 10px;
  transition: border-color .18s, box-shadow .18s;
}
.chat-input-box:focus-within {
  border-color: var(--chat-primary);
  box-shadow: 0 0 0 3px rgba(0, 194, 80, .12);
}
.chat-input-wrap.locked .chat-input-box {
  background: #f1f5f4;
  border-color: #dde5e2;
}
.chat-input-box textarea {
  width: 100%;
  flex: 0 0 auto;
  border: none;
  outline: none;
  resize: none;
  min-height: 22px;
  /* 底部留白：给右下角的发送按钮预留位置 */
  padding: 9px 0 26px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--chat-text);
  font-family: inherit;
  max-height: 180px;
  background: transparent;
}
.chat-input-box textarea::placeholder { color: var(--chat-text-mute); }

/* 字数统计（输入框内部左下角） */
.chat-input-count {
  position: absolute;
  left: 10px;
  bottom: 7px;
  font-size: 10px;
  color: var(--chat-text-mute);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.chat-input-count.warn { color: #f59e0b; }
.chat-input-count.over { color: #ef4444; }

/* 发送按钮：输入框内部右下角的圆形向上箭头 */
.chat-send-btn {
  position: absolute;
  right: 7px;
  bottom: 7px;
  width: 24px;
  height: 24px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #111827;
  border: none;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  transition: background .18s, transform .12s, opacity .18s;
  -webkit-tap-highlight-color: transparent;
}
.chat-send-btn svg {
  width: 13px;
  height: 13px;
  display: block;
  pointer-events: none;
}
.chat-send-btn:hover { background: #000; }
.chat-send-btn:active { transform: scale(.92); }
.chat-send-btn.empty,
.chat-send-btn.idle {
  background: #cbd5e1;
  color: #fff;
  cursor: not-allowed;
}
.chat-send-btn.locked,
.chat-send-btn:disabled {
  background: #cbd5e1 !important;
  color: #fff;
  cursor: not-allowed;
}

/* ============ 输入提示条 ============ */
.chat-input-tip {
  padding: 4px 12px 8px;
  font-size: 10.5px;
  color: var(--chat-text-mute);
  background: #fbfdfc;
  border-top: 1px dashed var(--chat-border-soft);
  flex-shrink: 0;
  font-family: var(--chat-font);
}
.chat-input-tip kbd {
  display: inline-block;
  padding: 1px 4px;
  margin: 0 1px;
  font-size: 10px;
  font-family: var(--chat-font-mono);
  background: #fff;
  border: 1px solid var(--chat-border);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--chat-text-soft);
}

/* ============ 「回到最新」悬浮提示 ============ */
/* 用户上滑看历史时，底部提示还有多少条新消息 */
.chat-new-btn {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 4px;
  padding: 4px 11px;
  border: 1px solid var(--chat-border);
  border-radius: 999px;
  background: #fff;
  color: var(--chat-primary-dark);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  box-shadow: var(--chat-shadow-2);
  cursor: pointer;
  z-index: 5;
  -webkit-tap-highlight-color: transparent;
}
.chat-new-btn.show { display: inline-flex; }
.chat-new-btn:hover { background: #f0fdf4; }

/* ============ 点击消息：切换成私聊（/to 用户名） ============ */
.chat-message[data-replyable="1"] { cursor: pointer; }
.chat-message[data-replyable="1"]:hover .message {
  border-color: var(--chat-primary-soft);
  box-shadow: var(--chat-shadow-2);
}
.chat-message[data-replyable="1"] .message-hint {
  display: block;
  font-size: 11px;
  color: var(--chat-text-mute);
  margin-top: 4px;
}
.chat-message[data-replyable="1"]:hover .message-hint { color: var(--chat-primary-dark); }

/* 输入框顶部提示当前正在私聊谁 */
.chat-reply-tip {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  font-size: 11px;
  color: #b45309;
  background: #fff7ed;
  border-bottom: 1px solid #fed7aa;
  flex-shrink: 0;
  font-family: var(--chat-font);
}
.chat-reply-tip.show { display: flex; }
.chat-reply-tip .chat-reply-name { font-weight: 600; }
.chat-reply-tip .chat-reply-cancel {
  margin-left: auto;
  cursor: pointer;
  color: #b45309;
  text-decoration: underline;
  background: none;
  border: none;
  padding: 2px 4px;
  font-size: 11px;
}

/* ================================================================
 * ============ 前台「AI 智能助手」悬浮球 + 面板 ============
 * ================================================================
 * 从模板内联样式移到这里统一维护（前台面板与后台 AI 智能助手共用一份设计语言）。
 */
.ai-fab {
  position: fixed;
  right: 24px;
  bottom: 96px;
  z-index: 950;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px 10px 12px;
  background: linear-gradient(135deg, #22d366 0%, #00a843 100%);
  color: #fff;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--chat-font, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif);
  box-shadow: 0 8px 24px rgba(0, 168, 67, .35);
  transition: transform .2s, box-shadow .2s;
}
.ai-fab:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(0, 168, 67, .45); }
.ai-fab-text { font-size: 14px; font-weight: 600; white-space: nowrap; }
.ai-fab.hidden { display: none; }
/* 未打开面板时收到新消息的红点提示 */
.ai-fab-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  box-shadow: 0 0 0 2px #fff;
}

.ai-panel {
  position: fixed;
  right: 24px;
  bottom: 72px;
  width: 460px;
  max-width: calc(100vw - 24px);
  height: 640px;
  max-height: calc(100vh - 130px);
  background: #fff;
  border: 1px solid rgba(0, 0, 0, .08);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .2);
  z-index: 960;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--chat-font, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif);
}
.ai-panel.show { display: flex; }
.ai-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  background: linear-gradient(135deg, #22d366 0%, #00a843 100%);
  color: #fff;
  flex-shrink: 0;
}
.ai-panel-title { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
.ai-panel-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  transition: background .2s, opacity .2s;
}
/* 连接状态：在线 / 重连中 / 离线 */
.ai-panel-dot.is-online { background: #fff; animation: aiPulse 1.8s ease-in-out infinite; }
.ai-panel-dot.is-connecting { background: #fde68a; animation: aiPulse .9s ease-in-out infinite; }
.ai-panel-dot.is-offline { background: #e2e8f0; animation: none; opacity: .85; }
@keyframes aiPulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }
.ai-panel-status {
  font-size: 11.5px;
  opacity: .9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* 关闭按钮：与最大化按钮同一套盒模型（26×26 方形 + 15px SVG 图标），
   避免字符 ✕ 与 SVG 图标基线/尺寸不一致导致两个按钮看起来不配套。 */
.ai-panel-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .18s;
  -webkit-tap-highlight-color: transparent;
}
.ai-panel-close:hover { background: rgba(255, 255, 255, .18); }
.ai-panel-close svg {
  width: 15px;
  height: 15px;
  display: block;
  pointer-events: none;
}

/* ============ 最大化按钮（位于关闭按钮 ✕ 之前） ============ */
/*
 * 两个按钮放在一个 .ai-panel-head-btns 里（而不是各自作为
 * .ai-panel-head 的直接 flex 子项）。
 *
 * 原因：.ai-panel-head 是 justify-content: space-between，
 * 如果最大化/关闭各自是独立子项，它们会被 space-between
 * 拉到头的两端、中间还夹着状态文字，看起来离得很远。
 * 套一层容器后两个按钮紧挨在一起（像浏览器右上角）。
 */
.ai-panel-head-btns {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.ai-panel-max {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .18s;
  -webkit-tap-highlight-color: transparent;
}
.ai-panel-max:hover { background: rgba(255, 255, 255, .18); }
.ai-panel-max svg {
  width: 15px;
  height: 15px;
  display: block;
  pointer-events: none;
}
/* 两个图标叠在一起，用 .is-max 切换显示哪一个 */
.ai-panel-max .icon-restore { display: none; }
.ai-panel-max.is-max .icon-expand { display: none; }
.ai-panel-max.is-max .icon-restore { display: block; }

/* ============ 最大化状态：面板铺满窗口 ============ */
/*
 * 只改尺寸/位置，样式本身仍由 .ai-panel 的规则控制，
 * 所以最大化前后配色、圆角、边框完全一致。
 */
.ai-panel.maximized {
  top: 12px;
  right: 12px;
  bottom: 12px;
  left: 12px;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  border-radius: 12px;
}
/* 移动端最大化时留一点边距，避免完全贴边 */
@media (max-width: 480px) {
  .ai-panel.maximized {
    top: 6px;
    right: 6px;
    bottom: 6px;
    left: 6px;
    border-radius: 10px;
  }
}

/* 前台面板里的消息区沿用共享样式，这里只做尺寸微调 */
/* 说明：前台面板与后台房间共用同一套聊天样式（.chat-discussion /
   .chat-input-wrap / .chat-input-tip 的尺寸在共享样式里定义），
   这里不再写任何覆盖规则，避免两边出现不一致。 */

/* ============ 后台「AI 智能助手」房间头 ============ */
/*
 * 注意：房间头（.wp-room-*）的样式**留在后台模板里**
 *（admin/workPlatform.html 的内联 <style>），不在这里定义。
 *
 * 原因：chat_room.css 是在后台模板内联 <style> **之后**引入的，
 * 同特异性的规则会覆盖模板里的定义。
 * 后台房间头用的是青绿渐变（与后台整体配色一致），
 * 放到这里会把它覆盖成前台的品牌绿，两边就不一致了。
 * 这里只放一个连接状态点（小圆点），它没有主题色偏好。
 */
.wp-room-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #cbd5e1;
  transition: background .2s;
  flex-shrink: 0;
}
.wp-room-dot.is-online { background: #00c250; }
.wp-room-dot.is-connecting { background: #f59e0b; }
.wp-room-dot.is-offline { background: #cbd5e1; }

/* ============ 响应式 / 移动端 ============ */
@media (max-width: 480px) {
  /* 移动端：上移悬浮按钮，避免遮挡分页的「下一页」按钮。
     层级（自底向上）：吸底页脚约 31px → 分页行按钮 32px + 下内边距 24px
     → 分页按钮顶部约在距底 87px 处。原来的 bottom:64px 会正好压住
     「下一页」，这里提到 108px，让分页行完整露出来。 */
  .ai-fab { right: 14px; bottom: 108px; padding: 9px 12px; }
  .ai-fab-text { display: none; }

  /* 面板高度用 svh（小视口高度）而不是 vh。
     vh 参照的是「浏览器地址栏收起时」的大视口，而 fixed 元素的
     bottom 参照的是当前可见视口，两者不一致：
     真机（iPhone 12: 大视口 844 / 地址栏展开后可见 690）时，
     74vh = 624px 会被算成 690 - 56 - 624 ≈ 10px，
     面板几乎贴着屏幕顶端。Edge 设备仿真里 vh 恰好等于可见视口，
     所以看不出这个偏差。
     svh 固定取「地址栏展开时」的小视口，与 bottom 同一基准，
     面板尺寸也不会随地址栏收放而抖动。
     比 dvh 同样能修正基准，但高度会随地址栏收放实时变化而抖动。 */
  .ai-panel {
    right: 10px;
    left: 10px;
    width: auto;
    bottom: 56px;
    height: 74vh;          /* 旧浏览器回退 */
    height: 74svh;         /* 支持 svh 的浏览器（现代手机浏览器）优先 */
    max-height: calc(100vh - 80px);
    max-height: calc(100svh - 80px);
  }

  /* 输入区避让 iPhone 底部 Home Indicator */
  .ai-panel .chat-input-tip {
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  /* 触控目标放大：移动端建议可点元素不小于 40px */
  .chat-send-btn { width: 32px; height: 32px; }
  .chat-send-btn svg { width: 17px; height: 17px; }
  .ai-expand-btn { padding: 6px 14px; }

  /* 移动端正文再放宽半档：屏幕窄，字太小反而看不清 */
  .message-content,
  .ai-round-part-text { font-size: 12.5px; line-height: 1.65; }
  .chat-input-box textarea { font-size: 13px; }
}
/* 小屏手机再放大一些 */
@media (max-width: 380px) {
  .ai-panel { height: 78vh; height: 78svh; }
}

/* ============ iPhone Home Indicator 安全区（所有移动端） ============ */
/*
 * 输入框贴着屏幕底部会被 Home Indicator 挡住，
 * 预留出安全区高度。
 */
@supports (padding: env(safe-area-inset-bottom)) {
  .ai-panel .chat-input-tip {
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
}

/* ============ 尊重系统的「减少动态效果」设置 ============ */
@media (prefers-reduced-motion: reduce) {
  .chat-message { animation: none; }
  .ai-panel-dot,
  .ai-panel-dot.is-online,
  .ai-panel-dot.is-connecting { animation: none; }
  .chat-discussion { scroll-behavior: auto; }
}
