/* ============================================================
   Panneau "Mes contacts" — colonne fixe à droite, pleine hauteur
   ============================================================ */
.friends-panel {
    position: fixed;
    top: 3.6rem; /* pour compenser le header de la page */
    right: 0;
    bottom: 0;
    width: 280px;
    background: #fff;
    border-left: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: width 0.2s ease;
    overflow: hidden;
}

.friends-panel.minimized {
    width: 40px;
}

.friends-panel .header {
    padding: 12px;
    border-bottom: 1px solid #eee;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Menu ⋮ : ajouter un ami + statut de présence */
.friends-menu-wrapper {
    position: relative;
}
.btn-friends-menu {
    border: none;
    background: none;
    cursor: pointer;
    font-size: 1.2em;
    line-height: 1;
    padding: 2px 6px;
}
.friends-panel.minimized .btn-friends-menu {
    display: none;
}
.friends-menu-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 1010;
    min-width: 180px;
    padding: 4px 0;
}
.friends-menu-dropdown .menu-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 12px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.9em;
    white-space: nowrap;
}
.friends-menu-dropdown .menu-item:hover {
    background: #f5f5f5;
}
.status-select-label {
    display: flex;
    align-items: center;
    gap: 6px;
}
.status-select-label select {
    flex: 1;
}

.friends-panel.minimized .header-label {
    display: none;
}

.friends-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.friends-panel.minimized .friends-panel-body {
    display: none;
}

.friend-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 4px;
    cursor: pointer;
}

.friend-info {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.friend-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    cursor: pointer; /* clic → profil */
}

.friend-name,
.friend-jid {
    cursor: pointer; /* clic → ouvrir le chat */
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status-online { background: #2ecc71; }
.status-offline { background: #bbb; }

.friend-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.friend-jid {
    font-size: 0.75em;
    color: #888;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* ============================================================
   Dock de conversations — fenêtres flottantes, grille CSS3
   ============================================================ */
.chat-dock {
    position: relative;
}

.chat-window {
    position: fixed;
    width: 328px;
    height: 582px;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
    z-index: 1001;
    overflow: hidden;

    display: grid;
    /* [AJUSTÉ] colonne "quit" élargie à 84px pour accueillir les boutons
       appel audio 📞, appel vidéo, réduire et fermer ✕. */
    grid-template-columns: 40px 1fr 84px;
    /* [AJUSTÉ] dernière ligne passée à 48px pour accueillir l'input à 48px. */
    grid-template-rows: 40px 1fr 48px;
    grid-template-areas:
        "icon   pseudo   quit"
        "chatarea chatarea chatarea"
        "smileys textmsg sendmsg";
}

.chat-window.minimized {
    height: 40px;
    grid-template-rows: 40px;
    grid-template-areas: "icon pseudo quit";
}

/* Effet de vague pendant le déplacement */
@keyframes wave-pulse {
    0%   { box-shadow: 0 2px 12px rgba(0,0,0,0.18), 0 0 0 0 rgba(243,107,33,0.5); }
    70%  { box-shadow: 0 2px 12px rgba(0,0,0,0.18), 0 0 0 16px rgba(243,107,33,0); }
    100% { box-shadow: 0 2px 12px rgba(0,0,0,0.18), 0 0 0 0 rgba(243,107,33,0); }
}
.chat-window.dragging {
    animation: wave-pulse 0.9s ease-out infinite;
    cursor: grabbing;
}
.chat-window.dragging .cw-pseudo {
    cursor: grabbing;
}

.cw-icon {
    grid-area: icon;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--orange);
}
.cw-icon img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

.cw-pseudo {
    grid-area: pseudo;
    display: flex;
    align-items: center;
    padding: 0 8px;
    background: var(--orange);
    color: var(--white);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: move;
    user-select: none;
}

/* [AJUSTÉ] flex + gap pour aligner 3 boutons (appel + réduire + fermer) côte à côte */
.cw-quit {
    grid-area: quit;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: var(--orange);
}
.cw-quit button {
    border: none;
    background: none;
    cursor: pointer;
    color: var(--white);
    font-size: 1em;
    padding: 0 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.9;
    transition: opacity 0.2s ease;
}
.cw-quit button:last-child {
    margin-right: 6px;
}
.cw-quit button:hover {
    opacity: 1;
}

.cw-chatarea {
    grid-area: chatarea;
    overflow-y: auto;
    padding: 6px 8px;
    background: var(--paper);
}

.cw-smileys {
    grid-area: smileys;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: var(--white);
    border-top: 1px solid var(--line);
}
.cw-smileys button {
    border: none;
    background: none;
    cursor: pointer;
    font-size: 1em;
    padding: 0 2px;
}

.cw-textmsg {
    grid-area: textmsg;
    display: flex;
    align-items: stretch;
    background: var(--white);
    border-top: 1px solid var(--line);
}
.cw-textmsg input {
    width: 100%;
    height: 48px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0 12px;
    background: var(--paper);
    color: var(--ink);
    font: inherit;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}
.cw-textmsg input:focus {
    outline: none;
    border-color: var(--orange);
    background: var(--white);
}

.cw-sendmsg {
    grid-area: sendmsg;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--white);
    border-top: 1px solid var(--line);
}
.cw-sendmsg button {
    border: none;
    background: none;
    cursor: pointer;
    color: var(--orange);
    font-size: 1.1em;
}
.cw-sendmsg button:hover {
    color: var(--orange-dark);
}

/* Alignement des messages : les miens à droite, ceux de l'interlocuteur
   à gauche (avec son avatar, jamais le mien). Espacement resserré par
   défaut entre messages consécutifs d'un même expéditeur (regroupés en
   un même bloc visuel) — un espace plus large est ajouté en fin de
   groupe (.block-end), quand l'expéditeur change ou en fin de fil. */
.message-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    margin-bottom: 2px;
}
.message-row.block-end {
    margin-bottom: 10px;
}
.message-row.theirs {
    justify-content: flex-start;
}
.message-row.own {
    justify-content: flex-end;
}

.message-row .message-avatar,
.message-avatar-spacer {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}
.message-row .message-avatar {
    border-radius: 50%;
    object-fit: cover;
}

.message-bubble {
    max-width: 70%;
    padding: 6px 10px;
    border-radius: 12px;
    word-break: break-word;
}
.message-row.theirs .message-bubble {
    background: var(--white);
    border: 1px solid var(--line);
    color: var(--ink);
}
.message-row.theirs.block-end .message-bubble {
    border-bottom-left-radius: 2px;
}
.message-row.own .message-bubble {
    background: var(--orange);
    color: var(--white);
}
.message-row.own.block-end .message-bubble {
    border-bottom-right-radius: 2px;
}

/* Au lieu du texte "✓✓ Lu" : petit avatar de l'interlocuteur, affiché à
   côté de MON message une fois qu'il/elle l'a lu. */
.read-avatar {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    align-self: flex-end;
}

/* En-tête de session — date/heure affichée une seule fois à l'ouverture
   de la conversation, avec une ligne 1rem dessous. */
.session-header {
    text-align: center;
    font-size: 0.75em;
    color: var(--muted);
    margin-bottom: 0.25rem;
}
.session-divider {
    height: 1rem;
    border-bottom: 1px solid var(--line);
    margin-bottom: 0.5rem;
}


/* ============================================================
   Fiche profil — popup au clic sur un avatar
   ============================================================ */
.profile-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1100;
}

.profile-modal {
    background: #fff;
    border-radius: 8px;
    padding: 24px;
    width: 260px;
    text-align: center;
    position: relative;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.profile-modal .btn-close-popup {
    position: absolute;
    top: 8px;
    right: 8px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 1em;
}

.profile-avatar {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 12px;
}

.profile-jid {
    font-size: 0.85em;
    color: #888;
    margin-bottom: 8px;
    word-break: break-all;
}

.profile-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-bottom: 16px;
}

.btn-open-chat-from-profile {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    background: #3498db;
    color: #fff;
    cursor: pointer;
}


/* ============================================================
   Appels audio/vidéo — bannière d'erreur, bannière entrante, fenêtre active
   ============================================================ */
.call-error-toast {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    border: 1px solid rgba(220, 38, 38, 0.25);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #b91c1c;
    font-size: 0.88rem;
    z-index: 1250;
}
.call-error-toast .btn-close-popup {
    border: none;
    background: none;
    cursor: pointer;
    color: inherit;
    font-size: 0.9em;
    line-height: 1;
    flex-shrink: 0;
}

.incoming-call-banner {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 1200;
}
.incoming-call-banner .call-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}
.incoming-call-info {
    display: flex;
    flex-direction: column;
    font-size: 0.85em;
    margin-right: 8px;
}
.btn-call-accept, .btn-call-decline {
    border: none;
    border-radius: 4px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 0.85em;
}
.btn-call-accept { background: #2ecc71; color: #fff; }
.btn-call-decline { background: #e74c3c; color: #fff; }

.active-call-window {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: #1c1c1c;
    color: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    width: 360px;
    z-index: 1200;
    overflow: hidden;
}
.active-call-window.dragging {
    cursor: grabbing;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.55);
}
.active-call-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    cursor: move;
    user-select: none;
}
.active-call-header .call-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}
.call-status {
    margin-left: auto;
    font-size: 0.75em;
    color: #bbb;
}
.call-video-area {
    position: relative;
    background: #000;
    height: 220px;
}
.remote-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.local-video {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 90px;
    height: 68px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.4);
}
.btn-call-hangup {
    width: 100%;
    padding: 10px;
    border: none;
    background: #e74c3c;
    color: #fff;
    cursor: pointer;
    font-size: 0.9em;
}
