/* ============================================================
   在线客服聊天系统 - 共享样式（设计令牌 + 通用组件）
   设计语言：暖白纸感 + 墨色头部 + 珊瑚橙点缀
   用户气泡：绿色系（右）  客服气泡：蓝色系（左）
   ============================================================ */

:root {
  /* 品牌色 */
  --cf-ink-900: #161a24;
  --cf-ink-800: #1f2532;
  --cf-ink-700: #2b3242;
  --cf-accent: #f97316;
  --cf-accent-hover: #ea580c;
  --cf-accent-soft: #fff1e6;

  /* 中性色（暖调） */
  --cf-bg: #f6f5f2;
  --cf-surface: #ffffff;
  --cf-surface-warm: #faf9f6;
  --cf-border: #e8e5df;
  --cf-border-strong: #d8d4cc;
  --cf-text: #26292f;
  --cf-text-sub: #6b6f78;
  --cf-text-faint: #9a9ea8;

  /* 气泡 */
  --cf-bubble-user-from: #23a04d;
  --cf-bubble-user-to: #15803d;
  --cf-bubble-user-text: #ffffff;
  --cf-bubble-other-bg: #e9f1fe;
  --cf-bubble-other-border: #d4e3fc;
  --cf-bubble-other-text: #1e3352;

  /* 语义色 */
  --cf-danger: #e5484d;
  --cf-success: #22a06b;
  --cf-warning: #f5a524;

  /* 字体 */
  --cf-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;

  /* 圆角 / 阴影 */
  --cf-radius-s: 8px;
  --cf-radius-m: 12px;
  --cf-radius-l: 18px;
  --cf-radius-bubble: 16px;
  --cf-shadow-pop: 0 12px 40px rgba(22, 26, 36, .18), 0 2px 8px rgba(22, 26, 36, .08);
  --cf-shadow-card: 0 1px 2px rgba(22, 26, 36, .05);
  --cf-shadow-float-btn: 0 6px 20px rgba(249, 115, 22, .45);

  /* 动效 */
  --cf-ease: cubic-bezier(.16, 1, .3, 1);
  --cf-fast: .18s var(--cf-ease);
  --cf-normal: .32s var(--cf-ease);
}

/* ---------- 通用头像 ---------- */
.cf-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--cf-border);
  box-shadow: 0 0 0 2px #fff, 0 1px 3px rgba(0, 0, 0, .12);
}
.cf-avatar--text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  user-select: none;
}

/* ---------- 消息列表 ---------- */
.cf-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 12px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.cf-messages::-webkit-scrollbar { width: 6px; }
.cf-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, .14);
  border-radius: 3px;
}
.cf-messages::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, .24); }

/* 时间分隔条 */
.cf-time-divider {
  text-align: center;
  margin: 6px 0 14px;
}
.cf-time-divider span {
  display: inline-block;
  font-size: 12px;
  color: var(--cf-text-faint);
  background: rgba(0, 0, 0, .05);
  padding: 2px 12px;
  border-radius: 99px;
}

/* 单条消息 */
.cf-msg {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-bottom: 16px;
  animation: cfMsgIn .28s var(--cf-ease);
}
@keyframes cfMsgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.cf-msg--mine { flex-direction: row-reverse; }

.cf-msg-body {
  max-width: 74%;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.cf-msg--mine .cf-msg-body { align-items: flex-end; }

.cf-msg-meta {
  font-size: 12px;
  color: var(--cf-text-faint);
  margin: 0 4px 4px;
  display: flex;
  gap: 6px;
  align-items: baseline;
}
.cf-msg--mine .cf-msg-meta { flex-direction: row-reverse; }

.cf-bubble {
  position: relative;
  padding: 9px 13px;
  border-radius: var(--cf-radius-bubble);
  font-size: 14.5px;
  line-height: 1.62;
  word-break: break-word;
  white-space: pre-wrap;
  width: fit-content;
  max-width: 100%;
}
.cf-msg--mine .cf-bubble {
  background: linear-gradient(135deg, var(--cf-bubble-user-from), var(--cf-bubble-user-to));
  color: var(--cf-bubble-user-text);
  border-bottom-right-radius: 5px;
  box-shadow: 0 2px 8px rgba(21, 128, 61, .25);
}
.cf-msg--other .cf-bubble {
  background: var(--cf-bubble-other-bg);
  border: 1px solid var(--cf-bubble-other-border);
  color: var(--cf-bubble-other-text);
  border-bottom-left-radius: 5px;
}

/* 气泡内图片 */
.cf-bubble--image {
  padding: 4px;
  background: var(--cf-surface) !important;
  border: 1px solid var(--cf-border) !important;
  cursor: zoom-in;
  overflow: hidden;
}
.cf-bubble--image img {
  display: block;
  max-width: 200px;
  max-height: 220px;
  border-radius: 12px;
  object-fit: cover;
}

/* 发送中 / 失败态 */
.cf-msg--pending .cf-bubble { opacity: .55; }
.cf-msg-status {
  font-size: 11px;
  color: var(--cf-text-faint);
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.cf-msg-status--error { color: var(--cf-danger); cursor: pointer; }
.cf-msg-status--error:hover { text-decoration: underline; }

.cf-spin {
  display: inline-block;
  width: 11px;
  height: 11px;
  border: 2px solid rgba(0, 0, 0, .15);
  border-top-color: var(--cf-text-sub);
  border-radius: 50%;
  animation: cfSpin .7s linear infinite;
}
@keyframes cfSpin { to { transform: rotate(360deg); } }

/* ---------- 输入区 ---------- */
.cf-input-area {
  border-top: 1px solid var(--cf-border);
  background: var(--cf-surface);
  padding: 10px 12px 12px;
  position: relative;
}
.cf-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-bottom: 6px;
}
.cf-tool-btn {
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  border-radius: var(--cf-radius-s);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--cf-text-sub);
  transition: background var(--cf-fast), color var(--cf-fast);
  padding: 0;
}
.cf-tool-btn:hover { background: var(--cf-accent-soft); color: var(--cf-accent); }
.cf-tool-btn svg { width: 20px; height: 20px; }

.cf-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
.cf-textarea {
  flex: 1;
  border: 1px solid var(--cf-border-strong);
  border-radius: var(--cf-radius-m);
  background: var(--cf-surface-warm);
  resize: none;
  padding: 9px 12px;
  font-family: var(--cf-font);
  font-size: 14.5px;
  line-height: 1.5;
  max-height: 110px;
  min-height: 40px;
  outline: none;
  color: var(--cf-text);
  transition: border-color var(--cf-fast), box-shadow var(--cf-fast), background var(--cf-fast);
}
.cf-textarea:focus {
  border-color: var(--cf-accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(249, 115, 22, .14);
}
.cf-textarea::placeholder { color: var(--cf-text-faint); }

.cf-send-btn {
  height: 40px;
  padding: 0 20px;
  border: none;
  border-radius: var(--cf-radius-m);
  background: linear-gradient(135deg, var(--cf-accent), var(--cf-accent-hover));
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--cf-font);
  cursor: pointer;
  flex-shrink: 0;
  letter-spacing: .05em;
  transition: transform var(--cf-fast), box-shadow var(--cf-fast), opacity var(--cf-fast);
  box-shadow: 0 3px 10px rgba(249, 115, 22, .35);
}
.cf-send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 5px 14px rgba(249, 115, 22, .45);
}
.cf-send-btn:active:not(:disabled) { transform: translateY(0); }
.cf-send-btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

/* ---------- 表情面板 ---------- */
.cf-emoji-panel {
  position: absolute;
  left: 10px;
  bottom: calc(100% + 6px);
  width: 316px;
  max-width: calc(100vw - 24px);
  background: var(--cf-surface);
  border: 1px solid var(--cf-border);
  border-radius: var(--cf-radius-l);
  box-shadow: var(--cf-shadow-pop);
  padding: 12px;
  z-index: 60;
  opacity: 0;
  transform: translateY(8px) scale(.97);
  pointer-events: none;
  transition: opacity var(--cf-fast), transform var(--cf-fast);
}
.cf-emoji-panel--open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.cf-emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  max-height: 216px;
  overflow-y: auto;
}
.cf-emoji-item {
  border: none;
  background: transparent;
  font-size: 21px;
  line-height: 1;
  padding: 6px 0;
  border-radius: var(--cf-radius-s);
  cursor: pointer;
  transition: background var(--cf-fast), transform var(--cf-fast);
}
.cf-emoji-item:hover { background: var(--cf-accent-soft); transform: scale(1.18); }

/* ---------- 图片预览遮罩 ---------- */
.cf-lightbox {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: rgba(12, 14, 20, .86);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  animation: cfFadeIn .2s ease;
  padding: 24px;
}
@keyframes cfFadeIn { from { opacity: 0; } to { opacity: 1; } }
.cf-lightbox img {
  max-width: 92vw;
  max-height: 88vh;
  border-radius: var(--cf-radius-m);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
  animation: cfZoomIn .28s var(--cf-ease);
}
@keyframes cfZoomIn {
  from { opacity: 0; transform: scale(.86); }
  to { opacity: 1; transform: scale(1); }
}
.cf-lightbox-close {
  position: absolute;
  top: 18px;
  right: 22px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, .14);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  transition: background var(--cf-fast);
}
.cf-lightbox-close:hover { background: rgba(255, 255, 255, .28); }

/* ---------- 状态标签 ---------- */
.cf-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 3px 11px;
  border-radius: 99px;
  font-weight: 500;
}
.cf-status-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.cf-status-pill--online { background: rgba(34, 160, 107, .16); color: #4ade9e; }
.cf-status-pill--connecting { background: rgba(245, 165, 36, .16); color: #fbbf4e; }
.cf-status-pill--closed { background: rgba(255, 255, 255, .12); color: rgba(255, 255, 255, .65); }
.cf-status-pill--offline { background: rgba(229, 72, 77, .2); color: #ff8a8e; }

/* ---------- 未读角标 ---------- */
.cf-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 99px;
  background: var(--cf-danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  box-shadow: 0 0 0 2px #fff;
}

/* ---------- Toast ---------- */
.cf-toast {
  position: fixed;
  left: 50%;
  top: 32px;
  transform: translateX(-50%) translateY(-12px);
  background: var(--cf-ink-900);
  color: #fff;
  font-size: 13.5px;
  padding: 10px 20px;
  border-radius: 99px;
  box-shadow: var(--cf-shadow-pop);
  z-index: 100000;
  opacity: 0;
  transition: opacity var(--cf-fast), transform var(--cf-fast);
  pointer-events: none;
  max-width: 80vw;
}
.cf-toast--show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 空状态 ---------- */
.cf-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--cf-text-faint);
  gap: 12px;
  padding: 40px 20px;
  text-align: center;
}
.cf-empty svg { width: 64px; height: 64px; opacity: .4; }
.cf-empty p { margin: 0; font-size: 14px; line-height: 1.7; }

/* ---------- 隐藏文件输入 ---------- */
.cf-file-input { display: none; }

/* ---------- 动效偏好 ---------- */
@media (prefers-reduced-motion: reduce) {
  .cf-msg, .cf-lightbox img { animation: none; }
  * { transition-duration: .01ms !important; }
}

/* ---------- 加载更多历史消息（用户端+客服端共用） ---------- */
.cf-load-more {
  text-align: center;
  padding: 12px 16px;
  font-size: 12.5px;
  color: var(--cf-text-sub);
  cursor: pointer;
  user-select: none;
  transition: color var(--cf-fast);
}
.cf-load-more:hover { color: var(--cf-accent); }

.cf-load-top {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
}
