/* =============================================================================
 * 在线交流（实时聊天）· v20261125g
 * 顶栏入口按钮复用画笔标注原气泡图标，样式与其一致（主题变量驱动，不写死色值）。
 * 面板为浮动小窗，跟随主题。类名统一 ht-chat- 前缀。
 * 2026-11-22b：新增头像 / 姓名 / 身份标签 / 在线状态 / 未登录只读提示；移除门户头像小条。
 * 2026-11-22c：入口气泡改为「心跳」动态图——双拍心跳缩放 + 两圈错峰扩散光环 +
 *              三个聊天气泡点依次闪烁；颜色全部走主题变量，支持 prefers-reduced-motion。
 * 2026-11-25b：标题栏保持原样；主体改左右两栏（左=消息+输入，右=在线统计+名单+分页），
 *              窄屏自动上下堆叠；所有新色值仍走主题变量，不引入全局样式污染。
 * 2026-11-25c：消息区左右内边距 12px→6px（减半）；在线成员身份后新增登录地省份样式。
 * ========================================================================== */

/* ---------- 顶栏入口容器（单一气泡按钮） ---------- */
.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: 16px; height: 16px; font-size: 9px; }
.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;
  /* 2026-11-25d：面板整体尺寸按当前 860×620 缩小 50%（430×310），内部字号不缩放；
     2026-11-25e：宽度保持 430px 不变，高度在 310px 基础上增加 100% → 620px；
     2026-11-25g：仅左侧「消息显示区」左右宽度 +100%（232 → 464），右栏 196px 与高度 620px 不变，
                 面板宽 = 464 + 196 + 2px 边框 = 662px */
  width: min(662px, calc(100vw - 28px));
  max-width: calc(100vw - 24px);
  height: min(620px, 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-body {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  /* 右栏随面板收窄：264px → 196px（严格等比 132px 会把姓名压成单字，按可读性取值） */
  grid-template-columns: minmax(0, 1fr) 196px;
}
.ht-chat-left {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}
.ht-chat-side {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--surface-2);
}
.ht-chat-compose {
  flex: 0 0 auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.ht-chat-compose .ht-chat-foot,
.ht-chat-compose .ht-chat-readonly { border-top: 0; }

.ht-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  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-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 6px 6px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.ht-chat-online-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}
.ht-chat-online-total {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--primary-50);
  border-radius: 999px;
  padding: 2px 6px;
  white-space: nowrap;
}
.ht-chat-online-total b { color: var(--primary); font-weight: 600; }
.ht-chat-online {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: stretch;
  padding: 4px;
  overflow-y: auto;
  font-size: 12px;
  color: var(--text-secondary);
}
.ht-chat-online-label { color: var(--text-tertiary); }
.ht-chat-online-empty {
  color: var(--text-tertiary);
  font-size: 11px;
  text-align: center;
  padding: 18px 6px;
}
.ht-chat-user-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 26px;
  padding: 2px 4px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--surface);
}
.ht-chat-user-row:hover { border-color: var(--border); background: var(--primary-50); }
.ht-chat-user-index {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-tertiary);
  font-size: 10px;
  line-height: 1;
}
.ht-chat-user-meta {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.ht-chat-user-line {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}
.ht-chat-user-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}
.ht-chat-user-account {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
  color: var(--text-tertiary);
}
.ht-chat-online-role {
  flex: 0 0 auto;
  font-size: 10px;
  line-height: 13px;
  padding: 0 3px;
  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; }
/* 登录地：右对齐，与右侧在线状态点形成稳定的信息列（2026-11-25d） */
.ht-chat-user-region {
  flex: 0 0 auto;
  margin-left: auto;
  padding-left: 3px;
  max-width: 44px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
  font-size: 10px;
  line-height: 13px;
  color: var(--text-tertiary);
}
.ht-chat-online-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #52c41a;
  box-shadow: 0 0 0 2px rgba(82, 196, 26, .16);
  flex: 0 0 auto;
}
.ht-chat-online-pager {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  padding: 4px 5px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.ht-chat-pager-info {
  margin-right: auto;
  font-size: 10px;
  color: var(--text-tertiary);
  white-space: nowrap;
}
.ht-chat-pager-gap { font-size: 11px; color: var(--text-tertiary); padding: 0 1px; }
.ht-chat-page-btn {
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
}
.ht-chat-page-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.ht-chat-page-btn.is-current { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.ht-chat-page-btn:disabled { opacity: .45; cursor: not-allowed; }
.ht-chat-page-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
[data-theme="dark"] .ht-chat-online-total { background: var(--sidebar-active-bg); }

.ht-chat-msgs {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 6px;   /* 2026-11-25c：左右内边距由 12px 减半为 6px；2026-11-25d：上下 10px→8px */
  display: flex;
  flex-direction: column;
  gap: 6px;
  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 5px;   /* 2026-11-25c：空态左右留白同步减半 */
  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: 6px;
  padding: 6px 8px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.ht-chat-input {
  flex: 1 1 auto;
  resize: none;
  max-height: 72px;
  min-height: 30px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text-primary);
  padding: 5px 8px;
  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: 34px;
  height: 34px;
  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: 84vh;
    border-radius: 14px 14px 0 0;
  }
  .ht-chat-body { display: flex; flex-direction: column; }
  .ht-chat-left { flex: 1 1 auto; min-height: 0; }
  .ht-chat-side {
    flex: 0 0 auto;
    max-height: 210px;
    border-left: 0;
    border-top: 1px solid var(--border);
  }
  .ht-chat-online { max-height: 118px; }
  .ht-chat-online-head { padding: 8px 10px; }
  .ht-chat-online-pager { justify-content: center; }
}
@media (max-width: 420px) {
  .ht-chat-panel { height: 88vh; }
  .ht-chat-user-account { display: none; }
  .ht-chat-pager-info { font-size: 9px; }
}

/* ---------- 打印：聊天一律不出现 ---------- */
@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; }
}
