/* ============================================================
 * 全站浮动聊天组件 chat-widget.css
 * 所有样式以 #cbw- 前缀隔离，避免污染宿主页面
 * ============================================================ */

/* ===== 浮动按钮（窗口右缘中部） ===== */
#cbw-fab {
    position: fixed; right: 0; top: 50%; transform: translateY(-50%);
    width: 54px; height: 58px; border: none; cursor: pointer;
    border-radius: 16px 0 0 16px; background: #4F46E5; color: #fff;
    font-size: 24px; line-height: 1; z-index: 99990;
    box-shadow: -4px 4px 14px rgba(79, 70, 229, .35);
    display: flex; align-items: center; justify-content: center;
    transition: background .15s, padding .15s;
}
#cbw-fab:hover { background: #4338CA; padding-right: 4px; }
#cbw-fab-badge {
    position: absolute; top: -6px; left: -6px;
    min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
    background: #EF4444; color: #fff; font-size: .72rem; font-weight: 700;
    display: none; align-items: center; justify-content: center;
    box-shadow: 0 2px 6px rgba(239, 68, 68, .5);
}

/* ===== 滑出面板 ===== */
#cbw-panel {
    position: fixed; top: 0; right: 0; height: 100vh; height: 100dvh;
    width: 390px; max-width: 94vw; background: #fff; z-index: 99991;
    box-shadow: -8px 0 30px rgba(0, 0, 0, .18);
    transform: translateX(105%); transition: transform .28s ease;
    display: flex; flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    color: #18181b; text-align: left;
}
#cbw-panel.open { transform: translateX(0); }

/* 面板头部 */
#cbw-head {
    padding: 14px 16px; border-bottom: 1px solid #f0f0f1;
    display: flex; align-items: center; gap: 8px; flex: none;
}
#cbw-head .cbw-title { font-weight: 700; font-size: 1.02rem; flex: 1; }
#cbw-dot {
    width: 9px; height: 9px; border-radius: 50%; background: #D4D4D8; display: inline-block; flex: none;
}
#cbw-dot.on { background: #22C55E; box-shadow: 0 0 6px rgba(34, 197, 94, .7); }
#cbw-close {
    border: none; background: #F4F4F5; color: #71717a; width: 28px; height: 28px;
    border-radius: 50%; cursor: pointer; font-size: 14px; line-height: 1; flex: none;
}
#cbw-close:hover { background: #E4E4E7; color: #18181b; }

/* Tab 栏 */
#cbw-tabs {
    display: flex; border-bottom: 1px solid #f0f0f1; flex: none;
}
#cbw-tabs button {
    flex: 1; border: none; background: none; padding: 10px 4px; cursor: pointer;
    font-size: .86rem; font-weight: 600; color: #71717a;
    border-bottom: 2px solid transparent; position: relative;
}
#cbw-tabs button.active { color: #4F46E5; border-bottom-color: #4F46E5; }
#cbw-tabs .cbw-tab-badge {
    position: absolute; top: 4px; right: 14%;
    min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px;
    background: #EF4444; color: #fff; font-size: .64rem; font-weight: 700;
    display: none; align-items: center; justify-content: center;
}

/* 主列表区 */
#cbw-lists { flex: 1; overflow-y: auto; padding: 12px 12px 20px; min-height: 0; }
#cbw-lists .cbw-add-row { display: flex; gap: 8px; margin-bottom: 12px; }
#cbw-lists .cbw-add-row input {
    flex: 1; height: 36px; padding: 0 12px; border: 1px solid #e4e4e7; border-radius: 10px;
    font-size: .86rem; outline: none; min-width: 0;
}
#cbw-lists .cbw-add-row input:focus { border-color: #4F46E5; }
.cbw-btn {
    padding: 7px 14px; border: none; border-radius: 10px; background: #4F46E5; color: #fff;
    font-weight: 600; font-size: .84rem; cursor: pointer; transition: opacity .15s; white-space: nowrap;
}
.cbw-btn:hover { opacity: .9; }
.cbw-btn-secondary { background: #fff; color: #71717a; border: 1px solid #e4e4e7; }
.cbw-btn-secondary:hover { border-color: #4F46E5; color: #4F46E5; opacity: 1; }
.cbw-btn-warn { background: #fff; color: #EF4444; border: 1px solid #FECACA; }
.cbw-btn-warn:hover { border-color: #EF4444; color: #EF4444; opacity: 1; }
.cbw-btn-sm { padding: 4px 10px; font-size: .76rem; border-radius: 8px; }
.cbw-title-action {
    font-size: .7rem; font-weight: 600; color: #4F46E5; background: #EEF2FF;
    border: none; border-radius: 999px; padding: 3px 10px; cursor: pointer;
}
.cbw-title-action:hover { background: #E0E7FF; }
.cbw-section {
    display: flex; justify-content: space-between; align-items: center;
    font-size: .78rem; color: #71717a; font-weight: 600; margin: 10px 2px 6px;
}
.cbw-badge {
    min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
    background: #EF4444; color: #fff; font-size: .68rem; font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center;
}
.cbw-count-chip {
    min-width: 20px; height: 20px; padding: 0 7px; border-radius: 999px;
    background: #F4F4F5; color: #71717a; font-size: .7rem; font-weight: 600;
    display: inline-flex; align-items: center; justify-content: center;
}
.cbw-item {
    display: flex; align-items: center; gap: 10px; padding: 9px 10px;
    border-radius: 10px; cursor: pointer; transition: background .12s;
}
.cbw-item:hover { background: #F4F4F5; }
.cbw-item.active { background: #EEF2FF; }
.cbw-avatar {
    width: 38px; height: 38px; border-radius: 50%; background: #4F46E5; color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .95rem; flex: none; object-fit: cover; overflow: hidden;
}
.cbw-avatar img { width: 100%; height: 100%; object-fit: cover; }
.cbw-info { flex: 1; min-width: 0; }
.cbw-name { font-size: .88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cbw-last { font-size: .76rem; color: #a1a1aa; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.cbw-req-item {
    display: flex; align-items: center; gap: 8px; padding: 9px 10px;
    border: 1px solid #EEF2FF; background: #F8FAFF; border-radius: 10px; margin-bottom: 8px;
}
.cbw-muted { color: #a1a1aa; font-size: .78rem; }
.cbw-empty { text-align: center; color: #a1a1aa; padding: 18px 6px; font-size: .82rem; }

/* ===== 聊天视图 ===== */
#cbw-chat {
    flex: 1; display: none; flex-direction: column; min-height: 0;
}
#cbw-chat.open { display: flex; }
#cbw-chat:not(.open) { display: none; }
#cbw-lists.hidden { display: none; }
#cbw-chat-head {
    padding: 10px 12px; border-bottom: 1px solid #f4f4f5;
    display: flex; align-items: center; gap: 8px; flex: none;
}
#cbw-back {
    border: none; background: #F4F4F5; color: #71717a; width: 26px; height: 26px;
    border-radius: 50%; cursor: pointer; font-size: 13px; line-height: 1; flex: none;
}
#cbw-back:hover { background: #E4E4E7; color: #18181b; }
#cbw-chat-name { font-weight: 700; font-size: .92rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#cbw-chat-actions { display: flex; gap: 6px; }
#cbw-chat-body {
    flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 9px;
    background: #FAFAFA; min-height: 0;
}
.cbw-msg-row { display: flex; gap: 6px; max-width: 84%; }
.cbw-msg-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.cbw-msg-bubble {
    padding: 8px 12px; border-radius: 13px; font-size: .86rem; line-height: 1.5;
    background: #fff; border: 1px solid #f0f0f1; word-break: break-word; white-space: pre-wrap;
}
.cbw-msg-row.mine .cbw-msg-bubble { background: #4F46E5; color: #fff; border-color: #4F46E5; }
.cbw-msg-link { color: #2563eb; text-decoration: underline; word-break: break-all; }
.cbw-msg-row.mine .cbw-msg-link { color: #fff; }
.cbw-msg-time { font-size: .64rem; color: #a1a1aa; align-self: flex-end; flex: none; }
.cbw-msg-nick { font-size: .66rem; color: #71717a; margin-bottom: 2px; }
.cbw-load-more { text-align: center; }
#cbw-chat-input {
    border-top: 1px solid #f4f4f5; padding: 10px 12px; display: flex; gap: 8px; flex: none;
}
#cbw-msg-input {
    flex: 1; resize: none; height: 42px; padding: 10px 12px; border: 1px solid #e4e4e7;
    border-radius: 10px; font-size: .86rem; font-family: inherit; outline: none; min-width: 0;
}
#cbw-msg-input:focus { border-color: #4F46E5; }

/* ===== 群创建/邀请弹窗 ===== */
#cbw-modal {
    position: fixed; inset: 0; background: rgba(24, 24, 27, .45); z-index: 99995;
    display: none; align-items: center; justify-content: center; padding: 20px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
#cbw-modal.open { display: flex; }
#cbw-modal-card {
    background: #fff; border-radius: 14px; padding: 18px 20px; width: 330px; max-width: 92vw;
    max-height: 78vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0, 0, 0, .18); color: #18181b;
}
#cbw-modal-card h3 { margin: 0 0 12px; font-size: 1rem; }
#cbw-modal-card input[type=text] {
    width: 100%; box-sizing: border-box; padding: 9px 12px; border: 1px solid #e4e4e7;
    border-radius: 10px; font-size: .88rem; outline: none; margin-bottom: 10px;
}
#cbw-modal-card input[type=text]:focus { border-color: #4F46E5; }
#cbw-pick-list { border: 1px solid #f0f0f1; border-radius: 10px; margin: 8px 0 14px; max-height: 240px; overflow-y: auto; }
.cbw-pick-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; font-size: .85rem; cursor: pointer; }
.cbw-pick-item:hover { background: #F8FAFF; }
.cbw-pick-item input { accent-color: #4F46E5; }
.cbw-modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ===== 全局 toast ===== */
#cbw-toast {
    position: fixed; top: 64px; left: 50%; transform: translateX(-50%);
    background: #18181b; color: #fff; padding: 9px 20px; border-radius: 10px;
    font-size: .84rem; z-index: 99999; display: none; max-width: 82vw;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}

/* 小屏适配 */
@media (max-width: 560px) {
    #cbw-panel { width: 100vw; max-width: 100vw; }
    #cbw-fab { width: 46px; height: 50px; font-size: 21px; }
}
