/* ==========================================================================
   FUENTES Y ANIMACIONES GLOBALES
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=UnifrakturMaguntia&display=swap');

@keyframes fadeSweep {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulseSignal {
    from { opacity: 0.3; }
    to { opacity: 1; }
}

/* ==========================================================================
   ESTRUCTURA BASE Y CONTROL DE PANTALLA COMPLETA
   ========================================================================== */
html, body {
    height: 100%;
    margin: 0;
}

body {
    font-family: Arial, sans-serif;
    color: #222;
    background: #fff;
    line-height: 1.2;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    box-sizing: border-box;
}

/* Wrapper central elástico */
.main-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
    width: 100%;
}

/* Ajustes adaptativos del contenedor principal */
.container {
    width: 100%;
    max-width: 760px; 
    margin: auto;
    transition: max-width 0.3s ease;
}

/* Expansión balanceada del ancho si la sala está activa (centrado elegante) */
#room:not(.hidden) ~ .container,
.container:has(#room:not(.hidden)) {
    max-width: 820px;
}

/* ==========================================================================
   SOLUCIÓN DE EXPANSIÓN VERTICAL ESTRICTA (Sala Activa)
   ========================================================================== */
body:has(#room:not(.hidden)) {
    height: 100vh;
    overflow: hidden; /* Elimina scrollbars globales */
}

body:has(#room:not(.hidden)) .main-wrapper {
    align-items: stretch;
    height: calc(100vh - 41px); /* Ajuste dinámico restando el alto exacto del footer */
    padding: 10px 20px;
}

body:has(#room:not(.hidden)) .container {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Anclaje estructural de la sala */
#room {
    position: relative;
}

body:has(#room:not(.hidden)) #room {
    display: flex;
    flex-direction: column;
    flex: 1;
    height: 100%;
}

/* ==========================================================================
   ELEMENTOS DE IDENTIDAD (BRANDING)
   ========================================================================== */
#brand-header {
    text-align: center;
    margin-bottom: 20px;
}

h1 {
    margin-bottom: 0;
    color: #551A8B;
    font-family: 'UnifrakturMaguntia', cursive;
    font-size: 7.5rem; 
    letter-spacing: 1px;
    -webkit-text-stroke: 1px #000000;
}

.subtitle {
    margin-top: 5px;
    color: #555;
    margin-bottom: 25px;
    max-width: 550px;
    margin-left: auto;
    margin-right: auto;
}

/* Ajustes de Branding compactados dentro del chat */
body:has(#room:not(.hidden)) h1 {
    font-size: 3.5rem; 
    margin-top: 0;
}

body:has(#room:not(.hidden)) .subtitle {
    display: none; /* Oculta eslogan para priorizar espacio de conversación */
}

/* ==========================================================================
   VISTAS Y ELEMENTOS FORMULARIOS BASE
   ========================================================================== */
#room:not(.hidden) {
    animation: fadeSweep 0.4s ease-out forwards;
}

#home {
    text-align: center;
}

.hidden {
    display: none !important;
}

label {
    display: block;
    margin-bottom: 10px;
    font-weight: bold;
}

select,
button,
input {
    font-size: 14px;
    padding: 6px;
    box-sizing: border-box;
}

button {
    cursor: pointer;
    background: #551A8B;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    transition: background 0.2s;
}

button:hover {
    background: #40126b;
}

#createRoom {
    margin-left: 10px;
}

/* ==========================================================================
   BOTONES DE CONTROL (EN FLUJO NATURAL Y VISIBLES)
   ========================================================================== */
.room-controls {
    display: flex;
    justify-content: flex-end; /* Los empuja perfectamente a la derecha */
    gap: 8px;
    margin-bottom: 10px; /* Genera un respiro antes de la caja de mensajes */
    width: 100%;
    z-index: 100;
}

.room-controls button {
    background: #f7f7f7;
    color: #222;
    border: 1px solid #ccc;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    width: 36px;
    height: 36px;
    transition: background 0.2s, color 0.2s;
}

.room-controls button:hover {
    background: #eee;
    color: #551A8B;
}

/* ==========================================================================
   MAIN LAYOUT (Estructura Corregida para Aislamiento de Scroll)
   ========================================================================== */
.room-main-layout {
    display: flex;
    flex-direction: column;
    margin-top: 0; 
    margin-bottom: 0;
    align-items: stretch; 
    flex: 1;
    min-height: 0; /* Impide el desbordamiento hacia abajo en flexbox */
    position: relative;
    overflow: hidden; /* Mantiene la caja rígida en el Viewport */
}

/* Contenedor del Chat (Ocupa el 100% centrado) */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    border: none;
    border-radius: 0; 
    padding: 0;
    background: transparent;
    width: 100%;
    min-height: 0; /* Permite calcular la reducción interna de los hijos */
}

/* Área de mensajes con scroll interno garantizado */
#messages {
    flex: 1; /* Absorbe el espacio disponible en lugar de flex-grow fijo */
    overflow-y: auto; /* Activa la barra de desplazamiento únicamente aquí */
    border: 1px solid #ddd;
    background: #fff;
    padding: 15px;
    margin-bottom: 12px;
    border-radius: 0;
    scroll-behavior: smooth;
    min-height: 0; /* Obliga a respetar los límites del contenedor padre */
}

/* Tipografía de Mensajería */
.message {
    margin-bottom: 8px;
    word-break: break-word;
    font-size: 19px;
    line-height: 1.2;
}

.message.system {
    color: #777;
    font-style: italic;
    font-size: 17px;
}

.message.sent {
    color: #222;
}

.message.received {
    color: #551A8B;
}

/* Barra inferior del chat estática */
.message-box {
    display: flex;
    gap: 8px;
    position: relative; /* Contexto de anclaje absoluto para Picmo */
    flex-shrink: 0; /* Protege el input de colapsar o moverse hacia abajo */
}

#messageInput {
    flex: 1;
    border: 1px solid #ccc;
    border-radius: 4px; /* CORREGIDO: Redondeo sutil aplicado */
    padding: 8px;
}

#sendBox {
    border-radius: 4px; /* CORREGIDO: Redondeo sutil aplicado */
}

/* ==========================================================================
   SIDEBAR PANEL / OVERLAYS FLOTANTES
   ========================================================================== */
.sidebar-panel {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 105; /* Prioridad de capa sobre los mensajes */
    width: 100%;
    max-width: 320px;
    pointer-events: none; /* Deja pasar clicks si está cerrado */
}

/* Alineados perfectamente cayendo abajo de la barra de controles */
.participants-section,
.room-meta-section {
    pointer-events: auto; /* Restaura interacción */
    position: absolute;
    top: 0;
    right: 0;
    width: 300px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    background: #fdfdfd !important; /* Asegura fondo sólido sin transparencias */
    box-sizing: border-box;
    animation: fadeSweep 0.2s ease-out;
}

/* Forzar despliegue correcto al remover .hidden */
.participants-section:not(.hidden) {
    display: flex !important;
    flex-direction: column;
}

.room-meta-section:not(.hidden) {
    display: flex !important;
    flex-direction: column;
}

/* Caja de Participantes */
.participants-section {
    padding: 15px;
    height: 300px; 
    min-height: 0;
}

.participants-section h3 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 16px;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
}

#participantsList {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-y: auto;
    flex: 1;
}

#participantsList li {
    padding: 5px 0;
    font-size: 13px;
    border-bottom: 1px dotted #eee;
}

/* Caja de Herramientas e Info */
.room-meta-section {
    padding: 15px;
    gap: 12px;
}

.info-meta p {
    margin: 0 0 6px 0;
    font-size: 13px;
}

.share-meta-box {
    display: flex;
    gap: 6px;
}

.share-meta-box input {
    flex: 1;
    font-size: 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    padding: 4px 6px;
}

/* Componente del Indicador de Red */
.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: #666;
}

.signal-online { color: #2ecc71; }
.signal-connecting { color: #f1c40f; }
.signal-offline { color: #e74c3c; }

.signal-connecting {
    animation: pulseSignal 1s infinite alternate;
}

/* ==========================================================================
   BOTONES DE CONTROL Y COMPONENTES ADICIONALES
   ========================================================================== */
.danger {
    background: #fff;
    color: #b00000;
    border: 1px solid #b00000;
    width: 100%; 
    padding: 8px;
    border-radius: 4px;
}

.danger:hover {
    background: #b00000;
    color: #fff;
}

/* ==========================================================================
   SELECTOR DE EMOJIS (PICMO)
   ========================================================================== */
#emojiPickerWrapper {
    position: absolute !important;
    bottom: 42px !important;
    left: 0 !important;
    z-index: 9999 !important;
}

#emojiPickerWrapper .picmo__picker,
#emojiPickerWrapper .picker-container,
#emojiPickerWrapper [data-picker] {
    --picker-width: 280px !important;
    --picker-height: 320px !important;
    width: 280px !important;               
    height: 320px !important;              
    background-color: #ffffff !important;
    font-size: 13px !important;            
    border-radius: 4px !important; /* CORREGIDO: Redondeo sutil aplicado también a la caja del popup */
    border: 1px solid #ccc !important;     
    box-shadow: 2px 2px 0px rgba(0, 0, 0, 0.1) !important;
}

#emojiBtn {
    background: #f7f7f7;
    color: #551A8B;
    border: 1px solid #ccc;
    border-radius: 4px; /* CORREGIDO: Redondeo sutil aplicado */
    padding: 6px 10px;
    cursor: pointer;
}

/* ==========================================================================
   FOOTER
   ========================================================================== */
.app-footer {
    text-align: center;
    padding: 10px 20px;
    font-size: 0.8rem;
    color: #666;
    border-top: 1px solid #eee;
    background: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    width: 100%;
    box-sizing: border-box;
}

.app-footer p {
    margin: 0;
}

.disclaimer {
    cursor: help;
    border-bottom: 1px dotted #999;
    transition: color 0.2s, border-color 0.2s;
}

.disclaimer:hover {
    color: #551A8B; 
    border-bottom: 1px solid #551A8B;
}

.disclaimer span {
    font-size: 0.65rem;
    text-decoration: underline;
    margin-left: 4px;
}

/* ==========================================================================
   VU METER COMPACTO
   ========================================================================== */
.vu-container {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 8px;
    height: 32px;
    align-self: center;
    gap: 2px;
    margin-right: 2px;
}

.vu-bar {
    flex: 1;
    width: 100%;
    background-color: #ccc;
    opacity: 0.25;
    transition: opacity 0.05s ease;
}

.vu-bar.vu-green.lit  { background-color: #2ecc71; opacity: 1; box-shadow: 0 0 4px #2ecc71; }
.vu-bar.vu-yellow.lit { background-color: #f1c40f; opacity: 1; box-shadow: 0 0 4px #f1c40f; }
.vu-bar.vu-red.lit    { background-color: #e74c3c; opacity: 1; box-shadow: 0 0 4px #e74c3c; }

/* ==========================================================================
   RESPONSIVIDAD ESTRICTA PARA TELÉFONOS (MÓVIL)
   ========================================================================== */
@media (max-width: 768px) {
    h1 {
        font-size: 4rem;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        -webkit-text-stroke: 0.5px #000000;
    }

    body:has(#room:not(.hidden)) h1 {
        font-size: 2.2rem;
    }

    /* En móviles se mantiene arriba en un flujo limpio */
    .room-controls {
        top: 0; 
        margin-bottom: 8px;
    }

    .main-wrapper {
        padding: 10px;
    }

    body:has(#room:not(.hidden)) .main-wrapper {
        height: calc(100vh - 45px);
        padding: 8px;
    }

    .room-main-layout {
        flex-direction: column;
        gap: 0;
        overflow: hidden;
    }

    .chat-container {
        flex: 1;
        min-height: 0;
    }

    #messages {
        padding: 10px;
        margin-bottom: 8px;
    }

    .message {
        font-size: 15px;
    }

    select, button, input, #messageInput {
        font-size: 16px !important; 
    }

    #emojiBtn, #emojiPickerWrapper {
        display: none !important;
    }
   
    .sidebar-panel {
        max-width: 100%;
        min-width: 100%;
        top: 0;
    }

    .participants-section,
    .room-meta-section {
        width: 100% !important;
        max-height: 280px;
        position: relative;
        top: 0;
    }

    #participantsList {
        max-height: 200px;
    }

    button, #createRoom {
        padding: 8px 14px;
    }

    #createRoom {
        margin-left: 0;
        margin-top: 8px;
        width: 100%;
    }
}


.disclaimer {
    cursor: help;
    border-bottom: 1px dotted #999;
    transition: color 0.2s, border-color 0.2s;
    font-size: 0.75rem; /* Asegura que sea legible pero pequeño */
    color: #888;
}

.disclaimer:hover {
    color: #551A8B; 
    border-bottom: 1px solid #551A8B;
}

/* Opcional: si quieres que el "Legal" se vea como un botón minúsculo */
.disclaimer span {
    font-size: 0.6rem;
    text-transform: uppercase;
    font-weight: bold;
    margin-left: 4px;
    background: #eee;
    padding: 1px 4px;
    border-radius: 3px;
}
