/* =============================================================================
 * 在线交流（实时聊天）· v20261122d
 * 顶栏入口按钮复用画笔标注原气泡图标，样式与其一致（主题变量驱动，不写死色值）。
 * 面板为浮动小窗，跟随主题。类名统一 ht-chat- 前缀。
 * 2026-11-22b：新增头像 / 姓名 / 身份标签 / 在线状态 / 未登录只读提示；移除门户头像小条。
 * 2026-11-22c：入口气泡改为「心跳」动态图——双拍心跳缩放 + 两圈错峰扩散光环 +
 *              三个聊天气泡点依次闪烁；颜色全部走主题变量，支持 prefers-reduced-motion。
 * ========================================================================== */

/* ---------- 顶栏入口容器（单一气泡按钮） ---------- */
.ht-chat-entry {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

/* ---------- 顶栏入口按钮（位于「切换主题配色」左侧） ---------- */
.ht-chat-launcher {
  --mk-bg: var(--text-primary);
  --mk-fg: var(--surface);
  position: relative;                 /* 扩散光环伪元素定位基准 */
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--mk-bg);
  color: var(--mk-fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  cursor: pointer;
  transition: background .18s ease, box-shadow .18s ease, transform .18s ease;
  -webkit-tap-highlight-color: transparent;
  animation: ht-chat-heartbeat 1.6s ease-in-out infinite;   /* 双拍心跳 */
}
.ht-chat-launcher:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .2);
}
.ht-chat-launcher:active { transform: none; }
.ht-chat-launcher:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.ht-chat-launcher.is-on {
  --mk-bg: var(--primary);
  --mk-fg: var(--on-primary);
}
.ht-chat-launcher svg { width: 18px; height: 18px; display: block; }
.ht-chat-launcher svg .ht-chat-dot { fill: var(--mk-bg); opacity: .5; }

/* 两圈错峰向外扩散的主题色光环，形成心跳波纹的视觉冲击 */
.ht-chat-launcher::before,
.ht-chat-launcher::after {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  opacity: 0;
  pointer-events: none;
  animation: ht-chat-ring 1.6s ease-out infinite;
}
.ht-chat-launcher::after { animation-delay: .8s; }
.ht-chat-launcher.is-on::before,
.ht-chat-launcher.is-on::after { border-color: var(--on-primary); }

/* 气泡内三个点依次闪烁，强化「活跃交流」观感 */
.ht-chat-launcher .ht-chat-dot:nth-of-type(1) { animation: ht-chat-dot-pulse 1.6s ease-in-out infinite; }
.ht-chat-launcher .ht-chat-dot:nth-of-type(2) { animation: ht-chat-dot-pulse 1.6s ease-in-out infinite .18s; }
.ht-chat-launcher .ht-chat-dot:nth-of-type(3) { animation: ht-chat-dot-pulse 1.6s ease-in-out infinite .36s; }

/* 心跳关键帧：lub-dub 双拍，停顿时保持原状，避免持续放大 */
@keyframes ht-chat-heartbeat {
  0%   { transform: scale(1); }
  8%   { transform: scale(1.16); }
  16%  { transform: scale(1); }
  26%  { transform: scale(1.1); }
  40%, 100% { transform: scale(1); }
}
/* 光环扩散关键帧 */
@keyframes ht-chat-ring {
  0%        { transform: scale(1);   opacity: .72; }
  70%, 100% { transform: scale(2.15); opacity: 0; }
}
/* 圆点闪烁关键帧 */
@keyframes ht-chat-dot-pulse {
  0%, 100% { opacity: .35; }
  20%      { opacity: 1; }
}

/* ---------- 共用头像 ---------- */
.ht-chat-ava {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--on-primary);
  border: 1px solid var(--surface);
  overflow: hidden;
  font-style: normal;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}
.ht-chat-ava-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ht-chat-ava-online { width: 20px; height: 20px; font-size: 10px; }
.ht-chat-ava-msg { width: 32px; height: 32px; font-size: 13px; align-self: flex-start; }

/* ---------- 聊天面板（浮动小窗） ---------- */
.ht-chat-panel {
  position: fixed;
  top: 56px;
  right: 14px;
  z-index: 12000;
  width: 340px;
  max-width: calc(100vw - 24px);
  height: min(560px, calc(100vh - 76px));
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, .22);
  overflow: hidden;
}
[data-theme="dark"] .ht-chat-panel { box-shadow: 0 16px 48px rgba(0, 0, 0, .6); }
.ht-chat-panel[hidden] { display: none !important; }

.ht-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.ht-chat-title {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.ht-chat-count { font-size: 12px; font-weight: 400; color: var(--text-tertiary); }
.ht-chat-x {
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ht-chat-x:hover { background: var(--surface-2); color: var(--text-primary); }
.ht-chat-x:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.ht-chat-x svg { width: 16px; height: 16px; }

/* ---------- 连接状态提示 ---------- */
.ht-chat-conn {
  display: none;
  padding: 6px 12px;
  font-size: 12px;
  line-height: 1.4;
  border-bottom: 1px solid var(--border);
}
.ht-chat-conn.is-visible { display: block; }
.ht-chat-conn.is-warn { background: var(--warning-50, #fffbe6); color: var(--warning, #ad6800); }
.ht-chat-conn.is-err { background: var(--danger-50); color: var(--danger); }
[data-theme="dark"] .ht-chat-conn.is-warn { background: rgba(255, 170, 0, .14); color: #ffc069; }

.ht-chat-online {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
  max-height: 76px;
  overflow-y: auto;
}
.ht-chat-online-label { color: var(--text-tertiary); }
.ht-chat-online-empty { color: var(--text-tertiary); font-size: 11px; }
.ht-chat-online-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--primary-50);
  color: var(--primary);
  border-radius: 999px;
  padding: 1px 7px 1px 1px;
  font-size: 11px;
  white-space: nowrap;
}
.ht-chat-online-name { margin-left: 1px; }
.ht-chat-online-role {
  font-size: 10px;
  line-height: 15px;
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .06);
  color: inherit;
  opacity: .9;
}
.ht-chat-online-role.ht-chat-role-admin,
.ht-chat-online-role.ht-chat-role-headteacher,
.ht-chat-online-role.ht-chat-role-grademaster { background: var(--danger); color: #fff; opacity: 1; }
.ht-chat-online-role.ht-chat-role-teacher { background: var(--primary); color: var(--on-primary); opacity: 1; }
.ht-chat-online-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #52c41a;
  box-shadow: 0 0 0 2px rgba(82, 196, 26, .16);
  flex: 0 0 auto;
}
[data-theme="dark"] .ht-chat-online-chip { background: var(--sidebar-active-bg); color: var(--text-primary); }
.ht-chat-online-chip.ht-chat-role-admin,
.ht-chat-online-chip.ht-chat-role-headteacher,
.ht-chat-online-chip.ht-chat-role-grademaster { background: var(--danger-50); color: var(--danger); }

.ht-chat-msgs {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface);
}
.ht-chat-row { display: flex; flex-direction: row; align-items: flex-start; gap: 8px; max-width: 100%; }
.ht-chat-row.is-mine { flex-direction: row-reverse; }
.ht-chat-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; max-width: calc(100% - 44px); }
.ht-chat-who {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-tertiary);
}
.ht-chat-name { font-weight: 600; color: var(--text-secondary); }
.ht-chat-role {
  border-radius: 999px;
  padding: 0 6px;
  font-size: 10px;
  line-height: 16px;
  background: var(--surface-2);
  color: var(--text-secondary);
}
.ht-chat-role-admin,
.ht-chat-role-headteacher,
.ht-chat-role-grademaster { background: var(--danger-50); color: var(--danger); }
.ht-chat-role-teacher { background: var(--primary-50); color: var(--primary); }
.ht-chat-role-guest { background: var(--surface-2); color: var(--text-tertiary); }
.ht-chat-text {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 6px 10px;
  word-break: break-word;
  white-space: pre-wrap;
}
.ht-chat-row.is-mine .ht-chat-who { flex-direction: row-reverse; }
.ht-chat-row.is-mine { align-items: flex-start; }
.ht-chat-row.is-mine .ht-chat-text { background: var(--primary-50); color: var(--primary); }
.ht-chat-msgs-empty {
  margin: auto;
  padding: 16px 10px;
  text-align: center;
  font-size: 12px;
  color: var(--text-tertiary);
}
.ht-chat-input:disabled { opacity: .6; cursor: not-allowed; }
[data-theme="dark"] .ht-chat-row.is-mine .ht-chat-text { background: var(--sidebar-active-bg); color: var(--text-primary); }

.ht-chat-foot {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.ht-chat-input {
  flex: 1 1 auto;
  resize: none;
  max-height: 120px;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text-primary);
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  outline: none;
  line-height: 1.4;
}
.ht-chat-input:focus { border-color: var(--primary); }
.ht-chat-input::placeholder { color: var(--text-tertiary); }
.ht-chat-send {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: var(--primary);
  color: var(--on-primary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ht-chat-send:hover { background: var(--primary-light); }
.ht-chat-send:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.ht-chat-send svg { width: 18px; height: 18px; }

/* 未登录访客只读提示条（替代发言区） */
.ht-chat-readonly {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-tertiary);
  font-size: 12px;
  text-align: center;
}
.ht-chat-readonly[hidden] { display: none; }

/* ---------- 移动端（手机 / 平板竖屏）：面板改为底部抽屉 ---------- */
@media (max-width: 768px) {
  .ht-chat-launcher { width: 30px; height: 30px; }
  .ht-chat-launcher svg { width: 16px; height: 16px; }
  .ht-chat-panel {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: none;
    height: 70vh;
    border-radius: 14px 14px 0 0;
  }
}

/* ---------- 打印：聊天一律不出现 ---------- */
@media print {
  .ht-chat-launcher,
  .ht-chat-entry,
  .ht-chat-panel { display: none !important; }
}

/* ---------- 动效偏好：尊重系统「减少动态效果」，关闭心跳/光环/闪烁 ---------- */
@media (prefers-reduced-motion: reduce) {
  .ht-chat-launcher,
  .ht-chat-launcher:hover { transition: none; transform: none; animation: none; }
  .ht-chat-launcher::before,
  .ht-chat-launcher::after,
  .ht-chat-launcher .ht-chat-dot { animation: none; }
  .ht-chat-launcher svg .ht-chat-dot { opacity: .85; }
}
