/* components.css — 访客端可复用组件：按钮、头像、消息气泡、媒体（图片/视频/语音/文件）、
   日期分隔、输入中、横幅、弹层、灯箱、提示条、录音条。只引用 tokens.css 变量。 */

/* ---------- 按钮 ---------- */
.kf-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--h-control); padding: 0 var(--sp-4);
  border: 1px solid transparent; border-radius: var(--r-btn);
  font-size: var(--fs-md); font-weight: 500; line-height: 1; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.kf-btn--primary { background: var(--brand-600); color: var(--brand-contrast); }
.kf-btn--primary:hover { background: var(--brand-700); }
.kf-btn--ghost { background: transparent; color: var(--text-secondary); border-color: var(--border-strong); }
.kf-btn--ghost:hover { background: var(--surface-hover); color: var(--text); }
.kf-btn:disabled { opacity: .5; cursor: not-allowed; }

.kf-icon-btn {
  flex: 0 0 auto; width: var(--h-icon-btn); height: var(--h-icon-btn);
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0; border: 0; border-radius: var(--r-btn); background: transparent; color: var(--text-secondary);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.kf-icon-btn:hover { background: var(--bg-sunken); color: var(--text); }
.kf-icon-btn:disabled { color: var(--text-muted); opacity: .5; cursor: default; background: transparent; }
.kf-icon-btn--quiet { color: var(--text-muted); }
.kf-send { border-radius: 50%; background: var(--brand-600); color: var(--brand-contrast); }
.kf-send:hover:not(:disabled) { background: var(--brand-700); color: var(--brand-contrast); }
.kf-send:disabled { background: var(--bg-sunken); color: var(--text-muted); opacity: 1; }
.kf-mic.is-recording { color: var(--accent); background: var(--accent-soft); }

/* ---------- 头像 ---------- */
.kf-avatar {
  flex: 0 0 auto; width: var(--avatar); height: var(--avatar); border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand-100); color: var(--brand-700);
  font-size: var(--fs-md); font-weight: 600; user-select: none; overflow: hidden;
}
.kf-avatar--brand { width: 40px; height: 40px; background: var(--brand-600); color: var(--brand-contrast); font-size: var(--fs-lg); }
.kf-avatar--sm { width: 28px; height: 28px; font-size: var(--fs-xs); }

/* ---------- 消息行 ---------- */
.kf-msg { display: flex; align-items: flex-start; gap: var(--sp-2); animation: kf-in var(--dur-base) var(--ease); }
.kf-msg--own { flex-direction: row-reverse; }
.kf-msg--system { justify-content: center; padding: var(--sp-1) 0; }
.kf-msg.is-cont { margin-top: -4px; }
.kf-msg.is-cont .kf-avatar { visibility: hidden; }
.kf-msg-body { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; max-width: min(78%, 420px); }
.kf-msg--own .kf-msg-body { align-items: flex-end; }
.kf-msg-name { margin: 0 0 3px 4px; font-size: var(--fs-xs); color: var(--text-muted); }
.kf-sys { max-width: 88%; padding: 2px 10px; font-size: var(--fs-xs); line-height: 1.5; text-align: center; color: var(--bubble-system-text); overflow-wrap: anywhere; }

.kf-bubble {
  position: relative; max-width: 100%; padding: 9px 13px; border-radius: var(--r-bubble);
  font-size: var(--fs-chat); line-height: var(--lh); white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
}
.kf-msg--other .kf-bubble { background: var(--bubble-other-bg); color: var(--bubble-other-text); border: 1px solid var(--bubble-other-border); border-bottom-left-radius: var(--r-bubble-tail); box-shadow: var(--shadow-sm); }
.kf-msg--own .kf-bubble { background: var(--bubble-own-bg); color: var(--bubble-own-text); border-bottom-right-radius: var(--r-bubble-tail); }
.kf-bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.kf-bubble--media { padding: 0; overflow: hidden; white-space: normal; }
.kf-msg--other .kf-bubble--media.kf-bubble--bare { background: transparent; border: 0; box-shadow: none; }
.kf-msg--own .kf-bubble--media.kf-bubble--bare { background: transparent; }
.kf-msg.is-pending .kf-bubble { opacity: .78; }
.kf-msg.is-failed .kf-bubble { opacity: .9; }

.kf-msg-meta { display: flex; align-items: center; gap: 4px; margin-top: 3px; padding: 0 4px; font-size: var(--fs-xs); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.kf-msg-state { display: inline-flex; align-items: center; gap: 2px; }
.kf-msg-state svg { width: 14px; height: 14px; }
.kf-msg-state--read { color: var(--brand-600); }
.kf-msg-state--failed { color: var(--danger); }
.kf-link-btn { padding: 0; border: 0; background: none; color: var(--brand-600); font-size: inherit; text-decoration: underline; text-underline-offset: 2px; }
.kf-link-btn--danger { color: var(--danger); }

/* ---------- 图片 / 视频 ---------- */
.kf-img { position: relative; display: block; max-width: min(240px, 100%); padding: 0; border: 0; border-radius: inherit; background: var(--bg-sunken); cursor: zoom-in; overflow: hidden; }
.kf-img img { display: block; width: 100%; max-width: 240px; max-height: 320px; height: auto; object-fit: cover; }
.kf-img.is-broken { width: 160px; height: 100px; display: grid; place-items: center; color: var(--text-muted); font-size: var(--fs-xs); cursor: default; }
.kf-video { display: block; width: min(280px, 100%); max-height: 320px; border-radius: inherit; background: var(--text); outline: none; }
.kf-progress { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; border-radius: inherit; background: rgba(28, 25, 23, .45); color: var(--text-inverse); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.kf-progress-bar { position: absolute; left: 0; bottom: 0; height: 3px; width: var(--p, 0%); background: var(--brand-200); transition: width var(--dur-fast) linear; }

/* ---------- 语音气泡（自定义播放器） ---------- */
.kf-audio { display: flex; align-items: center; gap: var(--sp-2); width: 100%; min-width: 150px; padding: 8px 12px 8px 8px; }
.kf-audio-btn { flex: 0 0 auto; width: 32px; height: 32px; border: 0; border-radius: 50%; display: grid; place-items: center; padding: 0; background: var(--brand-50); color: var(--brand-600); transition: background var(--dur-fast) var(--ease); }
.kf-audio-btn:hover { background: var(--brand-100); }
.kf-audio-btn svg { width: 16px; height: 16px; }
.kf-audio-btn .i-pause, .kf-audio.is-playing .kf-audio-btn .i-play { display: none; }
.kf-audio.is-playing .kf-audio-btn .i-pause { display: block; }
.kf-msg--own .kf-audio-btn { background: rgba(255, 255, 255, .18); color: var(--text-inverse); }
.kf-msg--own .kf-audio-btn:hover { background: rgba(255, 255, 255, .28); }
.kf-audio-bars { flex: 1 1 auto; display: flex; align-items: center; gap: 2px; height: 24px; min-width: 0; color: var(--brand-600); }
.kf-msg--own .kf-audio-bars { color: var(--text-inverse); }
.kf-audio-bars i { flex: 1 1 0; min-width: 2px; height: var(--h, 40%); border-radius: 1px; background: currentColor; opacity: .3; transition: opacity var(--dur-fast) var(--ease); }
.kf-audio-bars i.on { opacity: 1; }
.kf-audio-dur { flex: 0 0 auto; min-width: 30px; text-align: right; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.kf-audio.is-error .kf-audio-bars { opacity: .4; }

/* ---------- 文件卡片 ---------- */
.kf-file { display: flex; align-items: center; gap: 10px; width: 100%; min-width: 200px; padding: 10px 12px; color: inherit; text-decoration: none; }
.kf-file:hover .kf-file-dl { opacity: 1; }
.kf-file-icon { flex: 0 0 auto; width: 36px; height: 36px; display: grid; place-items: center; border-radius: var(--r-sm); background: var(--brand-50); color: var(--brand-600); }
.kf-msg--own .kf-file-icon { background: rgba(255, 255, 255, .18); color: var(--text-inverse); }
.kf-file-info { flex: 1 1 auto; min-width: 0; }
.kf-file-name { font-size: var(--fs-md); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kf-file-size { margin-top: 2px; font-size: var(--fs-xs); opacity: .75; font-variant-numeric: tabular-nums; }
.kf-file-dl { flex: 0 0 auto; width: 20px; height: 20px; opacity: .7; transition: opacity var(--dur-fast) var(--ease); }

/* ---------- 日期分隔 / 加载更多 ---------- */
.kf-day { display: flex; justify-content: center; margin: var(--sp-2) 0 var(--sp-1); }
.kf-day span { padding: 2px 10px; border-radius: var(--r-full); background: var(--bg-sunken); font-size: var(--fs-xs); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.kf-loadmore { display: flex; justify-content: center; padding: var(--sp-1) 0 var(--sp-3); }
.kf-spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--brand-600); border-radius: 50%; animation: kf-spin .8s linear infinite; }
.kf-spinner--sm { width: 14px; height: 14px; border-width: 2px; }

/* ---------- 输入中 ---------- */
.kf-typing { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2) 0 0 36px; font-size: var(--fs-xs); color: var(--text-muted); animation: kf-in var(--dur-base) var(--ease); }
.kf-typing-dots { display: inline-flex; gap: 3px; padding: 9px 10px; border-radius: var(--r-bubble); border-bottom-left-radius: var(--r-bubble-tail); background: var(--surface); border: 1px solid var(--border); }
.kf-typing-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); animation: kf-dot 1.2s infinite; }
.kf-typing-dots i:nth-child(2) { animation-delay: .15s; }
.kf-typing-dots i:nth-child(3) { animation-delay: .3s; }

/* ---------- 横幅 / 新消息提示 ---------- */
.kf-banner { position: absolute; top: 0; left: 0; right: 0; z-index: 5; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 6px 12px; background: var(--accent-soft); color: var(--text-secondary); font-size: var(--fs-xs); text-align: center; animation: kf-in var(--dur-base) var(--ease); }
.kf-banner::before { content: ""; width: 12px; height: 12px; border: 2px solid rgba(249, 115, 22, .35); border-top-color: var(--accent); border-radius: 50%; animation: kf-spin .9s linear infinite; }
.kf-banner.is-offline::before { display: none; }
.kf-newmsg { position: absolute; left: 50%; bottom: 12px; z-index: 5; transform: translateX(-50%); height: 32px; padding: 0 14px; border: 1px solid var(--border); border-radius: var(--r-full); background: var(--surface); color: var(--brand-600); font-size: var(--fs-sm); font-weight: 500; box-shadow: var(--shadow-md); animation: kf-in var(--dur-base) var(--ease); }
.kf-newmsg:hover { background: var(--surface-hover); }

/* ---------- 弹层 / 表单 ---------- */
.kf-modal { position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: var(--sp-4); background: rgba(28, 25, 23, .4); animation: kf-fade var(--dur-base) var(--ease); }
.kf-modal-card { width: 100%; max-width: 320px; padding: var(--sp-5); border-radius: var(--r-card); background: var(--surface); box-shadow: var(--shadow-md); animation: kf-in var(--dur-base) var(--ease); }
.kf-modal-title { font-size: var(--fs-xl); font-weight: 600; line-height: 1.3; }
.kf-modal-desc { margin-top: var(--sp-1); font-size: var(--fs-sm); color: var(--text-secondary); }
.kf-modal-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-4); }
.kf-field { display: block; width: 100%; height: var(--h-control); margin-top: var(--sp-4); padding: 0 var(--sp-3); border: 1px solid var(--border-strong); border-radius: var(--r-btn); background: var(--surface); font-size: var(--fs-chat); color: var(--text); transition: border-color var(--dur-fast) var(--ease); }
.kf-field:focus { border-color: var(--brand-500); outline: none; box-shadow: var(--focus-ring); }
.kf-field::placeholder { color: var(--text-muted); }

/* ---------- 灯箱 ---------- */
.kf-lightbox { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: var(--sp-4); background: rgba(28, 25, 23, .92); cursor: zoom-out; animation: kf-fade var(--dur-base) var(--ease); }
.kf-lightbox-img { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; border-radius: var(--r-sm); cursor: default; }
.kf-lightbox-close { position: absolute; top: calc(8px + env(safe-area-inset-top, 0px)); right: 8px; color: var(--text-inverse); }
.kf-lightbox-close:hover { background: rgba(255, 255, 255, .15); color: var(--text-inverse); }

/* ---------- 提示条 / 致命错误 ---------- */
.kf-toast { position: absolute; left: 50%; bottom: 84px; z-index: 40; transform: translateX(-50%); max-width: calc(100% - 32px); padding: 8px 14px; border-radius: var(--r-btn); background: var(--text); color: var(--text-inverse); font-size: var(--fs-sm); text-align: center; box-shadow: var(--shadow-md); animation: kf-in var(--dur-base) var(--ease); }
.kf-fatal { position: absolute; inset: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-1); padding: var(--sp-6); background: var(--bg); text-align: center; }
.kf-fatal .kf-btn { margin-top: var(--sp-3); }

/* ---------- 录音：底部录音条（桌面）与按住说话遮罩（移动端） ---------- */
.kf-rec-bar { display: flex; align-items: center; gap: var(--sp-2); min-height: var(--h-icon-btn); padding: 0 4px; animation: kf-in var(--dur-base) var(--ease); }
.kf-rec-dot { position: relative; flex: 0 0 auto; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.kf-rec-dot::after { content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 2px solid var(--accent); animation: kf-breathe 1.6s var(--ease) infinite; }
.kf-rec-time { flex: 0 0 auto; min-width: 38px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text); }
.kf-rec-hint { flex: 1 1 auto; min-width: 0; font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kf-rec-bar .kf-btn { height: 36px; padding: 0 12px; }
.kf-rec-overlay { position: absolute; inset: 0; z-index: 35; display: flex; align-items: center; justify-content: center; background: rgba(247, 247, 245, .94); touch-action: none; }
.kf-rec-card { text-align: center; }
.kf-rec-pulse { position: relative; width: 72px; height: 72px; margin: 0 auto var(--sp-4); border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--text-inverse); transition: background var(--dur-fast) var(--ease); }
.kf-rec-pulse::before { content: ""; position: absolute; inset: -10px; border-radius: 50%; border: 3px solid var(--accent); animation: kf-breathe 1.6s var(--ease) infinite; }
.kf-rec-pulse svg { width: 30px; height: 30px; }
.kf-rec-overlay.is-cancel .kf-rec-pulse { background: var(--text-muted); }
.kf-rec-overlay.is-cancel .kf-rec-pulse::before { display: none; }
.kf-rec-time--lg { font-size: var(--fs-2xl); }
.kf-rec-overlay-hint { margin-top: var(--sp-2); font-size: var(--fs-md); color: var(--text-secondary); }
.kf-rec-overlay.is-cancel .kf-rec-overlay-hint { color: var(--danger); }

/* ---------- 动效 ---------- */
@keyframes kf-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes kf-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes kf-spin { to { transform: rotate(360deg); } }
@keyframes kf-breathe { 0% { transform: scale(.75); opacity: .8; } 100% { transform: scale(1.25); opacity: 0; } }
@keyframes kf-pulse { from { opacity: .55; } to { opacity: 1; } }
@keyframes kf-dot { 0%, 80%, 100% { opacity: .35; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }
