/* 168客服 访客客户端样式 - 现代极简商务风 */
/* 全局统一设计规范：卡片圆角8px、按钮圆角6px、柔和阴影、微软雅黑/苹方 */

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  font-family: "Microsoft YaHei", "PingFang SC", -apple-system, sans-serif;
  background: #f5f7fa;
  min-height: 100vh;
}

.kefu-widget { position: fixed; z-index: 999999; font-family: "Microsoft YaHei", "PingFang SC", sans-serif; }

/* ========== 悬浮按钮 ========== */
.kefu-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  cursor: pointer;
  background: linear-gradient(135deg, #4a7dff 0%, #3b6fe0 100%);
  box-shadow: 0 4px 16px rgba(74, 125, 255, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: all 0.2s ease;
  z-index: 1000001;
  border: none;
}
.kefu-launcher:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(74, 125, 255, 0.5);
  background: linear-gradient(135deg, #5a8aff 0%, #4a7dff 100%);
}
.kefu-launcher svg { width: 28px; height: 28px; }
.kefu-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: #ff4d4f;
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  padding: 0 5px;
  display: none;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(255, 77, 79, 0.4);
}

/* ========== 客服主窗口 ========== */
.kefu-panel {
  position: fixed;
  right: 24px;
  bottom: 90px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 1000000;
  animation: panelIn 0.2s ease;
}
@keyframes panelIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.kefu-panel.open { display: flex; }

/* 最小化状态 */
.kefu-panel.minimized {
  height: 48px;
  min-height: 48px;
}
.kefu-panel.minimized .kefu-body,
.kefu-panel.minimized .kefu-footer,
.kefu-panel.minimized .kefu-notice,
.kefu-panel.minimized .kefu-agent-card {
  display: none;
}

/* ========== 顶部导航栏 ========== */
.kefu-header {
  background: #fff;
  border-bottom: 1px solid #f0f0f0;
  padding: 0 16px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.kefu-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.kefu-logo {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: linear-gradient(135deg, #4a7dff 0%, #3b6fe0 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}
.kefu-header-title {
  display: flex;
  flex-direction: column;
}
.kefu-header-title h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: #1a1a1a;
  line-height: 1.2;
}
.kefu-status {
  font-size: 11px;
  color: #52c41a;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}
.kefu-status .dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #52c41a;
}
.kefu-status.offline { color: #bfbfbf; }
.kefu-status.offline .dot { background: #bfbfbf; }
.kefu-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.kefu-header-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: #8c8c8c;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.15s ease;
}
.kefu-header-btn:hover {
  background: #f5f5f5;
  color: #1a1a1a;
}

/* ========== 公告区 ========== */
.kefu-notice {
  background: #f0f5ff;
  border-bottom: 1px solid #d6e4ff;
  padding: 10px 14px;
  max-height: 120px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.7;
  color: #595959;
  flex-shrink: 0;
}
.kefu-notice .notice-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.kefu-notice .notice-title {
  font-weight: 600;
  color: #2f54eb;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.kefu-notice .notice-close {
  background: transparent;
  border: none;
  color: #8c8c8c;
  font-size: 14px;
  cursor: pointer;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.kefu-notice .notice-close:hover {
  background: #e6e6e6;
  color: #1a1a1a;
}
.kefu-notice p { margin: 3px 0; }
.kefu-notice .c-red { color: #cf1322; font-weight: 600; }
.kefu-notice .c-green { color: #389e0d; font-weight: 600; }
.kefu-notice .c-blue { color: #1d39c4; }
.kefu-notice .c-gold { color: #d48806; font-weight: 600; }
.kefu-notice.hidden { display: none; }

/* ========== 客服信息卡片 ========== */
.kefu-agent-card {
  background: #fff;
  padding: 20px 16px;
  text-align: center;
  border-bottom: 1px solid #f0f0f0;
  flex-shrink: 0;
}
.kefu-agent-card .agent-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  overflow: hidden;
  margin: 0 auto 10px;
  border: 2px solid #fff;
  box-shadow: 0 2px 12px rgba(74, 125, 255, 0.25);
}
.kefu-agent-card .agent-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.kefu-agent-card .agent-name {
  font-size: 16px;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 4px;
}
.kefu-agent-card .agent-status {
  font-size: 12px;
  color: #52c41a;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.kefu-agent-card .agent-status .dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #52c41a;
}
.kefu-agent-card .agent-intro {
  font-size: 13px;
  color: #8c8c8c;
  margin-bottom: 14px;
}
.kefu-start-btn {
  background: linear-gradient(135deg, #4a7dff 0%, #3b6fe0 100%);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px 32px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 1px;
  box-shadow: 0 2px 8px rgba(74, 125, 255, 0.3);
  transition: all 0.2s ease;
}
.kefu-start-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(74, 125, 255, 0.4);
  background: linear-gradient(135deg, #5a8aff 0%, #4a7dff 100%);
}
.kefu-start-btn:active {
  transform: translateY(0);
}

/* ========== 聊天内容区 ========== */
.kefu-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  background: #f7f8fa;
  position: relative;
}

/* 加载动画 */
.kefu-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #bfbfbf;
}
.kefu-loading .spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #f0f0f0;
  border-top-color: #4a7dff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 10px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* 欢迎占位 */
.kefu-welcome-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #bfbfbf;
  text-align: center;
}
.kefu-welcome-placeholder .icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.5;
}
.kefu-welcome-placeholder .text {
  font-size: 14px;
}

/* 消息 - 通用 */
.kefu-msg {
  margin-bottom: 14px;
  display: flex;
  align-items: flex-start;
  position: relative;
  z-index: 1;
  animation: msgIn 0.2s ease;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.kefu-msg.right { justify-content: flex-end; flex-direction: row-reverse; }
.kefu-msg.left { justify-content: flex-start; }

.kefu-msg .msg-time {
  font-size: 10px;
  color: #bfbfbf;
  margin-bottom: 3px;
}
.kefu-msg.right .msg-time { text-align: right; }

.kefu-msg .bubble {
  max-width: 72%;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
}

/* 用户消息 - 浅灰气泡（居右） */
.kefu-msg.right .bubble {
  background: #fff;
  color: #1a1a1a;
  border: 1px solid #f0f0f0;
  border-bottom-right-radius: 2px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

/* 机器人消息 - 浅蓝气泡（居左） */
.kefu-msg.left.bot .bubble {
  background: #e6f0ff;
  color: #1a1a1a;
  border-bottom-left-radius: 2px;
}

/* 人工客服消息 - 深蓝气泡（居左） */
.kefu-msg.left.agent .bubble {
  background: linear-gradient(135deg, #4a7dff 0%, #3b6fe0 100%);
  color: #fff;
  border-bottom-left-radius: 2px;
  box-shadow: 0 2px 6px rgba(74, 125, 255, 0.25);
}

.kefu-msg .msg-status {
  font-size: 10px;
  color: #bfbfbf;
  margin-top: 3px;
}
.kefu-msg.right .msg-status { text-align: right; }

/* 头像 */
.kefu-msg .kefu-avatar {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
  margin: 0 8px;
  align-self: flex-start;
  background: #f0f0f0;
}
.kefu-msg .kefu-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* 系统消息 */
.kefu-msg.system-msg {
  justify-content: center;
}
.kefu-msg.system-msg .bubble {
  background: transparent;
  color: #bfbfbf;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 10px;
  box-shadow: none;
  border: none;
}

/* 转接人工等待动画 */
.kefu-waiting {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #fffbe6;
  border: 1px solid #ffe58f;
  border-radius: 6px;
  font-size: 12px;
  color: #d48806;
  margin: 8px 0;
}
.kefu-waiting .dots {
  display: inline-flex;
  gap: 3px;
}
.kefu-waiting .dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #d48806;
  animation: dotBounce 1.2s infinite;
}
.kefu-waiting .dots span:nth-child(2) { animation-delay: 0.2s; }
.kefu-waiting .dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* FAQ */
.kefu-faq {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 0;
  position: relative;
  z-index: 1;
}
.kefu-faq button {
  border: 1px solid #d6e4ff;
  color: #2f54eb;
  background: #fff;
  border-radius: 12px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.kefu-faq button:hover {
  background: #4a7dff;
  color: #fff;
  border-color: #4a7dff;
}

.kefu-typing {
  color: #8c8c8c;
  font-size: 12px;
  padding: 4px 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.kefu-typing .typing-dots {
  display: inline-flex;
  gap: 3px;
}
.kefu-typing .typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #8c8c8c;
  animation: dotBounce 1.2s infinite;
}
.kefu-typing .typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.kefu-typing .typing-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ========== 底部输入区 ========== */
.kefu-footer {
  border-top: 1px solid #f0f0f0;
  padding: 8px 12px 10px;
  background: #fff;
  flex-shrink: 0;
}
.kefu-footer.disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* 工具栏 */
.kefu-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 2px 8px;
  border-bottom: 1px solid #fafafa;
  margin-bottom: 8px;
}
.kefu-toolbar-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: #8c8c8c;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.15s ease;
  position: relative;
}
.kefu-toolbar-btn:hover {
  background: #f5f5f5;
  color: #4a7dff;
}
.kefu-toolbar-btn input[type="file"] {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.kefu-toolbar .kefu-typing {
  margin-left: auto;
  padding: 0;
}

/* 输入框区域 */
.kefu-inputbar {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.kefu-inputbar textarea {
  flex: 1;
  min-height: 36px;
  max-height: 100px;
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  resize: none;
  outline: none;
  font-family: inherit;
  line-height: 1.5;
  transition: all 0.15s ease;
  background: #fafafa;
  overflow-y: auto;
}
.kefu-inputbar textarea:focus {
  background: #fff;
  box-shadow: 0 0 0 2px rgba(74, 125, 255, 0.15);
}
.kefu-inputbar textarea:disabled {
  background: #f5f5f5;
  cursor: not-allowed;
}
.kefu-btn-send {
  background: linear-gradient(135deg, #4a7dff 0%, #3b6fe0 100%);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0 18px;
  height: 36px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s ease;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.kefu-btn-send:hover:not(:disabled) {
  background: linear-gradient(135deg, #5a8aff 0%, #4a7dff 100%);
  box-shadow: 0 2px 8px rgba(74, 125, 255, 0.35);
}
.kefu-btn-send:active:not(:disabled) {
  transform: scale(0.97);
}
.kefu-btn-send:disabled {
  background: #d9d9d9;
  cursor: not-allowed;
}

/* ========== 评价弹窗 ========== */
.kefu-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 999998;
  display: none;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.kefu-mask.open { display: flex; }
.kefu-dialog {
  background: #fff;
  border-radius: 8px;
  width: 320px;
  padding: 24px;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
  animation: dialogIn 0.2s ease;
}
@keyframes dialogIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.kefu-dialog h4 {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 600;
  color: #1a1a1a;
}
.kefu-stars {
  font-size: 32px;
  color: #f0f0f0;
  cursor: pointer;
  letter-spacing: 6px;
  margin-bottom: 14px;
  user-select: none;
}
.kefu-stars .on {
  background: linear-gradient(135deg, #ffd700 0%, #ffa500 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.kefu-dialog textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #f0f0f0;
  border-radius: 6px;
  padding: 10px;
  height: 70px;
  font-size: 13px;
  resize: none;
  outline: none;
  font-family: inherit;
  transition: all 0.15s;
}
.kefu-dialog textarea:focus {
  border-color: #4a7dff;
  box-shadow: 0 0 0 2px rgba(74, 125, 255, 0.1);
}
.kefu-dialog .btns {
  margin-top: 16px;
  display: flex;
  gap: 10px;
  justify-content: center;
}
.kefu-dialog .btns button {
  padding: 8px 22px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s;
}
.kefu-dialog .btns .primary {
  background: linear-gradient(135deg, #4a7dff 0%, #3b6fe0 100%);
  color: #fff;
}
.kefu-dialog .btns .primary:hover {
  box-shadow: 0 2px 8px rgba(74, 125, 255, 0.35);
}
.kefu-dialog .btns .plain {
  background: #f5f5f5;
  color: #595959;
}
.kefu-dialog .btns .plain:hover {
  background: #e8e8e8;
}

/* 图片消息 */
.kefu-msg .bubble img {
  max-width: 180px;
  border-radius: 6px;
  display: block;
  cursor: pointer;
}

/* 文件消息 */
.kefu-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  min-width: 160px;
}
.kefu-file .file-icon {
  font-size: 24px;
}
.kefu-file .file-info {
  flex: 1;
  min-width: 0;
}
.kefu-file .file-name {
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kefu-file .file-size {
  font-size: 10px;
  opacity: 0.7;
}

/* 滚动条美化 */
.kefu-body::-webkit-scrollbar,
.kefu-notice::-webkit-scrollbar,
.kefu-inputbar textarea::-webkit-scrollbar {
  width: 4px;
}
.kefu-body::-webkit-scrollbar-track,
.kefu-notice::-webkit-scrollbar-track,
.kefu-inputbar textarea::-webkit-scrollbar-track {
  background: transparent;
}
.kefu-body::-webkit-scrollbar-thumb,
.kefu-notice::-webkit-scrollbar-thumb,
.kefu-inputbar textarea::-webkit-scrollbar-thumb {
  background: #d9d9d9;
  border-radius: 2px;
}
.kefu-body::-webkit-scrollbar-thumb:hover,
.kefu-notice::-webkit-scrollbar-thumb:hover {
  background: #bfbfbf;
}

/* 移动端适配 */
@media (max-width: 480px) {
  .kefu-panel {
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }
  .kefu-launcher {
    right: 16px;
    bottom: 16px;
    width: 50px;
    height: 50px;
  }
  .kefu-panel.minimized {
    display: none;
  }
}
