/* ============================================================
 * 启昊 CRM · 内部聊天入口样式
 * 与现有玻璃拟态主题保持一致：半透明、细边框、圆角 10px
 * ============================================================ */

.qh-chat-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin: 0 2px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--n-text-color-2, #5b6472);
  cursor: pointer;
  transition: background .16s ease, color .16s ease, transform .16s ease;
  -webkit-tap-highlight-color: transparent;
}
.qh-chat-btn:hover {
  background: rgba(47, 111, 237, .10);
  color: var(--n-text-color, #1f2733);
}
.qh-chat-btn:active { transform: scale(.94); }
.qh-chat-btn:focus-visible {
  outline: 2px solid rgba(47, 111, 237, .55);
  outline-offset: 1px;
}
.qh-chat-btn svg { display: block; }

/* 回退挂载（未识别到图标组时） */
.qh-chat-btn-fallback { margin-left: auto; margin-right: 12px; }

/* 未读红点 */
.qh-chat-badge {
  position: absolute;
  top: -3px;
  right: -4px;
  min-width: 15px;
  height: 15px;
  padding: 0 4px;
  box-sizing: border-box;
  border-radius: 8px;
  background: #e5484d;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 15px;
  text-align: center;
  letter-spacing: -.2px;
  box-shadow: 0 0 0 2px var(--n-color, #fff);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  pointer-events: none;
}
.qh-chat-badge[hidden] { display: none; }
.qh-chat-btn.has-unread { color: #2f6fed; }

@keyframes qh-chat-shake {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-12deg); }
  40% { transform: rotate(10deg); }
  60% { transform: rotate(-6deg); }
  80% { transform: rotate(4deg); }
}
.qh-chat-btn.shake svg { animation: qh-chat-shake .85s ease; }

/* ---------------- 抽屉 ---------------- */
.qh-chat-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  /* 620 是能容纳「会话列表 264 + 聊天区 356」两栏的最小舒适宽度；
     窄于 560 时聊天页会退化成单栏（列表→聊天→返回）。 */
  width: 620px;
  max-width: 100vw;
  z-index: 2147482000;
  background: #fff;
  box-shadow: -10px 0 30px rgba(16, 24, 40, .14), -1px 0 0 rgba(16, 24, 40, .06);
  border-radius: 14px 0 0 14px;
  overflow: hidden;
  display: flex;
}
.qh-chat-drawer[hidden] { display: none; }

/* 预加载时不可见也不占据交互 */
.qh-chat-drawer.qh-chat-preload {
  visibility: hidden;
  pointer-events: none;
  display: flex;
}

.qh-chat-frame {
  flex: 1;
  width: 100%;
  height: 100%;
  border: 0;
  background: #f5f6f8;
  display: block;
}

/* 左边缘拖拽条 */
.qh-chat-grip {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 3;
}
.qh-chat-grip:hover { background: rgba(47, 111, 237, .18); }
body.qh-chat-resizing { user-select: none; cursor: col-resize; }
body.qh-chat-resizing iframe { pointer-events: none; }

/* 收起把手 */
.qh-chat-handle {
  position: absolute;
  left: -1px;
  top: 50%;
  z-index: 4;
  transform: translate(-100%, -50%);
  padding: 14px 5px;
  border-radius: 10px 0 0 10px;
  background: rgba(255, 255, 255, .92);
  border: 1px solid rgba(16, 24, 40, .10);
  border-right: 0;
  box-shadow: -4px 0 14px rgba(16, 24, 40, .08);
  cursor: pointer;
  opacity: 0;
  transition: opacity .18s ease, transform .18s ease, background .18s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.qh-chat-handle span {
  display: block;
  writing-mode: vertical-rl;
  font-size: 11px;
  letter-spacing: 2px;
  color: #6b7280;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}
.qh-chat-drawer:hover .qh-chat-handle { opacity: 1; transform: translate(-100%, -50%); }
.qh-chat-handle:hover { background: #fff; }
.qh-chat-handle:hover span { color: #2f6fed; }

/* 窄屏：整屏铺满，隐藏拖拽件与把手（用聊天页内返回键） */
@media (max-width: 700px) {
  .qh-chat-drawer {
    width: 100vw !important;
    border-radius: 0;
  }
  .qh-chat-grip, .qh-chat-handle { display: none; }
}

@media (prefers-color-scheme: dark) {
  .qh-chat-drawer { background: #16181d; }
  .qh-chat-frame { background: #16181d; }
  .qh-chat-handle {
    background: rgba(30, 33, 40, .92);
    border-color: rgba(255, 255, 255, .10);
  }
}
