/* ========================================================= */
/* --- ARCHIVO MAESTRO V2/V8: Estilos para Llamada Grupal --- */
/* ========================================================= */

/* 1. Contenedor Principal y Layout */
.call-modal-content {
    position: relative;
    max-width: 500px; width: 95vw;
    aspect-ratio: 9 / 16;
    max-height: 95vh;
    background-color: #1a1a1a;
    border-radius: 24px;
    overflow: hidden;
    transition: all 0.4s ease;
    /* Estilos adicionales del CSS anterior */
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
#video-grid {
    width: 100%; height: 100%;
    position: relative;
    background-color: #000;
}

/* 2. Contenedores de Video (Principal y Miniaturas) */
.video-container {
    position: absolute;
    background-color: #2c3e50;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}
.video-container video, .video-container .avatar-placeholder {
    width: 100%; height: 100%;
    object-fit: cover;
}
.participant-name {
    position: absolute;
    bottom: 5px; left: 8px;
    color: white; font-size: 12px;
    text-shadow: 0 1px 3px black;
    z-index: 15;
}

.main-video {
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 5;
    border-radius: 0;
}

#thumbnail-container {
    position: absolute;
    bottom: 120px;
    right: 15px;
    width: 100px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 10;
}
.thumbnail-video {
    position: relative; /* Importante para que fluya en la columna */
    width: 100px;
    height: 150px;
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    cursor: pointer;
}
.thumbnail-video video.mirror {
    transform: scaleX(-1);
}

/* --- Estilos del CSS anterior (fusionados y adaptados) --- */

/* 3. Lógica de Funciones Especiales */

/* Asegura que el contenedor tenga fondo negro cuando se comparte pantalla */
.call-modal-content.screen-sharing-active {
    background-color: #000;
}

/* Al presionar "Girar Vista", el contenedor CAMBIA DE FORMA a horizontal */
.call-modal-content.view-rotated {
    aspect-ratio: 16 / 9;
    width: 80vw;
    max-width: 140vh;
}

/* El video dentro de la vista rotada no necesita transformaciones extra */
.call-modal-content.view-rotated video {
    transform: none !important;
}

/* 4. Overlays (Información y Controles) */

/* Información superpuesta (nombre, estado, etc.) */
.call-info-overlay {
    position: absolute;
    top: 16px; left: 16px; right: 0;
    padding: 0 !important;
    color: white;
    z-index: 20;
    /* Limpieza total de fondos heredados (Adiós raya negra) */
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    pointer-events: none; /* Para poder hacer clic "a través" de él */
    transition: all 0.4s ease-in-out; /* Animación suave de cambio de posición */
}
.call-info-overlay h3 { 
    margin: 0 0 2px; 
    font-size: 1.4rem; 
    font-weight: 600; 
    /* Sombras más fuertes para legibilidad impecable sin usar fondo oscuro */
    text-shadow: 0 2px 6px rgba(0,0,0,0.9), 0 1px 3px rgba(0,0,0,0.7);
    background: transparent !important;
    transition: all 0.4s ease-in-out;
}
.call-info-overlay p { 
    margin: 2px 0 0 0; 
    font-size: 0.9rem; 
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
    background: transparent !important;
    transition: all 0.4s ease-in-out;
}
#callDuration:empty { display: none; } /* Ocultar duración si está vacía */

/* ✨ MEJORA UI: Estado de Llamada Entrante ✨ */
/* Cuando suena, la información se centra, se agranda y se ve premium */
.call-modal-content.incoming-call .call-info-overlay {
    top: 30%;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    width: 90%;
}
.call-modal-content.incoming-call .call-info-overlay h3 {
    font-size: 28px;
    margin-bottom: 6px;
}
.call-modal-content.incoming-call .call-info-overlay p {
    font-size: 16px;
    opacity: 0.8;
}

/* Contenedores de los botones de control (base del nuevo CSS, con ajustes del anterior) */
.call-controls-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 0 15px 25px 15px;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    z-index: 40;
    background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
}

/* Controles de llamada entrante (del CSS anterior) */
.incoming-call-controls {
    position: absolute;
    bottom: 25px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
    z-index: 40;
    width: 100%;
    justify-content: space-around;
}

.incoming-control-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: white;
    font-size: 0.8rem;
}

/* Estilo base para todos los botones redondos */
.call-control-btn {
    position: relative; /* Necesario para la línea diagonal */
    width: 60px; /* Ajustado para el nuevo diseño */
    height: 60px; /* Ajustado para el nuevo diseño */
    border-radius: 50%;
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px; /* Ajustado para el nuevo diseño */
    transition: transform 0.2s ease, background-color 0.2s ease;
    background-color: rgba(255, 255, 255, 0.2);
}
.call-control-btn:hover {
    transform: scale(1.1);
}
.call-control-btn .material-icons {
    font-size: inherit; /* Hereda el tamaño del botón */
}

/* Colores de botones específicos */
.call-controls-overlay .hangup, .incoming-call-controls .reject { background-color: #e63946; } /* Rojo */
.incoming-call-controls .accept { background-color: #2a9d8f; } /* Verde */

/* Lógica de visibilidad para llamada entrante vs. activa */
.incoming-call-controls { display: none; }
.call-modal-content.incoming-call .incoming-call-controls { display: flex; } /* Muestra los botones de aceptar/rechazar */
.call-modal-content.incoming-call .call-controls-overlay { display: none; } /* Oculta los controles normales */

/* Avatares y estados de video */
.avatar-placeholder {
    width: 100%; height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 0; left: 0;
    background-color: #2d3436;
    color: white;
    font-size: 48px;
    font-weight: bold;
    text-transform: uppercase;
}

/* LÓGICA CLAVE: La visibilidad la controla el JS usando la clase 'video-disabled' */
/* Por defecto, el avatar está oculto y el video intenta mostrarse. */
.avatar-placeholder {
    display: none;
}
/* Cuando el JS añade la clase .video-disabled al video (porque la cámara está apagada o no disponible)... */
video.video-disabled {
    display: none; /* ...ocultamos el video... */
}
/* ...y mostramos el avatar que es su hermano adyacente. */
video.video-disabled + .avatar-placeholder {
    display: flex;
}

/* Corrección para forzar la fuente de íconos en los botones de llamada */
.call-control-btn span {
    font-family: 'Material Icons';
    font-weight: normal;
    font-style: normal;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-block;
    white-space: nowrap;
    word-wrap: normal;
    direction: ltr;
    -webkit-font-feature-settings: 'liga';
    -webkit-font-smoothing: antialiased;
}

/* NUEVO ESTILO: Añade una línea diagonal a los botones desactivados */
.call-control-btn.muted::after,
.call-control-btn.off::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 45%; /* Ancho de la línea */
    height: 3px;  /* Grosor de la línea */
    background-color: red;
    transform: translate(-50%, -50%) rotate(45deg); /* Centra y rota la línea */
    border-radius: 3px;
}

/* Estilo para el botón de 'Compartir Pantalla' cuando está activo */
.call-control-btn#screenShareBtn.active {
    background-color: #2a9d8f;
    box-shadow: 0 0 15px #2a9d8f;
}

/* Estilo para el botón de rotación cuando está activo */
.call-control-btn#rotateBtn.active {
    background-color: #2a9d8f;
}

/* --- CALIBRACIÓN FINAL DEL ZOOM EN VISTA PREVIA --- */

/* Cuando la cámara local se rota manualmente... */
.call-modal-content.local-camera-rotated #local-video {
    /* ...la vista previa se ajusta en lugar de recortar */
    object-fit: contain;
    /* Y anulamos el efecto espejo porque el video ya viene orientado correctamente */
    transform: none !important;
}

/* --- INICIA CIRUGÍA ESTÉTICA: TRANSPARENCIA --- */

/* Por defecto, los controles y el video local están atenuados */
.call-controls-overlay,
.local-video-thumbnail { /* Ajustado para la nueva estructura */
    opacity: 0.1; /* Nivel de transparencia (puedes ajustarlo entre 0 y 1) */
    transition: opacity 0.3s ease-in-out; /* Animación suave */
}

/* Cuando el ratón pasa por CUALQUIER parte de la ventana de la llamada... */
.call-modal-content:hover .call-controls-overlay,
.call-modal-content:hover .local-video-thumbnail { /* Ajustado para la nueva estructura */
    /* ...los controles y el video local se vuelven 100% visibles */
    opacity: 1;
}

/* --- FIN DE CIRUGÍA ESTÉTICA --- */

/* --- INICIA CIRUGÍA: NUEVO MENÚ DE OPCIONES --- */

/* Contenedor de cada botón individual */
.control-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

/* Botones redondos (tamaño específico para colgar) */
.call-control-btn.hangup {
    width: 70px;
    height: 70px;
    font-size: 32px;
}

/* Etiqueta de texto (solo para el menú) */
.control-label {
    font-size: 11px;
    color: #FFFFFF;
    text-shadow: 0 1px 2px rgba(0,0,0,0.7);
    text-align: center;
}

/* --- Estilos para el Menú Desplegable --- */

.more-options-menu {
    position: absolute;
    bottom: 100px; /* Posición justo encima de la barra de controles */
    right: 20px;
    background-color: rgba(40, 40, 40, 0.9);
    backdrop-filter: blur(5px);
    padding: 15px;
    border-radius: 18px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 30;
    
    /* Animación de aparición */
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.2s ease-out;
    pointer-events: none;
}

.more-options-menu.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

/* Ajustes para los botones dentro del menú */
.more-options-menu .call-control-btn {
    width: 50px;
    height: 50px;
    font-size: 24px;
    background-color: rgba(80, 80, 80, 0.8);
}

/* --- FIN DE CIRUGÍA --- */

/* --- INICIA CIRUGÍA: MINI-CHAT TRANSPARENTE v3.0 --- */

.in-call-chat-container {
    position: absolute;
    bottom: 120px;
    left: 10px;
    right: 10px;
    height: 40%;
    max-height: 250px;
    
    /* FONDO COMPLETAMENTE TRANSPARENTE */
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    backdrop-filter: none;

    z-index: 35;
    display: flex;
    flex-direction: column;
    
    transform: translateY(100%);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease-out;
}

.in-call-chat-container.visible {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
}

.in-call-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    color: white;
    font-size: 0.8rem;
    font-weight: bold;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
    /* Transparencia para el header */
    background: transparent !important;
    border: none !important;
}

.in-call-chat-header .material-icons {
    cursor: pointer;
}

.in-call-message-area {
    flex-grow: 1;
    overflow-y: auto;
    padding: 0 10px;
    display: flex;
    flex-direction: column-reverse;
}

/* --- INICIA CIRUGÍA FINAL: TRANSPARENCIA ABSOLUTA Y TEXTO NEGRO --- */
/* Estilo base para TODOS los mensajes en el mini-chat */
.in-call-message-area .mensaje,
.in-call-message {
    background: transparent !important; /* Base transparente para todos */
    box-shadow: none !important;
    padding: 2px 12px;
    margin-bottom: 4px;
    font-size: 14px;
    /* Letras negras con trazo blanco para que JAMÁS se pierdan con el fondo del video */
    color: #000 !important;
    font-weight: 800 !important;
    text-shadow: 
        -1px -1px 0 #fff,
         1px -1px 0 #fff,
        -1px  1px 0 #fff,
         1px  1px 0 #fff,
         0 0 6px #fff !important;
}

/* Anulación específica para mensajes enviados dentro del mini-chat */
.in-call-message-area .mensaje.enviado {
    background: transparent !important;
}
/* Anulación específica para mensajes recibidos dentro del mini-chat */
.in-call-message-area .mensaje.recibido {
    background: transparent !important;
}

/* --- NUEVO ESTILO: Etiqueta del remitente del mensaje --- */
.in-call-sender,
.message-sender-label {
    font-size: 0.75rem;
    margin-bottom: 4px;
    color: #000 !important;
    font-weight: 900 !important;
    text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff !important;
}
/* --- FIN DE CIRUGÍA FINAL --- */

.in-call-chat-footer {
    display: flex;
    padding: 8px;
    /* Fondo transparente */
    background: transparent !important;
    border: none !important;
}

#inCallChatInput {
    flex-grow: 1;
    border: none;
    border-radius: 20px;
    padding: 8px 15px;
    outline: none;
    /* Caja de escritura transparente pero visible */
    background-color: rgba(255, 255, 255, 0.4) !important;
    color: #000 !important;
    font-weight: 600 !important;
}
#inCallChatInput::placeholder {
    color: rgba(0, 0, 0, 0.6) !important;
}

/* --- Estilos para el nuevo botón de Emojis del Mini-Chat --- */
.in-call-icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: 50%;
    transition: background-color 0.2s;
}
.in-call-icon-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}
.in-call-icon-btn .material-icons {
    font-size: 24px;
}

/* ================================================================
   ✅ v7.0: TOAST FLOTANTE — ANCLADO AL BODY (NIVEL DIOS)
   - position: fixed para que nadie lo tape (ni el video, ni el modal)
   - z-index: 999999 para estar encima de absolutamente todo
   - Barra de progreso animada de 15 segundos
   ================================================================ */

#inCallToastContainer {
    position: fixed !important;
    top: 12% !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    z-index: 999999 !important;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none; /* No bloquea clicks al video */
    width: 88%;
    max-width: 360px;
    text-align: left;
}

.in-call-toast {
    position: relative;
    background: rgba(20, 20, 20, 0.96) !important;
    color: #fff !important;
    padding: 14px 18px 10px 18px !important;
    border-radius: 16px !important;
    border: 2px solid #2a9d8f !important;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.85) !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    overflow: hidden;
    animation: toastPopIn 0.35s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
    transition: opacity 0.4s ease, transform 0.4s ease;
}

/* Etiqueta superior "💬 Mensaje en el mini-chat" */
.in-call-toast-label {
    font-size: 11px;
    font-weight: 700;
    color: #2a9d8f;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 5px;
}

/* Cuerpo del mensaje: "Nombre: texto..." */
.in-call-toast-body {
    font-size: 14px;
    color: #f0f0f0;
    line-height: 1.4;
    word-break: break-word;
}

.in-call-toast-body strong {
    color: #ffffff;
    font-weight: 700;
}

/* Barra de progreso verde que se vacía en 15 segundos */
.in-call-toast::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    width: 100%;
    background: #2a9d8f;
    border-radius: 0 0 14px 14px;
    animation: toastProgress 15s linear forwards;
    transform-origin: left;
}

/* Toast desvaneciéndose */
.in-call-toast.fade-out {
    opacity: 0 !important;
    transform: translateY(-12px) scale(0.96) !important;
}

/* Animación de entrada del toast */
@keyframes toastPopIn {
    0%   { opacity: 0; transform: translateY(-18px) scale(0.92); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* Barra de progreso que se vacía de derecha a izquierda */
@keyframes toastProgress {
    0%   { transform: scaleX(1); }
    100% { transform: scaleX(0); }
}

/* ================================================================
   PARCHE callview.css — Fixes Adicionales
   ================================================================ */

/* ── Fix 1: Botones de llamada entrante correctamente centrados ── */
.incoming-call-controls {
    position: absolute !important;
    bottom: 30px !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    transform: none !important;
    display: none;
    justify-content: center !important;
    align-items: center !important;
    gap: 50px !important;
    padding: 0 !important;
    box-sizing: border-box !important;
    z-index: 40 !important;
}
.call-modal-content.incoming-call .incoming-call-controls {
    display: flex !important;
}
.call-modal-content.incoming-call .call-controls-overlay {
    display: none !important;
}
.incoming-control-item {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    color: white !important;
    font-size: 0.8rem !important;
    margin: 0 !important;
    padding: 0 !important;
    transform: none !important;
}

/* ── Fix 2: Preview local — sin transform cuando canvas activo ── */
/* Sin canvas: mirror normal para cámara frontal */
#local-video.mirror {
    transform: scaleX(-1) !important;
}

/* Con canvas activo: el JS agrega clase local-camera-rotated al modal.
   Tu CSS ya tenía esta regla pero nunca se activaba — ahora sí. */
.call-modal-content.local-camera-rotated #local-video,
.call-modal-content.local-camera-rotated .thumbnail-video video {
    transform: none !important;
    object-fit: contain !important;
}

/* Thumbnail siempre contain para ver el encuadre completo */
.thumbnail-video video {
    object-fit: contain !important;
}

/* ── Notificación de mensaje nuevo en el botón del chat ── */
.call-control-btn#toggleChatBtn.has-new-messages::before {
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 14px;
    height: 14px;
    background-color: #ff3b30; /* Rojo intenso estilo iOS */
    border-radius: 50%;
    border: 2px solid rgba(0, 0, 0, 0.5); /* Borde para contrastar con el botón */
    z-index: 10;
}

/* ================================================================
   ✅ v8.0 NUEVO: Modal de opciones al colgar en grupo
   Se inyecta via JS (hangupOptionsModal), solo estilos de apoyo
   ================================================================ */

#hangupOptionsModal {
    animation: backdropFadeIn 0.2s ease forwards;
}
#hangupOptionsModal > div {
    animation: modalSlideUp 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
}

@keyframes backdropFadeIn {
    0%   { opacity: 0; }
    100% { opacity: 1; }
}
@keyframes modalSlideUp {
    0%   { opacity: 0; transform: translateY(20px) scale(0.95); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* ================================================================
   ✅ v8.0 NUEVO: Modal de invitación flotante
   Se inyecta via JS (callInviteModal), estilos hover de apoyo
   ================================================================ */

#callInviteModal #btnRejectInvite:hover {
    background: rgba(229, 57, 53, 0.35) !important;
}
#callInviteModal #btnAcceptInvite:hover {
    background: rgba(42, 157, 143, 0.5) !important;
}

/* ================================================================
   ✅ v8.0 NUEVO: Badge de modo grupo en el overlay de info
   Muestra "👥 X participantes" cuando callMode === 'group'
   ================================================================ */

#callStatus[data-mode="group"] {
    color: #2a9d8f;
    font-weight: 600;
}