/* ============================================================
   Club SW VIP — Módulo 6: Mensajería
   Diseño limpio tipo WhatsApp
   ============================================================ */

/* ============================================================
   LAYOUT PRINCIPAL
   ============================================================ */

.pagina-mensajes {
    height: calc(100vh - 56px); /* descontar navbar */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.msj-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: 100%;
}

/* ============================================================
   SIDEBAR
   ============================================================ */

.msj-sidebar {
    width: 300px;
    min-width: 300px;
    background: var(--negro-suave);
    border-right: 1px solid var(--gris-borde);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.msj-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.1rem 0.65rem;
    border-bottom: 1px solid var(--gris-borde);
    flex-shrink: 0;
}

.msj-sidebar-titulo {
    font-family: var(--fuente-display);
    font-size: 1.1rem;
    color: var(--plata-claro);
    letter-spacing: 0.04em;
}

.msj-sidebar-btns {
    display: flex;
    gap: 0.2rem;
}

.msj-btn-ic {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 0.25rem 0.35rem;
    border-radius: var(--radio);
    transition: var(--trans);
    line-height: 1;
}
.msj-btn-ic:hover { background: rgba(255,255,255,0.07); }

.msj-search-wrap {
    padding: 0.6rem 0.9rem;
    border-bottom: 1px solid var(--gris-borde);
    flex-shrink: 0;
}

.msj-search {
    width: 100%;
    background: var(--gris-medio);
    border: 1px solid var(--gris-borde);
    border-radius: 20px;
    padding: 0.4rem 0.9rem;
    font-size: 0.82rem;
    color: var(--plata);
    outline: none;
    transition: var(--trans);
}
.msj-search:focus { border-color: var(--gris-claro); }

.msj-lista {
    flex: 1;
    overflow-y: auto;
}

.msj-vacio {
    padding: 3rem 1rem;
    text-align: center;
    color: var(--gris-texto);
    font-size: 0.8rem;
    opacity: 0.6;
}
.msj-vacio span { font-size: 2rem; display: block; margin-bottom: 0.5rem; }

.msj-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1rem;
    text-decoration: none;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    transition: background 0.12s;
    cursor: pointer;
}
.msj-item:hover  { background: rgba(255,255,255,0.04); }
.msj-item.activo { background: rgba(201,168,76,0.08); border-left: 2px solid var(--oro-oscuro); }

.msj-item-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 1px solid var(--gris-borde);
}

.msj-item-info {
    flex: 1;
    min-width: 0;
}

.msj-item-nombre {
    font-size: 0.87rem;
    color: var(--plata-claro);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msj-item-preview {
    font-size: 0.73rem;
    color: var(--gris-texto);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 0.1rem;
}

.msj-item-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.2rem;
    flex-shrink: 0;
}

.msj-item-fecha {
    font-size: 0.65rem;
    color: var(--gris-texto);
}

.msj-badge {
    background: var(--oro-oscuro);
    color: var(--negro);
    font-size: 0.62rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* ============================================================
   PANEL DERECHO
   ============================================================ */

.msj-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--negro);
    min-width: 0;
}

.msj-panel-vacio {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--gris-texto);
    opacity: 0.4;
    font-size: 0.85rem;
    gap: 0.75rem;
}
.msj-panel-vacio span { font-size: 3rem; }

/* Cabecera conversación */
.conv-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.1rem;
    background: var(--negro-suave);
    border-bottom: 1px solid var(--gris-borde);
    flex-shrink: 0;
}

.conv-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--gris-borde);
}

.conv-header-icono {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--gris-medio);
    border: 1px solid var(--gris-borde);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.conv-header-info {
    flex: 1;
    min-width: 0;
}

.conv-header-nombre {
    display: block;
    font-size: 0.92rem;
    color: var(--plata-claro);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-header-sub {
    display: block;
    font-size: 0.68rem;
    color: var(--gris-texto);
}

.conv-header-btns {
    display: flex;
    gap: 0.35rem;
}

.conv-btn-hdr {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 0.3rem 0.4rem;
    border-radius: var(--radio);
    color: var(--gris-claro);
    text-decoration: none;
    transition: var(--trans);
    line-height: 1;
}
.conv-btn-hdr:hover { background: rgba(255,255,255,0.08); }

/* ============================================================
   ÁREA DE MENSAJES
   ============================================================ */

.conv-mensajes {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 1rem 1.1rem;
    gap: 0;
    min-height: 0;
}

.msg-sep-fecha {
    text-align: center;
    font-size: 0.68rem;
    color: var(--gris-texto);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin: 0.75rem 0 0.5rem;
    opacity: 0.6;
}

.msg-eliminado {
    align-self: center;
    font-size: 0.71rem;
    color: var(--gris-texto);
    font-style: italic;
    padding: 0.15rem 0.65rem;
    background: rgba(255,255,255,0.02);
    border: 1px solid var(--gris-borde);
    border-radius: 10px;
    margin: 0.25rem 0;
}

/* ============================================================
   BURBUJAS
   ============================================================ */

.msg-wrap {
    display: flex;
    align-items: flex-end;
    gap: 0.45rem;
    max-width: 72%;
    position: relative;
    padding-top: 28px; /* espacio para la barra de acciones */
    margin-bottom: 4px;
}

.msg-wrap.mia   { align-self: flex-end;  flex-direction: row-reverse; }
.msg-wrap.ajena { align-self: flex-start; }

.msg-avatar {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--gris-borde);
    margin-bottom: 2px;
}

.msg-col {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    position: relative;
}

.msg-username {
    font-size: 0.66rem;
    color: var(--oro-oscuro);
    padding-left: 0.4rem;
}

/* Reply preview */
.msg-reply-prev {
    background: rgba(255,255,255,0.05);
    border-left: 2px solid var(--oro-oscuro);
    border-radius: 0 var(--radio) var(--radio) 0;
    padding: 0.2rem 0.6rem;
    margin-bottom: 0.15rem;
    display: flex;
    flex-direction: column;
    gap: 0.05rem;
    cursor: pointer;
    max-width: 100%;
    transition: var(--trans);
}
.msg-reply-prev:hover { background: rgba(255,255,255,0.08); }

.msg-reply-autor {
    font-size: 0.66rem;
    color: var(--oro-claro);
}
.msg-reply-txt {
    font-size: 0.73rem;
    color: var(--gris-claro);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 240px;
}

/* Burbuja principal */
.msg-burbuja {
    padding: 0.45rem 0.75rem 0.3rem;
    border-radius: var(--radio-lg);
    word-break: break-word;
    max-width: 100%;
}
.msg-burbuja.mia   {
    background: linear-gradient(135deg, #6b4f1a, #3d2c0c);
    color: #f0e0b0;
    border-bottom-right-radius: 4px;
}
.msg-burbuja.ajena {
    background: var(--gris-medio);
    color: var(--plata);
    border-bottom-left-radius: 4px;
}

/* Emoji solo — sin burbuja de color */
.msg-burbuja.msg-emoji-solo {
    background: transparent !important;
    box-shadow: none !important;
    padding: 0.1rem 0.3rem;
}
.msg-burbuja.msg-emoji-solo .msg-txt {
    font-size: 2.8rem;
    line-height: 1.15;
}
.msg-burbuja.msg-emoji-solo .msg-hora {
    text-align: center;
}

.msg-txt {
    font-size: 0.86rem;
    line-height: 1.5;
    margin: 0;
}

.msg-img {
    max-width: 200px;
    max-height: 200px;
    border-radius: var(--radio-md);
    display: block;
    cursor: zoom-in;
    margin-bottom: 0.2rem;
    object-fit: cover;
}

.msg-video {
    max-width: 320px;
    max-height: 240px;
    border-radius: var(--radio-md);
    display: block;
    margin-bottom: 0.2rem;
    background: var(--negro);
}

.msg-hora {
    font-size: 0.58rem;
    opacity: 0.5;
    display: block;
    text-align: right;
    margin-top: 0.1rem;
    white-space: nowrap;
}

/* Reacciones debajo de la burbuja */
.msg-reacs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem;
    margin-top: 0.1rem;
}

.msg-reac-chip {
    background: var(--negro-suave);
    border: 1px solid var(--gris-borde);
    border-radius: 10px;
    padding: 1px 6px;
    font-size: 0.72rem;
    cursor: pointer;
    transition: var(--trans);
    color: var(--plata);
    line-height: 1.6;
}
.msg-reac-chip:hover  { border-color: var(--gris-claro); }
.msg-reac-chip.activo { background: var(--oro-trans); border-color: var(--oro-oscuro); color: var(--oro-claro); }

/* ============================================================
   BARRA DE ACCIONES — esquina superior derecha de msg-col
   ============================================================ */

.msg-acciones {
    position: absolute;
    top: -26px;
    right: 0;
    display: flex;
    flex-direction: row;
    gap: 2px;
    background: var(--negro-suave);
    border: 1px solid var(--gris-borde);
    border-radius: 14px;
    padding: 2px 5px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease;
    z-index: 50;
}

.msg-wrap:hover .msg-acciones,
.msg-wrap.show-acc .msg-acciones,
.msg-wrap.picker-open .msg-acciones {
    opacity: 1;
    pointer-events: auto;
}

.msg-acc-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.82rem;
    padding: 2px 3px;
    border-radius: 8px;
    transition: background 0.1s;
    color: var(--gris-claro);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    line-height: 1;
}
.msg-acc-btn:hover { background: rgba(255,255,255,0.12); color: var(--plata-claro); }

/* ============================================================
   PICKER GLOBAL DE REACCIONES
   ============================================================ */

#reac-picker-global {
    display: none;
    flex-direction: row;
    gap: 4px;
    background: var(--negro-suave);
    border: 1px solid var(--gris-borde);
    border-radius: 20px;
    padding: 5px 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.65);
}

.reac-btn-global {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.15rem;
    padding: 2px 3px;
    border-radius: 6px;
    transition: transform 0.1s;
    line-height: 1;
}
.reac-btn-global:hover { transform: scale(1.3); }

/* ============================================================
   REPLY BAR
   ============================================================ */

.conv-reply-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.45rem 1.1rem;
    background: var(--negro-suave);
    border-top: 1px solid var(--gris-borde);
    flex-shrink: 0;
    gap: 0.75rem;
}

.reply-bar-info {
    display: flex;
    flex-direction: column;
    border-left: 2px solid var(--oro-oscuro);
    padding-left: 0.65rem;
    min-width: 0;
    flex: 1;
}

.reply-bar-autor {
    font-size: 0.68rem;
    color: var(--oro-claro);
}
.reply-bar-txt {
    font-size: 0.75rem;
    color: var(--gris-claro);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 350px;
}

.reply-bar-cerrar {
    background: none;
    border: none;
    color: var(--gris-claro);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.2rem 0.4rem;
    flex-shrink: 0;
    transition: var(--trans);
}
.reply-bar-cerrar:hover { color: var(--plata-claro); }

/* ============================================================
   ÁREA DE INPUT
   ============================================================ */

/* Usuario suspendido/inactivo — banner en la conversación */
.conv-suspendida-banner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(220,53,69,0.07);
    border-top: 1px solid rgba(220,53,69,0.2);
    border-bottom: 1px solid rgba(220,53,69,0.2);
    padding: 0.7rem 1.25rem;
    flex-shrink: 0;
}
.conv-suspendida-banner p {
    font-size: 0.82rem;
    color: #f87171;
    line-height: 1.45;
    margin: 0;
}
.conv-suspendida-banner strong {
    display: block;
    font-size: 0.86rem;
    margin-bottom: 0.1rem;
}

/* Input deshabilitado (cuenta no activa) */
.conv-input-zona.deshabilitada {
    pointer-events: none;
    opacity: 0.4;
    user-select: none;
}

/* Item de sidebar con usuario no disponible */
.msj-item-nodisponible .msj-item-nombre {
    opacity: 0.6;
}
.msj-item-nodisponible .msj-item-preview {
    color: #f87171;
    font-style: italic;
    font-size: 0.74rem;
}
.msj-item-nodisponible .msj-item-avatar {
    opacity: 0.45;
    filter: grayscale(60%);
}

.conv-input-zona {
    background: var(--negro-suave);
    border-top: 1px solid var(--gris-borde);
    padding: 0.6rem 1rem;
    flex-shrink: 0;
}

.conv-input-fila {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}

.conv-btn-tool {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.3rem 0.35rem;
    border-radius: var(--radio);
    color: var(--gris-claro);
    transition: var(--trans);
    flex-shrink: 0;
    line-height: 1;
}
.conv-btn-tool:hover { background: rgba(255,255,255,0.07); color: var(--plata-claro); }

.conv-textarea {
    flex: 1;
    min-height: 36px;
    max-height: 100px;
    resize: none;
    background: var(--gris-medio);
    border: 1px solid var(--gris-borde);
    border-radius: 18px;
    padding: 0.5rem 0.9rem;
    font-size: 0.87rem;
    color: var(--plata);
    font-family: var(--fuente-cuerpo);
    outline: none;
    transition: border-color 0.15s;
    line-height: 1.45;
    overflow-y: auto;
}
.conv-textarea:focus { border-color: var(--gris-claro); }

.conv-btn-enviar {
    background: var(--oro-oscuro);
    border: none;
    cursor: pointer;
    color: var(--negro);
    font-size: 1rem;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--trans);
}
.conv-btn-enviar:hover   { background: var(--oro); }
.conv-btn-enviar:disabled { opacity: 0.5; cursor: not-allowed; }

.conv-bloqueado {
    padding: 0.9rem 1.1rem;
    background: var(--negro-suave);
    border-top: 1px solid var(--gris-borde);
    font-size: 0.82rem;
    color: var(--gris-texto);
    text-align: center;
    flex-shrink: 0;
}

/* ============================================================
   EMOJI PICKER (campo de texto)
   ============================================================ */

.emoji-wrap {
    position: relative;
    flex-shrink: 0;
}

.emoji-panel {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    width: 300px;
    max-height: 260px;
    background: var(--gris-oscuro);
    border: 1px solid var(--gris-borde);
    border-radius: var(--radio-lg);
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    z-index: 200;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.emoji-tabs {
    display: flex;
    gap: 2px;
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid var(--gris-borde);
    flex-wrap: wrap;
    flex-shrink: 0;
}

.emoji-tab {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 3px 5px;
    border-radius: var(--radio);
    transition: background 0.1s;
    line-height: 1;
}
.emoji-tab:hover  { background: rgba(255,255,255,0.08); }
.emoji-tab.activo { background: rgba(201,168,76,0.15); }

.emoji-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1px;
    padding: 0.4rem;
    overflow-y: auto;
}

.emoji-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 3px;
    border-radius: 4px;
    transition: background 0.1s;
    line-height: 1;
}
.emoji-btn:hover { background: rgba(255,255,255,0.1); }

/* ============================================================
   HIGHLIGHT AL NAVEGAR DESDE REPLY
   ============================================================ */

@keyframes msgHighlight {
    0%   { background: rgba(201,168,76,0.25); }
    70%  { background: rgba(201,168,76,0.25); }
    100% { background: transparent; }
}
.msg-highlight {
    animation: msgHighlight 1.5s ease forwards;
    border-radius: var(--radio);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* Boton "volver" en cabecera de conversacion (oculto en desktop) */
.conv-header-back {
    display: none;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--gris-borde);
    border-radius: 8px;
    color: var(--oro-claro);
    font-size: 1.2rem;
    text-decoration: none;
    flex-shrink: 0;
    margin-right: 0.25rem;
    transition: var(--trans);
}
.conv-header-back:hover { background: var(--oro-trans); }

@media (max-width: 900px) {
    .msj-sidebar { width: 260px; min-width: 260px; }
    .msg-wrap { max-width: 90%; }
}

/* ==== Mobile portrait: un solo panel a la vez ==== */
@media (max-width: 700px) {
    .pagina-mensajes {
        height: calc(100vh - 56px);
        height: calc(100dvh - 56px);
    }

    .msj-layout { position: relative; }

    /* Sidebar ocupa todo el ancho */
    .msj-sidebar {
        width: 100%;
        min-width: 0;
        border-right: none;
    }

    /* Panel ocupa todo el ancho */
    .msj-panel {
        width: 100%;
        min-width: 0;
    }

    /* Cuando hay conversacion activa: ocultar sidebar, mostrar panel */
    .msj-layout:not(:has(.msj-panel-vacio)) .msj-sidebar { display: none; }

    /* Cuando NO hay conversacion activa: mostrar sidebar, ocultar panel */
    .msj-layout:has(.msj-panel-vacio) .msj-panel { display: none; }

    /* Boton volver visible solo en mobile */
    .conv-header-back { display: inline-flex; }

    /* Cabecera mas compacta */
    .conv-header { padding: 0.55rem 0.75rem; gap: 0.5rem; }
    .conv-header-avatar, .conv-header-icono { width: 36px; height: 36px; }
    .conv-header-nombre { font-size: 0.9rem; }

    .msg-wrap { max-width: 92%; }

    /* Barra de entrada mas compacta */
    .conv-input-wrap { padding: 0.5rem 0.6rem; }
}

/* Fallback para navegadores sin :has() — usa data attribute en PHP si falla */
@media (max-width: 700px) {
    @supports not (selector(:has(*))) {
        .msj-sidebar { display: none; }
        .msj-panel { display: flex; flex-direction: column; width: 100%; }
    }
}
