/* ==========================================================================
   Shop Customer Service Widget (Web Chat Floating Container)
   Author: Antigravity Architecture Team
   ========================================================================== */

:root {
  --kefu-primary: #16141f;
  --kefu-primary-hover: #262335;
  --kefu-gradient: linear-gradient(135deg, #5b4bdb 0%, #4338ca 100%);
  --kefu-gradient-hover: linear-gradient(135deg, #4f3ec8 0%, #372e9e 100%);
  --kefu-accent: #5b4bdb;
  --kefu-bg: #fffcf8;
  --kefu-text: #16141f;
  --kefu-border: rgba(22, 20, 31, 0.1);
  --kefu-shadow: 0 18px 52px rgba(22, 20, 31, 0.2);
  --kefu-radius: 14px;
  --kefu-transition: cubic-bezier(0.16, 1, 0.3, 1);
}

/* 浮动根容器 */
.shop-kefu-root {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 2147483000;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  box-sizing: border-box;
}

.shop-kefu-root *,
.shop-kefu-root *::before,
.shop-kefu-root *::after {
  box-sizing: inherit;
}

/* 悬浮打开按钮 (高质感客服胶囊悬浮球，醒目且高端) */
.shop-kefu-launcher {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 50px;
  padding: 0 18px 0 16px;
  border: none;
  border-radius: 25px;
  background: var(--kefu-gradient);
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(91, 75, 219, 0.45), 0 2px 6px rgba(0, 0, 0, 0.1);
  transition: transform 0.25s var(--kefu-transition), box-shadow 0.25s ease, filter 0.2s;
  outline: none;
}

.shop-kefu-launcher:hover {
  transform: scale(1.05) translateY(-2px);
  box-shadow: 0 12px 32px rgba(91, 75, 219, 0.58), 0 4px 10px rgba(0, 0, 0, 0.16);
  filter: brightness(1.04);
}

.shop-kefu-launcher:active {
  transform: scale(0.96);
}

.shop-kefu-launcher svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: #ffffff;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
  flex-shrink: 0;
}

.shop-kefu-launcher-text {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #ffffff;
  white-space: nowrap;
}

.shop-kefu-live-indicator {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 8px #34d399;
  animation: kefu-glow 2s infinite ease-in-out;
  flex-shrink: 0;
}

@keyframes kefu-glow {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.25); opacity: 0.75; }
}

/* 桌面端悬停提示标签 (在线客服) */
.shop-kefu-tip {
  position: absolute;
  right: 68px;
  top: 50%;
  transform: translateY(-50%) translateX(6px);
  opacity: 0;
  pointer-events: none;
  background: rgba(17, 24, 39, 0.95);
  backdrop-filter: blur(8px);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  padding: 6px 13px;
  border-radius: 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  transition: opacity 0.2s ease, transform 0.2s ease;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 10;
}

.shop-kefu-tip-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
}

.shop-kefu-tip::after {
  content: "";
  position: absolute;
  right: -5px;
  top: 50%;
  transform: translateY(-50%);
  border-width: 5px 0 5px 5px;
  border-style: solid;
  border-color: transparent transparent transparent rgba(17, 24, 39, 0.95);
}

.shop-kefu-launcher:hover .shop-kefu-tip {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

/* 未读消息红点徽标 */
.shop-kefu-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: #ef4444;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px solid #ffffff;
  animation: kefu-pulse 2s infinite;
}

@keyframes kefu-pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* 聊天弹窗主体窗口 */
.shop-kefu-window {
  position: relative;
  display: none;
  width: 390px;
  height: 610px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 40px);
  background: var(--kefu-bg);
  border: 1px solid var(--kefu-border);
  border-radius: var(--kefu-radius);
  box-shadow: var(--kefu-shadow);
  overflow: hidden;
  flex-direction: column;
  transform-origin: bottom right;
  animation: kefu-scale-in 0.25s var(--kefu-transition);
}

@keyframes kefu-scale-in {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(16px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* 窗口状态切换 */
.shop-kefu-root.is-open .shop-kefu-window {
  display: flex;
}

.shop-kefu-root.is-open .shop-kefu-launcher {
  display: none;
}

/* 左上角自由缩放手柄 */
.shop-kefu-resize {
  position: absolute;
  top: 0;
  left: 0;
  width: 24px;
  height: 24px;
  z-index: 10;
  cursor: nwse-resize;
  background: transparent;
  border: none;
  padding: 0;
}

.shop-kefu-resize::before {
  content: "";
  position: absolute;
  top: 6px;
  left: 6px;
  width: 8px;
  height: 8px;
  border-top: 2px solid rgba(255, 255, 255, 0.7);
  border-left: 2px solid rgba(255, 255, 255, 0.7);
  transition: border-color 0.2s;
}

.shop-kefu-resize:hover::before {
  border-color: #ffffff;
}

/* 标题栏 */
.shop-kefu-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  background: var(--kefu-primary);
  color: #ffffff;
  padding: 0 12px 0 28px;
  flex-shrink: 0;
  user-select: none;
}

.shop-kefu-title-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.shop-kefu-title-info svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* 标题栏操作按钮组 */
.shop-kefu-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.shop-kefu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: #ffffff;
  cursor: pointer;
  padding: 0;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.shop-kefu-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

.shop-kefu-btn:active {
  transform: scale(0.92);
}

.shop-kefu-btn svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

/* 聊天 iframe 承载区 */
.shop-kefu-frame-wrap {
  position: relative;
  flex: 1;
  width: 100%;
  height: 100%;
  background: #f9fafb;
}

.shop-kefu-frame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* 正在调整大小时禁止 iframe 捕获鼠标事件 */
.shop-kefu-root.is-resizing,
.shop-kefu-root.is-resizing * {
  cursor: nwse-resize !important;
  user-select: none !important;
}

.shop-kefu-root.is-resizing .shop-kefu-frame {
  pointer-events: none;
}

/* 最大化全屏模式 */
.shop-kefu-root.is-maximized .shop-kefu-window {
  position: fixed;
  inset: 16px;
  width: auto !important;
  height: auto !important;
  max-width: none;
  max-height: none;
  border-radius: 8px;
}

.shop-kefu-root.is-maximized .shop-kefu-resize {
  display: none;
}

/* 移动端响应式适配 (< 768px) */
@media (max-width: 768px) {
  .shop-kefu-root {
    right: 16px;
    bottom: max(18px, env(safe-area-inset-bottom));
  }

  .shop-kefu-launcher {
    height: 40px !important;
    padding: 0 14px 0 10px !important;
    border-radius: 999px !important;
    gap: 6px !important;
    box-shadow: 0 4px 16px rgba(91, 75, 219, 0.45) !important;
  }
  .shop-kefu-launcher svg {
    width: 18px !important;
    height: 18px !important;
  }
  .shop-kefu-launcher-text {
    display: inline !important;
    font-size: 13px !important;
    font-weight: 600 !important;
  }
  .shop-kefu-live-indicator {
    position: absolute;
    bottom: 3px;
    right: 3px;
    width: 9px;
    height: 9px;
    border: 1.5px solid #ffffff;
  }

  /* 移动端全屏 Native 体验，适配 100dvh 与软键盘 */
  .shop-kefu-window {
    position: fixed;
    inset: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-width: 100vw !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    border: none !important;
  }

  .shop-kefu-tip {
    display: none !important;
  }

  .shop-kefu-resize {
    display: none !important;
  }

  .shop-kefu-titlebar {
    height: 52px;
    padding: 0 14px;
    padding-top: max(0px, env(safe-area-inset-top));
  }

  /* 移动端隐藏多余按钮，保留关闭 */
  .shop-kefu-popout,
  .shop-kefu-maximize {
    display: none !important;
  }

  .shop-kefu-btn {
    width: 36px;
    height: 36px;
  }
}

