/* L'Aparté - Messenger hybride (bulle flottante + vue complète) */
/* Les variables --msg-* suivent le thème (clair ou sombre) */
:root {
    --msg-fond: var(--fond);
    --msg-carte: var(--carte);
    --msg-carte2: color-mix(in srgb, var(--fond) 60%, var(--carte));
    --msg-texte: var(--texte);
    --msg-muted: var(--muted);
    --msg-accent: var(--accent);
    --msg-accent2: var(--accent2);
    --msg-bord: var(--bord);
    --msg-err: var(--err);
    --msg-ok: var(--msg-ok-txt);
}

/* --- Bulle flottante --- */
#msg-bubble {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--msg-accent);
    color: var(--msg-fond);
    border: none;
    cursor: pointer;
    font-size: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
    z-index: 1000;
    transition: transform .2s;
}
#msg-bubble:hover { transform: scale(1.08); }
#msg-bubble .badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--msg-err);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}
#msg-bubble .badge.show { display: flex; }

/* --- Fenêtre de chat (petite) --- */
#msg-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 360px;
    height: 480px;
    max-height: calc(100vh - 120px);
    background: var(--msg-carte);
    border: 1px solid var(--msg-bord);
    border-radius: 12px;
    display: none;
    flex-direction: column;
    box-shadow: 0 8px 30px rgba(0,0,0,0.5);
    z-index: 1001;
    overflow: hidden;
}
#msg-window.open { display: flex; }
#msg-window.fullscreen {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100%; height: 100%;
    max-height: none;
    border-radius: 0;
    z-index: 1002;
}

/* --- Header fenêtre --- */
#msg-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--msg-carte2);
    border-bottom: 1px solid var(--msg-bord);
}
#msg-header .title { font-weight: 700; color: var(--msg-accent); }
#msg-header .actions { display: flex; gap: 8px; }
#msg-header button {
    background: none;
    border: 1px solid var(--msg-bord);
    color: var(--msg-texte);
    border-radius: 6px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 13px;
}
#msg-header button:hover { border-color: var(--msg-accent2); color: var(--msg-accent2); }

/* --- Liste des conversations --- */
#msg-conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
#msg-conv-list .conv-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background .15s;
}
#msg-conv-list .conv-item:hover { background: var(--msg-carte2); }
#msg-conv-list .conv-item.active { background: var(--msg-carte2); }
#msg-conv-list .conv-avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--msg-accent2);
    color: var(--msg-fond);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 18px;
    flex-shrink: 0;
}
#msg-conv-list .conv-info { flex: 1; min-width: 0; }
#msg-conv-list .conv-badge {
    margin-left: auto;
    flex-shrink: 0;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: var(--msg-err);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}
#msg-conv-list .conv-name { font-weight: 600; font-size: 14px; }
#msg-conv-list .conv-last {
    color: var(--msg-muted);
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#msg-conv-list .empty {
    color: var(--msg-muted);
    text-align: center;
    padding: 30px 10px;
    font-size: 14px;
}

/* --- Fil de messages --- */
#msg-thread {
    flex: 1;
    display: none;
    flex-direction: column;
    min-height: 0;
}
#msg-thread.open { display: flex; }
#msg-thread .thread-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--msg-carte2);
    border-bottom: 1px solid var(--msg-bord);
}
#msg-thread .thread-header .back {
    background: none; border: none; color: var(--msg-accent2);
    cursor: pointer; font-size: 18px; padding: 0 4px;
}
#msg-thread .thread-header .name { font-weight: 700; }
#msg-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.msg-bubble {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}
.msg-bubble.mine {
    align-self: flex-end;
    background: var(--msg-accent);
    color: var(--msg-fond);
    border-bottom-right-radius: 4px;
}
.msg-bubble.theirs {
    align-self: flex-start;
    background: var(--msg-carte2);
    border-bottom-left-radius: 4px;
}
.msg-bubble .meta {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 2px;
}
/* Liens dans les messages : lisibles (accent) + soulignés */
.msg-bubble a {
    color: var(--msg-accent2);
    text-decoration: underline;
    word-break: break-all;
}
.msg-bubble.mine a { color: #fff; }
.msg-bubble a:hover { opacity: 0.85; }
#msg-input-row {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid var(--msg-bord);
}
#msg-input-row input {
    flex: 1;
    padding: 8px 12px;
    background: var(--msg-fond);
    border: 1px solid var(--msg-bord);
    border-radius: 20px;
    color: var(--msg-texte);
    font-size: 14px;
}
#msg-input-row input:focus { outline: none; border-color: var(--msg-accent2); }
#msg-input-row button {
    background: var(--msg-accent);
    color: var(--msg-fond);
    border: none;
    border-radius: 20px;
    padding: 8px 16px;
    font-weight: 700;
    cursor: pointer;
}
#msg-input-row button:hover { opacity: 0.9; }

/* --- Panneau émoticônes --- */
#msg-emoji-panel {
    display: none;
    flex-wrap: wrap;
    gap: 4px;
    padding: 10px;
    border-top: 1px solid var(--msg-bord);
    background: var(--msg-fond);
    max-height: 160px;
    overflow-y: auto;
}
#msg-emoji-panel .msg-emoji {
    font-size: 22px;
    cursor: pointer;
    padding: 2px;
    border-radius: 6px;
    line-height: 1;
    transition: background 0.15s;
}
#msg-emoji-panel .msg-emoji:hover { background: var(--msg-bord); }

/* --- Nouvelle conversation --- */
#msg-new {
    display: none;
    flex-direction: column;
    padding: 12px;
    gap: 10px;
}
#msg-new.open { display: flex; }
#msg-new input, #msg-new select {
    padding: 8px 12px;
    background: var(--msg-fond);
    border: 1px solid var(--msg-bord);
    border-radius: 8px;
    color: var(--msg-texte);
    font-size: 14px;
}
#msg-new .btn-row { display: flex; gap: 8px; }
#msg-new .btn-row button { flex: 1; }
#msg-new-results {
    flex: 1;
    overflow-y: auto;
    max-height: 300px;
}
#msg-new-results .conv-item { padding: 8px; }

/* --- Responsive : messagerie plein écran sur mobile --- */
@media (max-width: 768px) {
    #msg-bubble { bottom: 12px; right: 12px; }
    #msg-window {
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        border-radius: 0;
        margin: 0;
    }
    #msg-window .msg-bubble { max-width: 85%; }
}
