/* ============================================================
   SimpleChat Widget 样式
   嵌入方式：<link rel="stylesheet" href="/simplechat/widget.css">
   ============================================================ */

/* ---- CSS 变量 ---- */
.sc-root {
  --sc-brand-from:   #6366f1;
  --sc-brand-to:     #8b5cf6;
  --sc-danger:       #ef4444;
  --sc-success:      #34d399;
  --sc-warning-from: #f59e0b;
  --sc-warning-to:   #f97316;
  --sc-radius-sm:    8px;
  --sc-radius-md:    14px;
  --sc-radius-lg:    20px;
  --sc-radius-xl:    24px;
  --sc-radius-full:  9999px;
  --sc-dur:          0.22s;
  --sc-ease:         cubic-bezier(0.34, 1.56, 0.64, 1);
  --sc-ease-smooth:  cubic-bezier(0.4, 0, 0.2, 1);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
               'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   悬浮启动按钮（桌面胶囊 / 移动圆形）
   ============================================================ */
.sc-launcher-wrap {
  position: fixed;
  right: 50px;
  top: 50%;
  bottom: auto;
  left: auto;
  transform: translateY(-50%);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  /* 位置由 widget.js 根据 cfg.position 动态覆盖 */
}

.sc-launcher {
  height: 64px;
  padding: 0 24px 0 16px;
  border-radius: var(--sc-radius-full);
  background: linear-gradient(135deg, var(--sc-brand-from) 0%, var(--sc-brand-to) 100%);
  box-shadow:
    0 6px 24px rgba(99,102,241,.5),
    inset 0 1px 0 rgba(255,255,255,.22);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  transition:
    transform var(--sc-dur) var(--sc-ease),
    box-shadow var(--sc-dur) var(--sc-ease-smooth);
  white-space: nowrap;
  user-select: none;
  border: none;
  outline: none;
}
.sc-launcher:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow:
    0 12px 32px rgba(99,102,241,.55),
    0 2px 8px rgba(0,0,0,.1),
    inset 0 1px 0 rgba(255,255,255,.25);
}
.sc-launcher:active { transform: translateY(-1px) scale(0.99); }

/* 胶囊内图标圆圈 */
.sc-launcher-icon {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  border: 1.5px solid rgba(255,255,255,.3);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  position: relative;
}
.sc-launcher-icon svg { width: 22px; height: 22px; fill: #fff; }

/* 在线绿点 */
.sc-launcher-icon::after {
  content: '';
  position: absolute;
  bottom: 0; right: 0;
  width: 10px; height: 10px;
  background: var(--sc-success);
  border-radius: 50%;
  border: 2px solid var(--sc-brand-from);
  animation: sc-online-pulse 2.5s infinite;
}
.sc-launcher.is-busy .sc-launcher-icon::after {
  background: var(--sc-warning-from);
  animation: none;
}
@keyframes sc-online-pulse {
  0%,100% { transform: scale(1);    opacity: 1; }
  50%      { transform: scale(.85); opacity: .7; }
}

/* 胶囊文字 */
.sc-launcher-text { display: flex; flex-direction: column; gap: 1px; }
.sc-launcher-title { font-size: 16px; font-weight: 650; color: #fff; line-height: 1.2; }
.sc-launcher-sub   { font-size: 12px; color: rgba(255,255,255,.72); line-height: 1.2; }

/* 忙碌状态 */
.sc-launcher.is-busy {
  background: linear-gradient(135deg, var(--sc-warning-from), var(--sc-warning-to));
  box-shadow: 0 6px 24px rgba(245,158,11,.45), inset 0 1px 0 rgba(255,255,255,.2);
}

/* 未读角标 */
.sc-badge {
  position: absolute;
  top: -4px; right: -4px;
  min-width: 20px; height: 20px;
  background: var(--sc-danger);
  border-radius: var(--sc-radius-full);
  border: 2.5px solid #fff;
  font-size: 10px; font-weight: 700; color: #fff;
  display: none; align-items: center; justify-content: center;
  padding: 0 4px;
  animation: sc-badge-pop .3s var(--sc-ease);
}
.sc-badge.show { display: flex; }
@keyframes sc-badge-pop {
  0%   { transform: scale(0); }
  100% { transform: scale(1); }
}

/* 波纹呼吸 */
.sc-launcher.pulse::before {
  content: '';
  position: absolute;
  inset: -10px;
  border-radius: var(--sc-radius-full);
  border: 2px solid rgba(99,102,241,.38);
  animation: sc-ripple 2.2s infinite;
  pointer-events: none;
}
@keyframes sc-ripple {
  0%   { opacity: .8; transform: scale(.95); }
  100% { opacity: 0;  transform: scale(1.1); }
}

/* 移动端：退化为圆形 */
@media (max-width: 768px) {
  .sc-launcher {
    width: 52px; height: 52px;
    padding: 0;
    border-radius: 50%;
    justify-content: center;
  }
  .sc-launcher .sc-launcher-text { display: none; }
  .sc-launcher .sc-launcher-icon {
    width: 100%; height: 100%;
    background: transparent; border: none;
  }
  .sc-launcher .sc-launcher-icon::after { display: none; }
  .sc-launcher .sc-launcher-icon svg { width: 24px; height: 24px; }
  .sc-launcher.pulse::before { border-radius: 50%; }
  .sc-launcher-wrap { right: 16px; bottom: 16px; }
}

/* ============================================================
   聊天对话框
   ============================================================ */
.sc-dialog {
  position: fixed;
  right: 28px;
  bottom: 96px;
  width: 360px;
  max-height: 560px;
  background: #fff;
  border-radius: var(--sc-radius-xl);
  box-shadow:
    0 24px 64px rgba(0,0,0,.16),
    0 4px 16px rgba(0,0,0,.08),
    0 0 0 1px rgba(0,0,0,.04);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  transform-origin: bottom right;
  transition:
    transform var(--sc-dur) var(--sc-ease),
    opacity var(--sc-dur) var(--sc-ease-smooth);
}
.sc-dialog.hidden {
  transform: scale(0.88) translateY(12px);
  opacity: 0;
  pointer-events: none;
}

/* 头部 */
.sc-header {
  background: linear-gradient(135deg, var(--sc-brand-from) 0%, var(--sc-brand-to) 100%);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.sc-header-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  border: 2px solid rgba(255,255,255,.35);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.sc-header-info { flex: 1; min-width: 0; }
.sc-header-name {
  font-size: 15px; font-weight: 650; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sc-header-status {
  font-size: 12px; color: rgba(255,255,255,.78);
  display: flex; align-items: center; gap: 4px; margin-top: 1px;
}
.sc-status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--sc-success);
  animation: sc-online-pulse 2.5s infinite;
  flex-shrink: 0;
}
.sc-header-close {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--sc-dur);
  flex-shrink: 0;
}
.sc-header-close:hover { background: rgba(255,255,255,.28); }
.sc-header-close svg { width: 14px; height: 14px; stroke: #fff; fill: none; }

/* 消息列表 */
.sc-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #f5f4fb;
  scroll-behavior: smooth;
}
.sc-messages::-webkit-scrollbar { width: 4px; }
.sc-messages::-webkit-scrollbar-track { background: transparent; }
.sc-messages::-webkit-scrollbar-thumb { background: rgba(99,102,241,.2); border-radius: 2px; }

/* 消息气泡 */
.sc-msg { display: flex; gap: 8px; align-items: flex-end; }
.sc-msg.user { flex-direction: row-reverse; }

.sc-msg-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--sc-brand-from), var(--sc-brand-to));
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.sc-msg-body { max-width: 75%; display: flex; flex-direction: column; gap: 3px; }
.sc-msg.user .sc-msg-body { align-items: flex-end; }

.sc-bubble {
  padding: 10px 13px;
  border-radius: var(--sc-radius-md);
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}
/* 机器人消息 */
.sc-msg.bot .sc-bubble {
  background: #fff;
  color: #1f2937;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
/* 系统消息 */
.sc-msg.system .sc-bubble {
  background: #fff;
  color: #374151;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
/* 访客消息 */
.sc-msg.user .sc-bubble {
  background: linear-gradient(135deg, var(--sc-brand-from), var(--sc-brand-to));
  color: #fff;
  border-bottom-right-radius: 4px;
}

.sc-msg-time {
  font-size: 10px;
  color: #9ca3af;
  padding: 0 4px;
}

/* 二维码卡片 */
.sc-qr-card {
  background: linear-gradient(135deg, #f0f0ff 0%, #f5f0ff 100%);
  border: 1.5px solid rgba(99,102,241,.15);
  border-radius: var(--sc-radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
.sc-qr-img {
  width: 110px; height: 110px;
  border-radius: var(--sc-radius-sm);
  object-fit: cover;
  border: 3px solid #fff;
  box-shadow: 0 4px 12px rgba(99,102,241,.2);
}
.sc-qr-placeholder {
  width: 110px; height: 110px;
  border-radius: var(--sc-radius-sm);
  background: linear-gradient(135deg, rgba(99,102,241,.1), rgba(139,92,246,.1));
  border: 2px dashed rgba(99,102,241,.3);
  display: flex; align-items: center; justify-content: center;
  font-size: 36px;
}
.sc-qr-text {
  font-size: 12px;
  color: #6366f1;
  font-weight: 500;
  text-align: center;
  line-height: 1.5;
}

/* 正在输入动画 */
.sc-typing-wrap {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.sc-typing {
  display: flex; align-items: center; gap: 4px;
  background: #fff;
  padding: 10px 14px;
  border-radius: var(--sc-radius-md);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.sc-typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--sc-brand-from);
  animation: sc-typing 1.2s infinite;
}
.sc-typing span:nth-child(2) { animation-delay: .2s; background: var(--sc-brand-to); }
.sc-typing span:nth-child(3) { animation-delay: .4s; background: #a78bfa; }
@keyframes sc-typing {
  0%,60%,100% { transform: translateY(0);   opacity: .6; }
  30%          { transform: translateY(-5px); opacity: 1;  }
}

/* 满员状态 */
.sc-busy-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 20px 0 4px;
}
.sc-busy-icon {
  width: 60px; height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(245,158,11,.12), rgba(249,115,22,.12));
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
}
.sc-busy-title {
  font-size: 15px; font-weight: 600; color: #374151; text-align: center;
}
.sc-busy-sub {
  font-size: 13px; color: #6b7280; text-align: center; line-height: 1.5; max-width: 220px;
}

/* 系统提示文字（会话结束等） */
.sc-sys-notice {
  text-align: center;
  font-size: 12px;
  color: #9ca3af;
  padding: 4px 0;
}

/* 输入区 */
.sc-footer {
  border-top: 1px solid #f0eeff;
  padding: 10px 12px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #fff;
  flex-shrink: 0;
}
.sc-input {
  flex: 1;
  background: #f5f4fb;
  border: 1.5px solid transparent;
  border-radius: var(--sc-radius-md);
  padding: 9px 12px;
  font-size: 14px;
  color: #1f2937;
  resize: none;
  outline: none;
  max-height: 96px;
  line-height: 1.5;
  transition: border-color var(--sc-dur), background var(--sc-dur);
  font-family: inherit;
}
.sc-input::placeholder { color: #b0aac8; }
.sc-input:focus {
  border-color: rgba(99,102,241,.4);
  background: #fff;
}

.sc-send-btn {
  width: 38px; height: 38px;
  border-radius: var(--sc-radius-sm);
  background: linear-gradient(135deg, var(--sc-brand-from), var(--sc-brand-to));
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform var(--sc-dur) var(--sc-ease), opacity var(--sc-dur);
  flex-shrink: 0;
}
.sc-send-btn:hover  { transform: scale(1.08); }
.sc-send-btn:active { transform: scale(0.95); }
.sc-send-btn:disabled { opacity: .4; cursor: default; transform: none; }
.sc-send-btn svg { width: 17px; height: 17px; fill: #fff; }

/* 移动端全屏 */
@media (max-width: 768px) {
  .sc-dialog {
    right: 0; bottom: 0; left: 0;
    width: 100%;
    max-height: 100dvh;
    border-radius: var(--sc-radius-xl) var(--sc-radius-xl) 0 0;
    transform-origin: bottom center;
  }
  .sc-dialog.hidden {
    transform: translateY(100%);
    opacity: 1;
  }
}
