/* ═══════════════════════════════════════════════════════════════════
   plugins/v0x_messager/public/css/chat.css
   Version unifiée & responsive — mobile / tablette / desktop
   ═══════════════════════════════════════════════════════════════════ */

/* ─── CONTENEUR PRINCIPAL ─────────────────────────────────────────── */
#chat-container {
    display: flex;
    height: calc(100vh - var(--header-height, 56px) - 2rem);
    height: calc(100dvh - var(--header-height, 56px) - 2rem); /* navigateurs modernes — corrige le bug barre d'adresse mobile */
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--bg-surface);
}

/* ─── SIDEBAR (liste conversations) ───────────────────────────────── */
#conv-sidebar {
    width: 300px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
}

#conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.conv-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    margin: 2px 6px;
    cursor: pointer;
    border-radius: 12px;
    transition: background 0.15s;
    position: relative;
}
.conv-item:hover  { background: var(--green-ghost, rgba(0,255,0,0.06)); }
.conv-item.active { background: var(--green-ghost, rgba(0,255,0,0.12)); }

.conv-avatar-wrap {
    position: relative;
    flex-shrink: 0;
    width: 44px;
    height: 44px;
}
.conv-avatar-wrap .avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--green-dim, #2a8a2a);
}
.conv-avatar-wrap .online-dot,
.conv-avatar-wrap .offline-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--bg-card, #000);
}
.online-dot  { background: #4ade80; }
.offline-dot { background: #666; }

.conv-info {
    flex: 1;
    min-width: 0;
}
.conv-name {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}
.conv-preview {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conv-badge {
    background: var(--green-bright, #0f0);
    color: #000;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    flex-shrink: 0;
}

/* ─── FENÊTRE CHAT ─────────────────────────────────────────────────── */
#chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    min-width: 0;
    overflow-x: hidden;
}

#chat-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(0,8,0,0.5);
    min-height: 60px;
}

#chat-back {
    display: none;
    background: none;
    border: none;
    color: var(--green-bright, #0f0);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}
#chat-back:hover { background: var(--green-ghost); }

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* ─── BULLES DE MESSAGES ──────────────────────────────────────────── */
.msg-bubble {
    max-width: 70%;
    display: flex;
    flex-direction: column;
    position: relative;
    margin: 2px 0;
}
.msg-bubble.sent     { align-self: flex-end;   }
.msg-bubble.received { align-self: flex-start; }

/* Bulle contenant un média : largeur compacte + sans fond */
.msg-bubble.has-media {
    max-width: 320px;
}
.msg-bubble.has-media .msg-content {
    background: none !important;
    padding: 0 !important;
    border-radius: 12px;
    overflow: hidden;
}

.msg-content {
    padding: 9px 14px;
    border-radius: 18px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.4;
    word-break: break-word;
}
.msg-bubble.received .msg-content {
    background: #2a2a2a;
    color: #eee;
    border-bottom-left-radius: 4px;
}
.msg-bubble.sent .msg-content {
    background: linear-gradient(135deg, #0f7a0f, #0aa00a);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.msg-bubble.sending .msg-content { opacity: 0.6; }

/* ─── MÉTADONNÉES ──────────────────────────────────────────────────── */
.msg-meta {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-muted);
    padding: 2px 8px;
    opacity: 0.75;
    display: flex;
    align-items: center;
    gap: 4px;
}
.msg-bubble.sent .msg-meta     { align-self: flex-end;   }
.msg-bubble.received .msg-meta { align-self: flex-start; }

.sig-ok   { color: #4ade80; margin-left: 4px; }
.sig-fail { color: #f87171; margin-left: 4px; }

/* ─── FICHIERS / MÉDIAS — ASPECT RATIO PRÉSERVÉ ───────────────────── */
.msg-file {
    display: block;
    width: 100%;
    max-width: 300px;
    border-radius: 12px;
    overflow: hidden;
}
.msg-file img,
.msg-file video {
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: 360px;
    object-fit: contain;
    border-radius: 12px;
    display: block;
    background: #000;
}
.msg-file img { cursor: pointer; }

.msg-file audio,
.voice-message audio {
    width: 240px;
    height: 38px;
    border-radius: 20px;
    display: block;
}
.msg-file .file-size {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
    padding: 0 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.voice-message {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 200px;
}

/* ─── ACTIONS DE MESSAGE ──────────────────────────────────────────── */
.msg-actions {
    display: flex;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    background: var(--bg-elevated, #111);
    border-radius: 20px;
    padding: 3px 6px;
    gap: 2px;
    transition: opacity 0.15s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    z-index: 3;
}
.msg-bubble.sent .msg-actions     { right: 100%; margin-right: 6px; }
.msg-bubble.received .msg-actions { left: 100%;  margin-left: 6px;  }
.msg-bubble:hover .msg-actions    { opacity: 1; }

.msg-action-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 4px 6px;
    border-radius: 50%;
    color: var(--text-secondary, #aaa);
    transition: background 0.1s;
}
.msg-action-btn:hover { background: rgba(0,255,0,0.15); }

/* ─── RÉACTIONS ───────────────────────────────────────────────────── */
.msg-reactions {
    display: flex;
    gap: 3px;
    flex-wrap: wrap;
    margin-top: -6px;
    padding: 0 12px;
    position: relative;
    z-index: 2;
}
.msg-bubble.sent .msg-reactions     { justify-content: flex-end; }
.msg-bubble.received .msg-reactions { justify-content: flex-start; }
.msg-reactions:empty { display: none; }

.reaction {
    background: var(--bg-elevated, #1a1a1a);
    border: 1px solid var(--green-dim, #2a8a2a);
    border-radius: 12px;
    padding: 1px 8px;
    font-size: 0.75rem;
    cursor: pointer;
    white-space: nowrap;
}

/* ─── EMOJI PICKER ────────────────────────────────────────────────── */
.emoji-picker {
    position: absolute;
    z-index: 9999;
    background: #1a1a1a;
    border: 1px solid var(--green-dim, #2a8a2a);
    border-radius: 12px;
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.7);
    max-width: 280px;
}
.emoji-picker .emoji-btn {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px;
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background 0.1s;
}
.emoji-picker .emoji-btn:hover { background: rgba(0,255,0,0.15); }

/* ─── ZONE DE SAISIE ──────────────────────────────────────────────── */
#msg-input {
    flex: 1;
    background: var(--bg-input, #1a1a1a);
    border: 1px solid var(--border, #2a2a2a);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 16px; /* anti-zoom iOS : jamais < 16px, sinon Safari zoome au focus */
    padding: 0.5rem 0.75rem;
    border-radius: 20px;
    resize: none;
    min-height: 40px;
    max-height: 120px;
    outline: none;
    line-height: 1.5;
}
#msg-input:focus { border-color: var(--green-bright, #0f0); }

.voice-btn {
    background: none;
    border: none;
    color: var(--text-secondary, #999);
    cursor: pointer;
    font-size: 1.3rem;
    padding: 6px 10px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.15s;
    flex-shrink: 0;
}
.voice-btn:hover { color: var(--green-bright, #0f0); background: rgba(0,255,0,0.1); }
.voice-btn.recording {
    color: #ff4444;
    background: rgba(255,68,68,0.15);
    animation: pulse 1s infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ─── BARRE DE RÉPONSE ────────────────────────────────────────────── */
#reply-bar {
    display: none;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    background: var(--green-ghost);
    border-bottom: 1px solid var(--border);
}
#reply-bar.open { display: flex; }

/* ─── INDICATEURS ─────────────────────────────────────────────────── */
.typing-dot {
    display: inline-block;
    width: 4px;
    height: 4px;
    background: var(--green-bright);
    border-radius: 50%;
    margin: 0 1px;
    animation: typingDot 1.4s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingDot {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30%           { opacity: 1;   transform: translateY(-3px); }
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE — Tablette (≤ 1024px)
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
    #conv-sidebar { width: 260px; }
    .msg-bubble  { max-width: 78%; }
    .msg-bubble.has-media { max-width: 300px; }
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile (≤ 768px)
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

    #chat-container {
        height: calc(100vh - var(--header-height, 56px));
        height: calc(100dvh - var(--header-height, 56px)); /* navigateurs modernes — corrige le bug barre d'adresse mobile */
        border-radius: 0;
        border: none;
        position: relative;
    }

    #conv-sidebar {
        width: 100%;
        border-right: none;
    }

    #chat-window {
        display: none;
        position: absolute;
        inset: 0;
        background: var(--bg-surface);
        z-index: 10;
    }
    #chat-window.open {
        display: flex;
    }

    #chat-back { display: inline-flex; align-items: center; }

    .msg-bubble { max-width: 85%; }
    .msg-bubble.has-media { max-width: 260px; }

    /* Actions inline (le hover desktop ne marche pas en tactile) */
    .msg-actions {
        position: static;
        opacity: 1;
        transform: none;
        margin-top: 4px;
        background: transparent;
        box-shadow: none;
        padding: 0;
    }
    .msg-bubble.sent .msg-actions     { align-self: flex-end;   margin-right: 0; }
    .msg-bubble.received .msg-actions { align-self: flex-start; margin-left: 0;  }

    .msg-file img,
    .msg-file video { max-height: 280px; }

    #chat-messages { padding: 0.5rem; }
    .conv-item     { padding: 12px 14px; }

    #remote-video { height: 280px; }
    #local-video  { width: 100px; height: 75px; }
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE — Très petit mobile (≤ 380px)
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 380px) {
    .msg-bubble       { max-width: 90%; }
    .msg-bubble.has-media { max-width: 220px; }
    .msg-content      { font-size: 0.8rem; padding: 8px 12px; }
    .conv-avatar-wrap,
    .conv-avatar-wrap .avatar { width: 40px; height: 40px; }
    .msg-file img,
    .msg-file video   { max-height: 220px; }
    .voice-message audio,
    .msg-file audio   { width: 200px; }
}

/* ═══════════════════════════════════════════════════════════════════
   CITATION REPLY (message cité en haut d'une bulle)
   ═══════════════════════════════════════════════════════════════════ */
.msg-quote {
    background: rgba(0, 0, 0, 0.25);
    border-left: 3px solid var(--green-bright, #0f0);
    border-radius: 8px;
    padding: 5px 10px;
    margin: 4px 0;
    cursor: pointer;
    font-size: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
    transition: background 0.15s;
    max-width: 100%;
    overflow: hidden;
}
.msg-quote:hover { background: rgba(0, 0, 0, 0.4); }
.msg-quote-name {
    color: var(--green-bright, #0f0);
    font-weight: 600;
    font-size: 0.7rem;
}
.msg-quote-text {
    color: var(--text-secondary, #ccc);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.msg-bubble.sent .msg-quote { background: rgba(0, 0, 0, 0.2); border-left-color: rgba(255,255,255,0.5); }
.msg-bubble.sent .msg-quote-name { color: rgba(255,255,255,0.9); }
.msg-bubble.sent .msg-quote-text { color: rgba(255,255,255,0.7); }

/* Surbrillance temporaire quand on clique sur une citation */
.msg-bubble.highlight .msg-content {
    box-shadow: 0 0 0 2px var(--green-bright, #0f0);
    transition: box-shadow 0.3s;
}

/* ═══════════════════════════════════════════════════════════════════
   STATUT "LU" (✓✓ vert au lieu de ✓)
   ═══════════════════════════════════════════════════════════════════ */
.msg-status        { color: rgba(255,255,255,0.6); font-size: 0.8rem; }
.msg-status.read   { color: var(--green-bright, #0f0); font-weight: 700; }

/* ═══════════════════════════════════════════════════════════════════
   LIGHTBOX IMAGE (clic image plein écran)
   ═══════════════════════════════════════════════════════════════════ */
.chat-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    cursor: zoom-out;
    animation: lightboxFadeIn 0.15s ease-out;
}
@keyframes lightboxFadeIn { from { opacity: 0; } to { opacity: 1; } }

.chat-lightbox img {
    max-width: 95vw;
    max-height: 92vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.8);
    cursor: default;
}

.chat-lightbox-close {
    position: absolute;
    top: 16px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #fff;
    font-size: 1.3rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    z-index: 1;
}
.chat-lightbox-close:hover {
    background: rgba(255, 68, 68, 0.8);
    transform: scale(1.1);
}

@media (max-width: 768px) {
    .chat-lightbox-close { top: 12px; right: 12px; width: 40px; height: 40px; }
}

/* ═══════════════════════════════════════════════════════════════════
   MESSAGES SUPPRIMÉS — aucune action possible
   ═══════════════════════════════════════════════════════════════════ */
.msg-bubble.deleted .msg-content {
    background: rgba(255, 255, 255, 0.08) !important;
    color: var(--text-muted, #888) !important;
    font-style: italic;
    border: 1px dashed var(--border, #333);
}
.msg-bubble.deleted .msg-content em { opacity: 0.7; }
.msg-bubble.deleted .msg-actions,
.msg-bubble.deleted .msg-reactions {
    display: none !important;
}

/* ═══════════════════════════════════════════════════════════════════
   ACTIONS SOUS LES MÉDIAS (au lieu de à côté de la bulle)
   ═══════════════════════════════════════════════════════════════════ */
.msg-bubble.has-media .msg-actions {
    position: static;
    transform: none;
    opacity: 1;
    margin-top: 6px;
    margin-left: 0 !important;
    margin-right: 0 !important;
    background: var(--bg-elevated, rgba(0,0,0,0.6));
    align-self: flex-start;
    width: fit-content;
}
.msg-bubble.has-media.sent .msg-actions     { align-self: flex-end;   }
.msg-bubble.has-media.received .msg-actions { align-self: flex-start; }

/* Sur mobile, les actions sont déjà sous la bulle — uniformiser le style */
@media (max-width: 768px) {
    .msg-bubble.has-media .msg-actions {
        background: var(--bg-elevated, rgba(0,0,0,0.6));
    }
}

/* Panneau Amis — repliable */
#friends-list.collapsed { display: none; }
#conv-list.collapsed    { display: none; }
.friend-item {
    display: flex; align-items: center; gap: .6rem;
    padding: .5rem .85rem; cursor: pointer;
    border-radius: var(--radius, 4px);
}
.friend-item:hover { background: var(--green-ghost, rgba(74,222,128,.08)); }
