/* ============ 在线客服聊天组件 ============ */
.chat-widget *,
.chat-widget *::before,
.chat-widget *::after {
  box-sizing: border-box;
}

/* 聊天面板（入口为右下角功能圆 fab 的「在线咨询」） */
.chat-widget {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
.chat-panel {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 9991;
  width: 360px;
  max-width: calc(100vw - 30px);
  height: 520px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
}
.chat-panel.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* 头部 */
.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: linear-gradient(135deg, #4f46e5, #0ea5e9);
  color: #fff;
}
.chat-head-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.chat-head-info {
  flex: 1;
  min-width: 0;
}
.chat-head-info .name {
  font-size: 15px;
  font-weight: 600;
}
.chat-head-info .status {
  font-size: 12px;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 4px;
}
.chat-head-info .status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
}
.chat-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  opacity: 0.8;
  padding: 4px;
  line-height: 1;
}
.chat-close:hover {
  opacity: 1;
}

/* 消息区 */
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #f6f7fb;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-msg {
  display: flex;
  gap: 8px;
  max-width: 85%;
}
.chat-msg .avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  background: #e2e8f0;
}
.chat-msg .bubble {
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-msg .time {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 3px;
}
.chat-msg.agent {
  align-self: flex-start;
}
.chat-msg.agent .bubble {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-top-left-radius: 4px;
  color: #334155;
}
.chat-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.chat-msg.user .avatar {
  background: #c7d2fe;
}
.chat-msg.user .bubble {
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  color: #fff;
  border-top-right-radius: 4px;
}
.chat-msg.user .time {
  text-align: right;
}
.chat-msg.failed .bubble {
  border: 1px dashed #ef4444;
  opacity: 0.8;
}
.chat-msg.failed .bubble::after {
  content: '发送失败';
  display: inline-block;
  margin-left: 8px;
  font-size: 11px;
  font-weight: 600;
  color: #ef4444;
}

/* 开始表单 */
.chat-start {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  padding: 16px;
}
.chat-start .tip {
  text-align: center;
  font-size: 13px;
  color: #64748b;
  line-height: 1.6;
}
.chat-start input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}
.chat-start input:focus {
  border-color: #6366f1;
}
.chat-form-error {
  min-height: 18px;
  margin-top: -5px;
  color: #dc2626;
  font-size: 12px;
  line-height: 1.5;
}
.chat-start .btn-start {
  width: 100%;
  padding: 11px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #4f46e5, #0ea5e9);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}
.chat-start .btn-start:hover {
  opacity: 0.9;
}

/* 输入区 */
.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid #eef2f7;
  background: #fff;
}
.chat-input-bar textarea {
  flex: 1;
  resize: none;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  line-height: 1.4;
  height: 40px;
  max-height: 90px;
  transition: border-color 0.2s;
}
.chat-input-bar textarea:focus {
  border-color: #6366f1;
}
.chat-input-bar .btn-send {
  padding: 0 18px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #4f46e5, #0ea5e9);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  height: 40px;
  transition: opacity 0.2s;
}
.chat-input-bar .btn-send:hover {
  opacity: 0.9;
}

/* 客服离线提示 */
.chat-offline {
  text-align: center;
  font-size: 12px;
  color: #94a3b8;
  padding: 4px 0;
}

/* 滚动条 */
.chat-body::-webkit-scrollbar,
.chat-input-bar textarea::-webkit-scrollbar {
  width: 6px;
}
.chat-body::-webkit-scrollbar-thumb,
.chat-input-bar textarea::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

@media (max-width: 480px) {
  .chat-panel {
    right: 8px;
    left: 8px;
    bottom: 12px;
    width: auto;
    height: 70vh;
  }
}
