/* ===== 悬浮根容器 ===== */
.chat-root {
  position: fixed;
  right: 20px;
  top: 45%;
  transform: translateY(-50%);
  z-index: 2147483647;
  display: block;
  visibility: visible;
  opacity: 1;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* ===== 悬浮按钮 ===== */
.chat-toggle {
  position: relative;
  display: inline-block;
  background: #07c160;
  color: #fff;
  border: 0;
  border-radius: 24px;
  padding: 10px 18px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
  font-size: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.2;
  text-align: center;
  width: auto;
  height: auto;
  box-sizing: border-box;
  text-transform: none;
  letter-spacing: normal;
  visibility: visible;
  opacity: 1;
}
.chat-toggle:hover {
  background: #06ad56;
}

.chat-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #ff3b30;
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  border: 2px solid #fff;
  line-height: 1;
  font-weight: bold;
}

/* ===== 面板 ===== */
.chat-panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 340px;
  height: 560px;
  min-width: 320px;
  min-height: 400px;
  max-width: 90vw;
  max-height: 90vh;
  background: #ededed;
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overflow-x: hidden;
  transition: width 0.2s, height 0.2s;
  z-index: 2147483647;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;

  --chat-panel-bg: #ededed;
  --chat-head-bg: #ededed;
  --chat-head-fg: #111;
  --chat-body-bg: #ededed;
  --chat-name-fg: #888;
  --chat-time-fg: #999;
  --chat-bubble-visitor-bg: #95ec69;
  --chat-bubble-visitor-fg: #111;
  --chat-bubble-agent-bg: #ffffff;
  --chat-bubble-agent-fg: #111;
  --chat-input-bg: #f7f7f7;
  --chat-input-fg: #111;
  --chat-input-border: #ddd;
  --chat-send-bg: #07c160;
  --chat-send-fg: #fff;
  --chat-scroll-thumb: #c1c1c1;
  --chat-scroll-track: transparent;
  --chat-welcome-bg: #ffffff;
  --chat-welcome-fg: #666;
  --chat-welcome-title: #07c160;
  --chat-notice-fg: #888;
  --chat-btn-border: #ccc;
}

/* 暗黑模式变量 */
.chat-panel.chat-theme-dark {
  --chat-panel-bg: #111214;
  --chat-head-bg: #1e1f22;
  --chat-head-fg: #f2f3f5;
  --chat-body-bg: #111214;
  --chat-name-fg: #8a8f98;
  --chat-time-fg: #6b7078;
  --chat-bubble-visitor-bg: #3a3d43;
  --chat-bubble-visitor-fg: #e6e7e9;
  --chat-bubble-agent-bg: #26282c;
  --chat-bubble-agent-fg: #e6e7e9;
  --chat-input-bg: #1e1f22;
  --chat-input-fg: #e6e7e9;
  --chat-input-border: #3a3d43;
  --chat-send-bg: #07c160;
  --chat-send-fg: #fff;
  --chat-scroll-thumb: #3a3d43;
  --chat-scroll-track: transparent;
  --chat-welcome-bg: #1e1f22;
  --chat-welcome-fg: #8a8f98;
  --chat-welcome-title: #07c160;
  --chat-notice-fg: #8a8f98;
  --chat-btn-border: #3a3d43;
  background: var(--chat-panel-bg);
}

/* 拖拽调整大小的八个触角 */
.chat-resizer {
  position: absolute;
  z-index: 100;
  background: transparent;
}
.chat-resizer-r { right: 0; top: 0; bottom: 0; width: 5px; cursor: ew-resize; }
.chat-resizer-l { left: 0; top: 0; bottom: 0; width: 5px; cursor: ew-resize; }
.chat-resizer-b { bottom: 0; left: 0; right: 0; height: 5px; cursor: ns-resize; }
.chat-resizer-t { top: 0; left: 0; right: 0; height: 5px; cursor: ns-resize; }
.chat-resizer-br { bottom: 0; right: 0; width: 10px; height: 10px; cursor: nwse-resize; }
.chat-resizer-bl { bottom: 0; left: 0; width: 10px; height: 10px; cursor: nesw-resize; }
.chat-resizer-tr { top: 0; right: 0; width: 10px; height: 10px; cursor: nesw-resize; }
.chat-resizer-tl { top: 0; left: 0; width: 10px; height: 10px; cursor: nwse-resize; }

/* 顶部标题栏 */
.chat-head {
  background: var(--chat-head-bg);
  color: var(--chat-head-fg);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgba(0,0,0,.06);
  cursor: move;
  user-select: none;
}
.chat-title {
  font-weight: 600;
  font-size: 14px;
  margin: 0 auto;
  transform: translateX(-22px);
  pointer-events: none;
}

.chat-mac-btns {
  position: relative;
  width: 45px;
  height: 10px;
  flex-shrink: 0;
  pointer-events: none;
}
.chat-mac-btns img {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}
.mac-btn {
  position: absolute;
  top: 0;
  height: 100%;
  width: 15px;
  pointer-events: auto;
  cursor: pointer;
}
.mac-close { left: 0; }
.mac-min { left: 15px; }
.mac-max { left: 30px; }

/* 聊天主体 */
.chat-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
  background: var(--chat-body-bg);
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--chat-scroll-thumb) var(--chat-scroll-track);
}
.chat-body::-webkit-scrollbar { width: 8px; height: 8px; }
.chat-body::-webkit-scrollbar-track { background: var(--chat-scroll-track); }
.chat-body::-webkit-scrollbar-thumb {
  background: var(--chat-scroll-thumb);
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: content-box;
}
.chat-body::-webkit-scrollbar-thumb:hover {
  background: var(--chat-scroll-thumb);
  background-clip: content-box;
}

/* 欢迎语 */
.chat-welcome {
  background: var(--chat-welcome-bg);
  color: var(--chat-welcome-fg);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0 0 12px;
  font-size: 12px;
  line-height: 1.6;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.chat-welcome-title {
  color: var(--chat-welcome-title);
  font-weight: 600;
  margin-bottom: 2px;
}
.chat-welcome-text { color: var(--chat-welcome-fg); }

/* 消息列表 */
.chat-row { display: flex; align-items: flex-start; margin: 10px 0; gap: 8px; }
.chat-row.visitor { flex-direction: row-reverse; }

.chat-avatar { width: 36px; height: 36px; border-radius: 50px; flex-shrink: 0; object-fit: cover; }

.chat-bubble-wrap { max-width: 76%; display: flex; flex-direction: column; min-width: 0; }
.chat-row.visitor .chat-bubble-wrap { align-items: flex-end; }
.chat-row.agent .chat-bubble-wrap { align-items: flex-start; }

.chat-name { font-size: 11px; color: var(--chat-name-fg); margin-bottom: 3px; padding: 0 2px; }

.chat-bubble {
  padding: 8px 11px;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
  overflow-wrap: anywhere;
  position: relative;
  white-space: pre-line;
  max-width: 100%;
}
.chat-row.visitor .chat-bubble { background: var(--chat-bubble-visitor-bg); color: var(--chat-bubble-visitor-fg); }
.chat-row.agent .chat-bubble { background: var(--chat-bubble-agent-bg); color: var(--chat-bubble-agent-fg); }
.chat-time { display: none; font-size: 10px; color: var(--chat-time-fg); margin-top: 3px; padding: 0 2px; }

.chat-bubble img.chat-img {
  max-width: 100%;
  max-height: 200px;
  border-radius: 4px;
  display: block;
  margin: 4px 0;
}

/* 图片带链接时的光标和过渡 */
.chat-bubble .chat-img-link {
    display: inline-block;
    cursor: pointer;
    transition: opacity 0.2s;
}
.chat-bubble .chat-img-link:hover {
    opacity: 0.9;
}
.chat-bubble .chat-img-link img {
    margin: 0;
    border: none;
}

/* 状态提示框 */
.chat-state-notice {
  text-align: center;
  font-size: 12px;
  color: var(--chat-notice-fg);
  margin: 15px 0;
  padding: 10px;
}
.chat-state-notice .chat-request-btn {
  display: inline-block;
  margin-top: 10px;
  padding: 8px 22px;
  border: none;
  background: #07c160;
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  transition: background 0.2s, opacity 0.2s;
  box-shadow: none;
}
.chat-state-notice .chat-request-btn:hover {
  background: #06ad56;
  color: #fff;
}
.chat-state-notice .chat-request-btn:active {
  background: #059a4c;
}
.chat-state-notice .chat-request-btn:disabled {
  background: #9ed9b5;
  color: #fff;
  cursor: not-allowed;
  opacity: 0.9;
}

/* 输入区 */
.chat-input {
  display: flex;
  align-items: stretch;
  border-top: 1px solid var(--chat-input-border);
  background: var(--chat-input-bg);
  height: 100px;
  flex-shrink: 0;
}
.chat-input textarea {
  flex: 1;
  height: 100%;
  min-height: 0;
  box-sizing: border-box;
  border: 0;
  resize: none;
  padding: 10px;
  font-size: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif !important;
  line-height: 1.4;
  outline: none;
  background: transparent;
  color: var(--chat-input-fg);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: hidden;
  overflow-y: auto;
}
.chat-input textarea::placeholder {
  color: var(--chat-input-fg);
  opacity: .4;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif !important;
}

.chat-send {
  border: 0;
  background: var(--chat-send-bg);
  color: var(--chat-send-fg);
  padding: 0 16px;
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif !important;
  height: 100%;
  min-width: 80px;
  text-align: center;
  flex-shrink: 0;
}
.chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* 移动端适配 */
@media (max-width: 768px) {
  .chat-panel {
    width: calc(100vw - 24px);
    min-width: 280px;
    max-width: calc(100vw - 24px);
    height: 70vh;
  }
}

/* ===== 针对副站主题全局覆盖的兜底（放在最后） ===== */
.chat-root,
.chat-root .chat-toggle {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}
.chat-root {
  position: fixed !important;
  right: 20px !important;
  top: 45% !important;
  transform: translateY(-50%) !important;
  z-index: 2147483647 !important;
}
.chat-root .chat-toggle {
  display: inline-block !important;
  position: relative !important;
  background: #07c160 !important;
  color: #fff !important;
  border: 0 !important;
  border-radius: 24px !important;
  padding: 10px 18px !important;
  cursor: pointer !important;
  box-shadow: 0 4px 12px rgba(0,0,0,.2) !important;
  font-size: 14px !important;
  line-height: 1.2 !important;
  text-align: center !important;
  width: auto !important;
  height: auto !important;
  min-width: 0 !important;
  min-height: 0 !important;
  box-sizing: border-box !important;
  text-transform: none !important;
  letter-spacing: normal !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif !important;
}
.chat-root .chat-toggle:hover {
  background: #06ad56 !important;
}

/* 图片带链接时的光标和过渡 */
.chat-bubble .chat-img-link {
    display: inline-block;
    cursor: pointer;
    transition: opacity 0.2s;
}
.chat-bubble .chat-img-link:hover {
    opacity: 0.9;
}
.chat-bubble .chat-img-link img {
    margin: 0;
    border: none;
}