/* v6.76: Global floating chat ball — theme-aware redesign + friend group chats.
   面板自带 --cfab-* 局部令牌: 亮色默认 + body.dark-mode 覆写;
   文字/表面/强调色一律走站点语义令牌 (--ink-1/--ink-2/--surface-2/--line-1/--accent),
   保证两套主题下所有元素对比度达标 (正文 ≥4.5:1)。 */

/* ── Panel-scoped tokens ── */
.chat-fab-wrap {
    --cfab-panel: rgba(255, 255, 255, 0.94);
    --cfab-border: rgba(15, 23, 42, 0.08);
    --cfab-shadow: 0 24px 64px rgba(15, 23, 42, 0.16), 0 6px 20px rgba(15, 23, 42, 0.10);
    --cfab-hover: rgba(15, 23, 42, 0.05);
    --cfab-press: rgba(15, 23, 42, 0.09);
    --cfab-field-bg: rgba(15, 23, 42, 0.04);
    --cfab-field-border: rgba(15, 23, 42, 0.10);
    --cfab-icon-hover: rgba(15, 23, 42, 0.07);
    --cfab-focus-ring: rgba(47, 107, 255, 0.15);
    --cfab-ph-bg: linear-gradient(135deg, #e2e8f0, #cbd5e1);
    --cfab-ph-ink: #64748b;
    --cfab-group-bg: rgba(47, 107, 255, 0.07);
    /* 质押仲裁入口: 与 escrow.css 的「待确认」徽标同色系 (亮 #92400e on rgba(217,119,6,.13) ≥6:1) */
    --cfab-esc-bg: rgba(217, 119, 6, 0.13);
    --cfab-esc-ink: #92400e;
    --cfab-scroll: rgba(15, 23, 42, 0.18);
    /* 三级文字 (时间戳/摘要/占位): 亮色 #475569 on #fff/#EDEFF3 ≥6.5:1 */
    --cfab-time: #475569;
    /* 发送气泡: 双端点对白字均 ≥4.9:1, 亮/暗主题通用 */
    --cfab-sent-bg: linear-gradient(135deg, #2563eb, #4338ca);

    position: fixed;
    right: 18px;
    bottom: 90px;
    z-index: 998;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    touch-action: none;
    font-family: var(--font-sans, 'Inter', -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif);
}

body.dark-mode .chat-fab-wrap {
    --cfab-panel: rgba(15, 23, 42, 0.92);
    --cfab-border: rgba(255, 255, 255, 0.10);
    --cfab-shadow: 0 24px 64px rgba(0, 0, 0, 0.50), 0 6px 20px rgba(0, 0, 0, 0.35);
    --cfab-hover: rgba(255, 255, 255, 0.06);
    --cfab-press: rgba(255, 255, 255, 0.10);
    --cfab-field-bg: rgba(255, 255, 255, 0.06);
    --cfab-field-border: rgba(255, 255, 255, 0.10);
    --cfab-icon-hover: rgba(255, 255, 255, 0.08);
    --cfab-focus-ring: rgba(79, 124, 255, 0.20);
    --cfab-ph-bg: linear-gradient(135deg, #1e293b, #334155);
    --cfab-ph-ink: #94a3b8;
    --cfab-group-bg: rgba(79, 124, 255, 0.10);
    --cfab-esc-bg: rgba(245, 158, 11, 0.16);
    --cfab-esc-ink: #fbbf24;
    --cfab-scroll: rgba(255, 255, 255, 0.16);
    --cfab-time: #94a3b8;
}

.chat-fab-wrap.dragging { cursor: grabbing; }

/* ── FAB Button ── */
.chat-fab-btn {
    width: 52px; height: 52px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, var(--accent, #2f6bff), #6366f1);
    box-shadow: 0 4px 20px rgba(47, 107, 255, 0.35), 0 2px 8px rgba(0, 0, 0, 0.20);
    display: flex; align-items: center; justify-content: center;
    position: relative;
    transition: transform var(--dur-fast, 120ms) var(--ease-out, ease),
                box-shadow 0.2s var(--ease-out, ease);
    overflow: hidden;
    padding: 0;
}
.chat-fab-btn:hover {
    transform: scale(1.06);
    box-shadow: 0 6px 28px rgba(47, 107, 255, 0.45), 0 3px 10px rgba(0, 0, 0, 0.25);
}
.chat-fab-btn:active { transform: scale(0.94); }
.chat-fab-btn svg.chat-fab-icon { width: 22px; height: 22px; fill: #fff; }

.chat-fab-avatar {
    width: 100%; height: 100%;
    border-radius: 50%;
    object-fit: cover;
    position: absolute;
    top: 0; left: 0;
    border: 2px solid rgba(255, 255, 255, 0.25);
}

/* ── Badge ── */
.chat-fab-badge {
    position: absolute; top: -3px; right: -4px;
    min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: 999px;
    background: #dc2626;
    color: #fff; font-size: 10px; font-weight: 700;
    display: none; align-items: center; justify-content: center;
    box-shadow: 0 0 0 2px var(--card-light, #fff);
    animation: cfabBadgePulse 2s infinite;
    letter-spacing: 0;
}
@keyframes cfabBadgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.12); }
}

/* 质押待办红点: 球体本身被 overflow:hidden 裁切, 故挂在 wrap 的右下角
   (按钮是最后一个 flex-end 子元素, 面板开合时该角始终与球体重合)
   双层选择器用于压过 escrow.css 的 .esc-entry-dot { top/right } 定位 */
.chat-fab-wrap .chat-fab-escrow-dot {
    top: auto; bottom: 0; right: 0;
    box-shadow: 0 0 0 2px var(--card-light, #fff);
}
.chat-fab-wrap.open .chat-fab-escrow-dot { display: none; }

/* ── Panel Container ── */
.chat-fab-panel {
    display: none;
    width: min(340px, calc(100vw - 32px));
    height: 520px;
    max-height: calc(100dvh - 130px);
    border-radius: var(--radius-lg, 14px);
    background: var(--cfab-panel);
    backdrop-filter: saturate(150%) blur(24px);
    -webkit-backdrop-filter: saturate(150%) blur(24px);
    border: 1px solid var(--cfab-border);
    box-shadow: var(--cfab-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
    flex-direction: column;
    overflow: hidden;
    position: relative;
}
.chat-fab-wrap.open .chat-fab-panel {
    display: flex;
    animation: cfabPanelIn 0.25s var(--ease-out, ease);
}
@keyframes cfabPanelIn {
    from { opacity: 0; transform: translateY(12px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Views Container (holds list + chat views) ── */
.cfab-views {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

/* ── List View ── */
.cfab-view-list {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.cfab-view-list.hidden { display: none; }

/* ── Chat View ── */
.cfab-view-chat {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    background: var(--cfab-panel);
    z-index: 2;
}
.cfab-view-chat.active {
    display: flex;
    animation: cfabSlideIn 0.25s var(--ease-out, ease);
}
@keyframes cfabSlideIn {
    from { transform: translateX(20px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ── Header (shared) ── */
.cfab-header {
    display: flex; align-items: center; gap: var(--sp-3, 12px);
    padding: var(--sp-3, 12px) var(--sp-4, 16px);
    border-bottom: 1px solid var(--border-light, rgba(0, 0, 0, 0.06));
    flex-shrink: 0;
    min-height: 52px;
}
.cfab-header-title {
    font-size: var(--text-md, 14px);
    font-weight: 600;
    color: var(--text-main, #0f172a);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Header icon buttons (back / close) */
.cfab-back-btn,
.cfab-close-btn {
    background: none; border: none;
    color: var(--text-muted, #64748b);
    width: 32px; height: 32px; border-radius: var(--radius-sm, 6px);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
    padding: 0;
}
.cfab-back-btn:hover,
.cfab-close-btn:hover { background: var(--cfab-icon-hover); color: var(--text-main, #0f172a); }
.cfab-back-btn svg { width: 18px; height: 18px; }
.cfab-close-btn svg { width: 16px; height: 16px; }

/* Chat header peer avatar */
.cfab-peer-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    object-fit: cover; flex-shrink: 0;
    border: 1px solid var(--cfab-border);
}
.cfab-peer-avatar-ph {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--cfab-ph-bg);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.cfab-peer-avatar-ph svg { width: 16px; height: 16px; fill: var(--cfab-ph-ink); }

/* ── Friend List ── */
.cfab-list {
    flex: 1; overflow-y: auto;
    padding: var(--sp-2, 8px);
    display: flex; flex-direction: column;
    gap: 2px;
}
.cfab-list::-webkit-scrollbar { width: 3px; }
.cfab-list::-webkit-scrollbar-track { background: transparent; }
.cfab-list::-webkit-scrollbar-thumb { background: var(--cfab-scroll); border-radius: 3px; }

/* ── List Item ── */
.cfab-item {
    display: flex; align-items: center; gap: var(--sp-3, 12px);
    padding: 10px var(--sp-3, 12px);
    border-radius: var(--radius-md, 10px);
    cursor: pointer;
    transition: background 0.12s;
    position: relative;
}
.cfab-item:hover { background: var(--cfab-hover); }
.cfab-item:active { background: var(--cfab-press); }

/* Avatar */
.cfab-item-av {
    width: 40px; height: 40px; border-radius: 50%;
    object-fit: cover; flex-shrink: 0;
    border: 1px solid var(--cfab-border);
}
.cfab-item-av-ph {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--cfab-ph-bg);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    border: 1px solid var(--cfab-border);
}
.cfab-item-av-ph svg { width: 20px; height: 20px; fill: var(--cfab-ph-ink); }

/* Info block */
.cfab-item-info {
    flex: 1; overflow: hidden;
    display: flex; flex-direction: column; gap: 3px;
}
.cfab-item-name {
    font-size: var(--text-md, 14px);
    font-weight: 600;
    color: var(--text-main, #0f172a);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    line-height: 1.3;
}
.cfab-item-last {
    font-size: var(--text-sm, 12.5px);
    color: var(--cfab-time);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    line-height: 1.3;
}

/* Unread dot */
.cfab-item-unread {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--accent, #2f6bff);
    flex-shrink: 0;
    box-shadow: 0 0 6px rgba(47, 107, 255, 0.45);
}

/* ── Group Entry ── */
.cfab-item.cfab-group {
    background: var(--cfab-group-bg);
    border: 1px solid var(--cfab-border);
    margin-bottom: var(--sp-1, 4px);
}
.cfab-item.cfab-group:hover { background: var(--cfab-group-bg); filter: brightness(0.97); }
body.dark-mode .cfab-item.cfab-group:hover { filter: brightness(1.2); }
.cfab-group-icon {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--cfab-group-bg);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    border: 1px solid var(--cfab-border);
}
.cfab-group-icon svg { width: 20px; height: 20px; fill: var(--accent, #2f6bff); }
.cfab-group-count {
    font-size: var(--text-sm, 12.5px);
    color: var(--accent, #2f6bff);
    font-weight: 500;
}

/* 置顶的质押仲裁入口: 与聊天条目区分开 (分隔线 + 琥珀底图标) */
.cfab-item.cfab-escrow-entry {
    margin-bottom: 6px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--cfab-border);
    border-radius: 0;
}
.cfab-escrow-icon {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--cfab-esc-bg);
    color: var(--cfab-esc-ink);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.cfab-escrow-icon svg { width: 20px; height: 20px; fill: currentColor; }

/* ── Messages Area ── */
.cfab-messages {
    flex: 1; overflow-y: auto;
    padding: var(--sp-3, 12px) var(--sp-4, 16px);
    display: flex; flex-direction: column;
    gap: 6px;
}
.cfab-messages::-webkit-scrollbar { width: 3px; }
.cfab-messages::-webkit-scrollbar-track { background: transparent; }
.cfab-messages::-webkit-scrollbar-thumb { background: var(--cfab-scroll); border-radius: 3px; }

/* ── Message Bubbles ── */
.cfab-bubble {
    max-width: 78%;
    padding: 8px 14px;
    font-size: var(--text-md, 14px);
    line-height: 1.45;
    word-break: break-word;
    position: relative;
    animation: cfabBubbleIn 0.18s var(--ease-out, ease);
}
@keyframes cfabBubbleIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}
.cfab-bubble.sent {
    align-self: flex-end;
    background: var(--cfab-sent-bg);
    border: none;
    color: #fff;
    border-radius: 16px 16px 4px 16px;
}
.cfab-bubble.received {
    align-self: flex-start;
    background: var(--surface-2, #edeff3);
    border: 1px solid var(--border-light, rgba(0, 0, 0, 0.06));
    color: var(--text-main, #0f172a);
    border-radius: 16px 16px 16px 4px;
}
.cfab-bubble-sender {
    font-size: var(--text-xs, 11px);
    color: var(--accent, #2f6bff);
    font-weight: 600;
    margin-bottom: 2px;
    letter-spacing: 0.02em;
}
.cfab-bubble-time {
    font-size: var(--text-xs, 11px);
    color: var(--cfab-time);
    margin-top: 3px;
    text-align: right;
}
.cfab-bubble.sent .cfab-bubble-time { color: rgba(255, 255, 255, 0.92); }

/* ── Empty State ── */
.cfab-empty {
    text-align: center;
    color: var(--cfab-time);
    font-size: var(--text-sm, 12.5px);
    padding: 48px 24px;
    line-height: 1.5;
}

/* ── Input Area ── */
.cfab-input-row {
    display: flex; align-items: center; gap: var(--sp-2, 8px);
    padding: var(--sp-2, 8px) var(--sp-3, 12px);
    border-top: 1px solid var(--border-light, rgba(0, 0, 0, 0.06));
    flex-shrink: 0;
}
.cfab-input {
    flex: 1;
    padding: 9px 14px;
    border-radius: 999px;
    background: var(--cfab-field-bg);
    border: 1px solid var(--cfab-field-border);
    color: var(--text-main, #0f172a);
    font-size: var(--text-sm, 12.5px);
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.cfab-input:focus {
    border-color: var(--accent, #2f6bff);
    box-shadow: 0 0 0 3px var(--cfab-focus-ring);
}
.cfab-input::placeholder { color: var(--cfab-time); }

/* Send button — icon only */
.cfab-send-btn {
    width: 36px; height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--cfab-sent-bg);
    color: #fff;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: opacity 0.15s, transform 0.12s;
    flex-shrink: 0;
    padding: 0;
}
.cfab-send-btn:hover { opacity: 0.88; transform: scale(1.05); }
.cfab-send-btn:active { transform: scale(0.92); }
.cfab-send-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }
.cfab-send-btn svg { width: 16px; height: 16px; fill: #fff; }

/* ── v6.76: Create-Group View ── */
.cfab-view-create {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    background: var(--cfab-panel);
    z-index: 3;
}
.cfab-view-create.active {
    display: flex;
    animation: cfabSlideIn 0.25s var(--ease-out, ease);
}
.cfab-create-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--sp-3, 12px) var(--sp-4, 16px);
    display: flex;
    flex-direction: column;
    gap: var(--sp-3, 12px);
}
.cfab-create-name {
    width: 100%;
    border-radius: var(--radius-md, 10px);
    flex: none;
}
.cfab-create-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
/* Friend pick row — reuse .cfab-item layout, add a leading checkbox */
.cfab-item.cfab-pick { cursor: pointer; }
.cfab-pick-cb {
    width: 18px; height: 18px;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: var(--accent, #2f6bff);
    margin: 0;
}
.cfab-create-footer {
    padding: var(--sp-2, 8px) var(--sp-3, 12px) var(--sp-3, 12px);
    border-top: 1px solid var(--border-light, rgba(0, 0, 0, 0.06));
    flex-shrink: 0;
}
.cfab-create-btn {
    width: 100%;
    padding: 11px 16px;
    border: none;
    border-radius: 999px;
    background: var(--cfab-sent-bg);
    color: #fff;
    font-size: var(--text-md, 14px);
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.12s;
}
.cfab-create-btn:hover { opacity: 0.9; }
.cfab-create-btn:active { transform: scale(0.985); }
.cfab-create-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ── v6.76: Private chat-group rows ── */
.cfab-item.cfab-chat-group { margin-bottom: 2px; }
.cfab-item.cfab-chat-group .cfab-group-icon { background: var(--cfab-group-bg); }
.cfab-item.cfab-chat-group .cfab-group-icon svg { fill: var(--accent, #2f6bff); }
