/* ── Chat widget flottant ─────────────────────────────────── */
#chatWidget {
    position: fixed;
    bottom: 24px;
    right: 20px;
    z-index: 9500;
}

#chatToggleBtn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--color-accent);
    border: none;
    color: #fff;
    font-size: 1.35rem;
    cursor: pointer;
    position: relative;
    box-shadow: 0 4px 18px rgba(0,0,0,.5);
    transition: transform .2s, background .2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
#chatToggleBtn:hover { transform: scale(1.08); background: var(--color-accent-hover); }

#chatUnreadBadge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    background: #e53935;
    border-radius: 10px;
    font-size: .68rem;
    font-weight: 700;
    color: #fff;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    pointer-events: none;
}

/* ── Panneau ───────────────────────────────────────────────── */
#chatPanel {
    display: none;
    position: absolute;
    bottom: 62px;
    right: 0;
    width: 320px;
    height: 560px;
    background: var(--color-bg-card, #1b1b1b);
    border: 1px solid var(--color-border);
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0,0,0,.65);
    overflow: hidden;
    flex-direction: column;
}

#chatViewList,
#chatViewConv {
    display: none;
    flex-direction: column;
    height: 100%;
}

/* ── En-tête ───────────────────────────────────────────────── */
.chat-panel-header {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .7rem 1rem;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
    background: var(--color-bg-card, #1b1b1b);
}
.chat-panel-title {
    font-size: .85rem;
    font-weight: 600;
    color: var(--color-text, #e0e0e0);
    flex: 1;
}
.chat-close-btn, .chat-back-btn {
    background: none;
    border: none;
    color: var(--color-text-muted, #888);
    cursor: pointer;
    padding: .25rem .35rem;
    border-radius: 6px;
    font-size: .8rem;
    transition: color .15s;
    line-height: 1;
}
.chat-close-btn:hover, .chat-back-btn:hover { color: var(--color-accent); }

.chat-conv-peer {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex: 1;
    overflow: hidden;
}
.chat-peer-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 1px solid var(--color-border);
}
.chat-peer-initials {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--color-accent-muted, rgba(196,130,154,.15));
    border: 1px solid var(--color-border);
    color: var(--color-accent);
    font-size: .75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
#chatPeerName {
    font-size: .84rem;
    font-weight: 600;
    color: var(--color-text, #e0e0e0);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Liste des conversations ───────────────────────────────── */
.chat-conv-list {
    flex: 1;
    overflow-y: auto;
    padding: .35rem 0;
}
.chat-conv-item {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .6rem 1rem;
    cursor: pointer;
    transition: background .15s;
    border-bottom: 1px solid rgba(255,255,255,.04);
}
.chat-conv-item:hover { background: var(--color-accent-muted, rgba(196,130,154,.1)); }
.chat-conv-avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 1px solid var(--color-border);
}
.chat-conv-initials {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--color-accent-muted, rgba(196,130,154,.15));
    border: 1px solid var(--color-border);
    color: var(--color-accent);
    font-size: .88rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.chat-conv-info { flex: 1; overflow: hidden; }
.chat-conv-name {
    font-size: .82rem;
    font-weight: 600;
    color: var(--color-text, #e0e0e0);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-conv-preview {
    font-size: .73rem;
    color: var(--color-text-muted, #888);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-conv-meta { text-align: right; flex-shrink: 0; }
.chat-conv-time { font-size: .67rem; color: var(--color-text-muted, #888); }
.chat-conv-unread {
    min-width: 18px; height: 18px;
    background: var(--color-accent);
    border-radius: 9px;
    font-size: .65rem;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 3px;
    margin-left: auto;
    padding: 0 4px;
}

/* ── Messages ──────────────────────────────────────────────── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: .75rem;
    display: flex;
    flex-direction: column;
    gap: .4rem;
    scroll-behavior: smooth;
}
.chat-msg {
    max-width: 82%;
    padding: .45rem .75rem .3rem;
    border-radius: 12px;
    font-size: .82rem;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.chat-msg-self {
    align-self: flex-end;
    background: var(--color-accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-msg-other {
    align-self: flex-start;
    background: rgba(255,255,255,.08);
    color: var(--color-text, #e0e0e0);
    border-bottom-left-radius: 4px;
}
.chat-msg-time {
    font-size: .63rem;
    opacity: .6;
    margin-top: 2px;
    text-align: right;
}
.chat-msg-other .chat-msg-time { text-align: left; }

/* ── Saisie ────────────────────────────────────────────────── */
.chat-input-bar {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .6rem .75rem;
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
    background: var(--color-bg-card, #1b1b1b);
}
#chatInput {
    flex: 1;
    background: rgba(255,255,255,.06);
    border: 1px solid var(--color-border);
    border-radius: 20px;
    padding: .4rem .85rem;
    font-size: .82rem;
    color: var(--color-text, #e0e0e0);
    outline: none;
    transition: border-color .15s;
}
#chatInput:focus { border-color: var(--color-accent); }
#chatSendBtn {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--color-accent);
    border: none;
    color: #fff;
    font-size: .85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s, transform .15s;
}
#chatSendBtn:hover { background: var(--color-accent-hover); transform: scale(1.06); }

/* ── États vides / chargement ──────────────────────────────── */
.chat-loading, .chat-empty {
    text-align: center;
    color: var(--color-text-muted, #888);
    font-size: .8rem;
    padding: 2rem 1rem;
}
.chat-empty-conv {
    margin: auto;
    text-align: center;
    color: var(--color-text-muted, #888);
    font-size: .78rem;
    padding: 1rem;
}

/* ── Calepin notes ─────────────────────────────────────────── */
#chatPanel.notes-open {
    width: 630px;
}
#chatViewConv {
    flex-direction: column;
    height: 100%;
}
#chatViewConv > div:first-child {
    height: 100%;
}
#chatNotesPanel {
    display: none;
    width: 290px;
    flex-shrink: 0;
    border-left: 1px solid var(--color-border);
    flex-direction: column;
    background: var(--color-bg-card, #1b1b1b);
    overflow: hidden;
}
#chatPanel.notes-open #chatNotesPanel {
    display: flex;
}
.chat-notes-header {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .65rem .85rem;
    border-bottom: 1px solid var(--color-border);
    font-size: .78rem;
    font-weight: 600;
    color: var(--color-text, #e0e0e0);
    flex-shrink: 0;
    background: var(--color-bg-card, #1b1b1b);
}
.chat-notes-body {
    flex: 1;
    overflow-y: auto;
    padding: .75rem;
    display: flex;
    flex-direction: column;
    gap: .85rem;
}
.chat-notes-subscriber {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding-bottom: .75rem;
    border-bottom: 1px solid var(--color-border);
}
.chat-notes-avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 1px solid var(--color-border);
}
.chat-notes-avatar-init {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--color-accent-muted);
    color: var(--color-accent);
    font-size: .85rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.chat-notes-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: .73rem;
    padding: .2rem 0;
    border-bottom: 1px solid rgba(255,255,255,.04);
}
.chat-notes-stat-label { color: var(--color-text-muted, #888); }
.chat-notes-stat-value { font-weight: 600; color: var(--color-text, #e0e0e0); }
.chat-notes-stat-value.accent { color: var(--color-accent); }
.chat-notes-section-title {
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--color-text-muted, #888);
    margin-bottom: .3rem;
}
.chat-notes-textarea {
    width: 100%;
    background: rgba(255,255,255,.05);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: .5rem .65rem;
    font-size: .76rem;
    color: var(--color-text, #e0e0e0);
    resize: vertical;
    outline: none;
    min-height: 70px;
    line-height: 1.45;
    font-family: inherit;
    transition: border-color .15s;
}
.chat-notes-textarea:focus { border-color: var(--color-accent); }
.chat-notes-textarea.likes   { border-color: rgba(76,175,138,.35); }
.chat-notes-textarea.dislikes { border-color: rgba(229,57,53,.25); }
.chat-notes-textarea.likes:focus   { border-color: rgba(76,175,138,.7); }
.chat-notes-textarea.dislikes:focus { border-color: rgba(229,57,53,.6); }

/* ── Sidebar interlocuteurs ────────────────────────────────── */
#chatConvSidebar {
    display: none;
    width: 46px;
    flex-shrink: 0;
    border-right: 1px solid var(--color-border);
    flex-direction: column;
    overflow-y: auto;
    padding: .45rem 0;
    gap: .35rem;
    align-items: center;
    background: var(--color-bg-card, #1b1b1b);
}
#chatConvSidebar.visible { display: flex; }
.chat-sidebar-btn {
    width: 34px; height: 34px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    background: var(--color-accent-muted, rgba(196,130,154,.15));
    color: var(--color-accent);
    font-size: .75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: visible;
    transition: border-color .15s, transform .1s;
    flex-shrink: 0;
    padding: 0;
}
.chat-sidebar-btn:hover { transform: scale(1.1); }
.chat-sidebar-btn.active { border-color: var(--color-accent); }
.chat-sidebar-btn img {
    width: 30px; height: 30px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}
.chat-sidebar-badge {
    position: absolute;
    top: -2px; right: -2px;
    min-width: 13px; height: 13px;
    background: #e53935;
    border-radius: 7px;
    font-size: .52rem;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid var(--color-bg-card, #1b1b1b);
    padding: 0 2px;
    pointer-events: none;
}
#chatConvSidebar::-webkit-scrollbar { width: 2px; }
#chatConvSidebar::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 1px; }

/* ── Scrollbar fine ────────────────────────────────────────── */
.chat-conv-list::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-conv-list::-webkit-scrollbar-track,
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-conv-list::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 2px; }
