/* ============================================================================
   SACLR 通用会话组件（聊天）
   ----------------------------------------------------------------------------
   ★ 用户要求（原文）：
     「用户这边需要优化啊，管理员在左，用户在右，而且工单办结可以自动折叠，
       用户可以在选择打开折叠，这个界面也支持发表情和图片啊……
       只要有输入的地方就要支持表情那些啊！还有主页和帖子页支持@功能，
       可以@已有的用户，跟抖音一样啊，这个工单聊天页面跟私信页面一样，
       支持已读，撤回，引用，正在输入！！！！！！
       ……论坛，评论区，聊天，工单，就不能实时出现消息吗？
       必须还要刷新一下才会有消息，这个很难实现吗？」

   ★ 为什么要抽成公共组件：
     私信页（forum/messages.html）本来就已经有 表情/图片/引用/撤回/已读/
     正在输入/轮询 —— 但**只有私信有**。工单、入职申请都没有。
     与其复制四遍（以后改一处漏三处），不如抽成这一份：
        · 工单对话、入职申请对话、私信   → 三种会话共用
        · 论坛评论区、帖子评论           → 只需要"表情 + @"
     后端对应 chat_engine.py 的 /api/chat/ 系列接口。

   ★ 左右规则（用户明确要求）：
       自己发的消息在**右**，对方在**左**。
       工单里"用户"是提交人、"管理员/管理组"是处理方 ——
       所以管理员看到自己在右、玩家在左；玩家看到自己在右、管理员在左。
       —— 这是聊天软件的通用直觉，双方视角都自然。
   ========================================================================== */

/* ---------------------------------------------------------------- 消息列表 */
.sc-chat {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 4px 2px 2px;
}
.sc-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  max-width: 78%;
  width: fit-content;
  animation: scMsgIn .32s cubic-bezier(.2,.8,.2,1) both;
}
@keyframes scMsgIn {
  from { opacity: 0; transform: translateY(8px) scale(.985); }
  to   { opacity: 1; transform: none; }
}
/* 对方在左（默认），自己在右 */
.sc-row.mine {
  margin-left: auto;
  flex-direction: row-reverse;
}
.sc-av {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  display: grid; place-items: center; font-size: .9rem;
  background: rgba(255,255,255,.06);
  border: 1px solid var(--line, rgba(148,163,184,.2));
  color: var(--muted, #8b98a9);
  overflow: hidden;
}
.sc-av img { width: 100%; height: 100%; object-fit: cover; }
.sc-row.mine .sc-av {
  background: linear-gradient(150deg, rgba(41,151,255,.28), rgba(10,132,255,.18));
  color: #fff; border-color: rgba(41,151,255,.4);
}
.sc-main { min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.sc-head {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  font-size: .74rem; color: var(--muted, #8b98a9);
}
.sc-row.mine .sc-head { flex-direction: row-reverse; }
.sc-who { color: var(--text, #e7f0ff); font-size: .8rem; font-weight: 600; }
.sc-tag {
  padding: 1px 7px; border-radius: 20px; font-size: .68rem;
  border: 1px solid transparent;
}
.sc-tag.staff { color: #93c5fd; background: rgba(59,130,246,.13);
  border-color: rgba(59,130,246,.3); }
.sc-tag.user { color: #6ee7b7; background: rgba(52,211,153,.12);
  border-color: rgba(52,211,153,.28); }
.sc-tag.origin { color: #c4b5fd; background: rgba(139,92,246,.13);
  border-color: rgba(139,92,246,.3); }
.sc-at { font-size: .7rem; white-space: nowrap; }

/* ---------------------------------------------------------------- 气泡 */
.sc-bubble {
  position: relative;
  padding: 9px 13px;
  border-radius: 14px;
  background: rgba(255,255,255,.045);
  border: 1px solid var(--line, rgba(148,163,184,.18));
  color: var(--text, #e7f0ff);
  font-size: .89rem;
  line-height: 1.62;
  word-break: break-word;
  white-space: pre-wrap;
  transition: background .2s ease, border-color .2s ease;
}
.sc-row:not(.mine) .sc-bubble { border-top-left-radius: 5px; }
.sc-row.mine .sc-bubble {
  border-top-right-radius: 5px;
  background: linear-gradient(150deg, rgba(41,151,255,.20), rgba(10,132,255,.12));
  border-color: rgba(41,151,255,.32);
}
/* 图片消息 */
.sc-bubble-img { padding: 5px; line-height: 0; }
.sc-bubble-img img {
  max-width: 260px; max-height: 300px; width: auto; border-radius: 10px;
  cursor: zoom-in; display: block;
}
.sc-bubble-body:empty { display: none; }
/* 引用块 */
.sc-quote {
  display: flex; flex-direction: column; gap: 2px;
  margin-bottom: 7px; padding: 6px 9px;
  border-left: 3px solid rgba(41,151,255,.6);
  border-radius: 0 8px 8px 0;
  background: rgba(0,0,0,.2);
  font-size: .76rem; cursor: pointer;
  transition: background .2s ease;
}
.sc-quote:hover { background: rgba(0,0,0,.32); }
.sc-quote b { color: #93c5fd; font-weight: 600; }
.sc-quote span {
  color: var(--muted, #8b98a9);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
/* 已撤回 */
.sc-recalled {
  display: flex; align-items: center; gap: 6px;
  color: var(--muted, #8b98a9); font-size: .8rem; font-style: normal;
  background: transparent !important; border-style: dashed !important;
}
/* 操作条（悬停出现：撤回 / 引用） */
.sc-acts {
  display: flex; align-items: center; gap: 4px;
  margin-top: 5px; font-size: .7rem;
  color: var(--muted, #8b98a9);
  opacity: 0; transition: opacity .2s ease;
}
.sc-row:hover .sc-acts, .sc-row.touch .sc-acts { opacity: 1; }
.sc-row.mine .sc-acts { justify-content: flex-end; }
.sc-act {
  background: none; border: none; padding: 2px 6px; border-radius: 6px;
  color: inherit; font-size: .7rem; cursor: pointer;
  transition: background .16s ease, color .16s ease;
}
.sc-act:hover { background: rgba(255,255,255,.08); color: var(--text, #e7f0ff); }
/* 已读回执 */
.sc-read { display: inline-flex; align-items: center; gap: 3px; font-size: .7rem; }
.sc-read.read { color: #38bdf8; }

/* ---------------------------------------------------------------- 正在输入 */
.sc-typing {
  display: none; align-items: center; gap: 8px;
  padding: 6px 4px; font-size: .76rem; color: var(--muted, #8b98a9);
  min-height: 26px;
}
.sc-typing.on { display: flex; }
.sc-dots { display: inline-flex; gap: 3px; }
.sc-dots i {
  width: 5px; height: 5px; border-radius: 50%; background: currentColor;
  animation: scDot 1.15s ease-in-out infinite;
}
.sc-dots i:nth-child(2) { animation-delay: .16s; }
.sc-dots i:nth-child(3) { animation-delay: .32s; }
@keyframes scDot {
  0%, 60%, 100% { opacity: .28; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-3px); }
}

/* ---------------------------------------------------------------- 输入区 */
.sc-compose {
  display: flex; flex-direction: column; gap: 8px;
  margin-top: 12px; padding: 12px;
  border-radius: 14px;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--line, rgba(148,163,184,.18));
  transition: border-color .22s ease, box-shadow .22s ease;
}
.sc-compose:focus-within {
  border-color: rgba(41,151,255,.5);
  box-shadow: 0 0 0 3px rgba(41,151,255,.12);
}
.sc-quote-bar {
  display: none; align-items: center; gap: 9px;
  padding: 7px 10px; border-radius: 9px;
  background: rgba(41,151,255,.09);
  border-left: 3px solid #2997ff;
  font-size: .78rem; color: var(--muted, #8b98a9);
}
.sc-quote-bar.on { display: flex; }
.sc-quote-bar b { color: #93c5fd; }
.sc-quote-bar span {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
}
.sc-quote-x {
  background: none; border: none; color: var(--muted, #8b98a9);
  cursor: pointer; padding: 2px 5px; border-radius: 5px;
}
.sc-quote-x:hover { background: rgba(255,255,255,.1); color: var(--text); }
/* ⚠⚠ 输入行改成"纵向"：上面是输入区，下面是工具行。
   ----------------------------------------------------------------------------
   原来是 `display:flex; align-items:flex-end` + textarea(flex:1) + 工具(右侧)，
   结果 **打字区域被右侧工具横向挤窄** —— 两行字就换行，用户看到的
   就是"一个小框里打字"（实测截图确认）。
   改成纵向后 textarea 占满整行宽度，视觉上是一个舒展的输入区。 */
.sc-input-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
}
/* 原来的横向排布留给"工具行"自身用 */
.sc-input-row > .sc-tools { align-self: flex-end; }
.sc-ta {
  /* 原来的高度是 42px / 150px —— 两行字就换行，
     用户描述成「只能在那个小框里面打消息」（实测确认）。
     放宽到 52px / 220px，配合上面 .sc-input-row 的纵向排布，
     输入区就变成一个舒展的大框了。 */
  flex: 1; min-height: 52px; max-height: 220px; resize: none;
  background: transparent; border: none; outline: none;
  color: var(--text, #e7f0ff); font-size: .9rem; line-height: 1.6;
  font-family: inherit; padding: 8px 2px;
}
.sc-ta::placeholder { color: var(--muted, #8b98a9); }
.sc-tools { display: flex; align-items: center; gap: 4px; padding-bottom: 4px; }
.sc-tool {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center; cursor: pointer;
  background: none; border: 1px solid transparent;
  color: var(--muted, #8b98a9); font-size: 1rem;
  transition: background .18s ease, color .18s ease, border-color .18s ease,
              transform .18s cubic-bezier(.2,.8,.2,1);
}
.sc-tool:hover {
  background: rgba(255,255,255,.07); color: var(--text, #e7f0ff);
  border-color: var(--line, rgba(148,163,184,.2));
}
.sc-tool:active { transform: scale(.93); }
.sc-send {
  height: 38px; padding: 0 16px; border-radius: 10px; border: none;
  cursor: pointer; font-size: .85rem; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, #2997ff, #0a84ff);
  box-shadow: 0 4px 14px rgba(41,151,255,.3);
  display: inline-flex; align-items: center; gap: 6px;
  transition: transform .18s cubic-bezier(.2,.8,.2,1), box-shadow .22s ease,
              filter .2s ease;
}
.sc-send:hover { filter: brightness(1.08); box-shadow: 0 6px 18px rgba(41,151,255,.42); }
.sc-send:active { transform: scale(.96); }
.sc-send:disabled { opacity: .5; cursor: not-allowed; }

/* 图片预览 */
.sc-imgpick { display: none; position: relative; width: fit-content; }
.sc-imgpick.on { display: block; }
.sc-imgpick img {
  max-height: 110px; border-radius: 10px;
  border: 1px solid var(--line, rgba(148,163,184,.24));
}
.sc-imgpick-x {
  position: absolute; top: -8px; right: -8px;
  width: 24px; height: 24px; border-radius: 50%; border: none;
  background: #ef4444; color: #fff; cursor: pointer; font-size: .7rem;
  display: grid; place-items: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.sc-hint { font-size: .72rem; color: var(--muted, #8b98a9); }

/* ---------------------------------------------------------------- 表情面板 */
.sc-emoji {
  display: none; flex-wrap: wrap; gap: 3px; padding: 9px;
  border-radius: 12px; max-height: 176px; overflow-y: auto;
  background: rgba(9,16,28,.97);
  border: 1px solid var(--line, rgba(148,163,184,.24));
  box-shadow: 0 12px 32px rgba(0,0,0,.44);
}
.sc-emoji.on { display: flex; }
.sc-emoji button {
  width: 32px; height: 32px; border-radius: 8px; border: none;
  background: none; cursor: pointer; font-size: 1.15rem; line-height: 1;
  transition: background .14s ease, transform .14s cubic-bezier(.2,.8,.2,1);
}
.sc-emoji button:hover { background: rgba(255,255,255,.1); transform: scale(1.16); }
.sc-emoji-cat {
  width: 100%; font-size: .68rem; color: var(--muted, #8b98a9);
  padding: 5px 4px 2px; letter-spacing: .5px;
}

/* ---------------------------------------------------------------- @ 提及 */
.sc-mention {
  position: absolute; z-index: 900; display: none;
  min-width: 210px; max-height: 216px; overflow-y: auto;
  padding: 5px; border-radius: 12px;
  background: rgba(9,16,28,.98);
  border: 1px solid var(--line, rgba(148,163,184,.26));
  box-shadow: 0 14px 36px rgba(0,0,0,.5);
}
.sc-mention.on { display: block; }
.sc-mention button {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 7px 9px; border-radius: 8px; border: none; background: none;
  cursor: pointer; text-align: left; color: var(--text, #e7f0ff);
  font-size: .84rem;
}
.sc-mention button:hover, .sc-mention button.on {
  background: rgba(41,151,255,.16);
}
.sc-mention .nm { color: var(--muted, #8b98a9); font-size: .72rem; }
.sc-mention .av {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  background: rgba(255,255,255,.08); display: grid; place-items: center;
  font-size: .72rem; color: var(--muted, #8b98a9); overflow: hidden;
}
.sc-mention .av img { width: 100%; height: 100%; object-fit: cover; }
/* 正文里的 @提及 高亮 */
.sc-at-user { color: #38bdf8; font-weight: 500; }

/* ---------------------------------------------------------------- 折叠 */
.sc-collapse {
  margin-top: 6px; padding: 13px 15px; border-radius: 13px;
  display: flex; align-items: center; gap: 11px; cursor: pointer;
  background: rgba(52,211,153,.07);
  border: 1px solid rgba(52,211,153,.22);
  transition: background .2s ease, border-color .2s ease;
}
.sc-collapse:hover { background: rgba(52,211,153,.11); }
.sc-collapse-ic { color: #34d399; font-size: 1.1rem; flex-shrink: 0; }
.sc-collapse-tx { flex: 1; min-width: 0; }
.sc-collapse-tx b { display: block; font-size: .86rem; color: #6ee7b7; }
.sc-collapse-tx span {
  font-size: .78rem; color: var(--muted, #8b98a9);
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical;
  overflow: hidden;
}
.sc-collapse-x {
  color: var(--muted, #8b98a9); font-size: .8rem; flex-shrink: 0;
  transition: transform .3s cubic-bezier(.2,.8,.2,1);
}
.sc-collapse.open .sc-collapse-x { transform: rotate(180deg); }
/* 折叠时被收起的内容 */
.sc-foldable { display: none; }
.sc-foldable.open { display: block; }

/* ---------------------------------------------------------------- 响应式 */
@media (max-width: 640px) {
  .sc-row { max-width: 92%; }
  .sc-bubble { font-size: .86rem; padding: 8px 11px; }
  .sc-bubble-img img { max-width: 200px; max-height: 240px; }
  .sc-av { width: 30px; height: 30px; border-radius: 9px; }
  .sc-acts { opacity: 1; }          /* 手机没有 hover，操作常显 */
  .sc-compose { padding: 10px; }
  .sc-ta { font-size: 16px; }        /* 防 iOS 聚焦缩放 */
  .sc-emoji button { width: 34px; height: 34px; }
}
@media (prefers-reduced-motion: reduce) {
  .sc-row, .sc-dots i { animation: none !important; }
  .sc-tool, .sc-send, .sc-quote { transition: none !important; }
}


/* 输入框聚焦态：给一个柔和的光晕，让"正在输入"这件事看起来更有反馈 */
.sc-ta:focus {
  outline: none;
}
.sc-compose:focus-within {
  border-color: rgba(41, 151, 255, .45);
  box-shadow: 0 0 0 3px rgba(41, 151, 255, .1);
}


/* @不到的用户（工单 / 私信侧）：弱化显示，点不了是**有意**的 */
.sc-at-dead {
  color: var(--muted, #8b98a9);
  cursor: default;
  border-bottom: 1px dashed rgba(255, 255, 255, .14);
}
.sc-at-user { color: #6cb6ff; font-weight: 600; text-decoration: none; }
.sc-at-user:hover { text-decoration: underline; }
