/* ========================================== */
/* SECTION 1: VARIABLES & RESET */
/* ========================================== */
:root {
    --bg-color: #303030;
    --card-bg: #424242;
    --text-color: #ffffff;
    --accent: #4caf50; /* Green */
    --accent-yellow: #ffc107;
    --accent-red: #f44336;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    /* FIX MOBILE : On autorise le scroll naturel et on gère la hauteur min */
    min-height: 100vh; 
    overflow-y: auto; /* IMPORTANT : Scroll activé */
    display: flex;
    flex-direction: column;
}

/* ========================================== */
/* SECTION 2: HEADER (STICKY) */
/* ========================================== */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: rgba(48, 48, 48, 0.95); /* Légèrement transparent */
    backdrop-filter: blur(5px); /* Effet flou moderne */
    border-bottom: 1px solid rgba(255,255,255,0.1);
    
    /* FIX MOBILE : Le header reste collé en haut mais ne bloque pas le layout */
    position: sticky;
    top: 0;
    z-index: 50; 
}

.logo h1 { 
    font-size: 1.4rem; 
    font-weight: 500; 
    cursor: pointer;
}
.controls { display: flex; align-items: center; gap: 15px; }

.btn-text {
    background: none; border: none; 
    font-size: 1rem; color: #aaa; 
    cursor: pointer; font-weight: bold;
    text-transform: uppercase;
}
.btn-text:hover { color: #fff; }

.my-identity { display: flex; flex-direction: column; align-items: center; font-size: 0.8rem; cursor: pointer;}
.my-emoji { font-size: 1.5rem; }

/* ========================================== */
/* SECTION 3: MAIN PEER GRID (SCROLL NATUREL) */
/* ========================================== */
main {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    justify-content: center; 
    align-content: flex-start; 
    padding: 20px;
    padding-bottom: 100px; /* Espace pour ne pas cacher le dernier élément derrière le chat */
    gap: 30px;
    /* On enlève l'overflow ici, c'est le body qui scroll maintenant */
    width: 100%;
}

.peer {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s;
    width: 110px;
    /* Evite que les éléments se chevauchent sur petits écrans */
    margin-bottom: 10px;
}
.peer:active { transform: scale(0.95); }

.avatar-container { position: relative; width: 80px; height: 80px; }
.avatar {
    width: 100%; height: 100%;
    background: var(--card-bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

.status-led {
    position: absolute;
    bottom: 0; right: 0;
    width: 18px; height: 18px;
    border-radius: 50%;
    border: 3px solid var(--bg-color);
    box-shadow: 0 0 5px rgba(0,0,0,0.5);
}
.status-led.green { background-color: var(--accent); }
.status-led.yellow { background-color: var(--accent-yellow); }
.status-led.red { background-color: var(--accent-red); }

@keyframes pulse { 0% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.4); opacity: 0.7; } 100% { transform: scale(1); opacity: 1; } }
.status-led.blink { animation: pulse 0.5s ease-out; }

.peer-name { margin-top: 10px; font-weight: bold; text-align: center; font-size: 1rem; }
.peer-info { font-size: 0.75rem; color: #aaa; text-align: center; display: flex; flex-direction: column; margin-top: 2px;}

.wait-message { text-align: center; color: #666; margin-top: 50px;}
.radar {
    width: 60px; height: 60px; margin: 0 auto 20px;
    border: 2px solid var(--accent); border-radius: 50%;
    animation: radar-ping 2s infinite;
}
@keyframes radar-ping { 0% { transform: scale(0.5); opacity: 1; } 100% { transform: scale(2); opacity: 0; } }

/* ========================================== */
/* SECTION 4: CHAT INTERFACE */
/* ========================================== */
/* Bouton flottant pour rouvrir le chat */
.reopen-chat-btn {
    position: absolute;
    bottom: 20px; right: 20px;
    background: var(--accent); color: #000;
    width: 50px; height: 50px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    cursor: pointer; z-index: 90;
    border: none;
}

.chat-panel {
    position: fixed;
    bottom: 0; right: 0; width: 100%; 
    /* Modif Mobile : max 40% de l'écran pour voir le reste */
    height: 40vh; 
    background: var(--card-bg);
    display: flex; flex-direction: column;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -5px 20px rgba(0,0,0,0.5);
    z-index: 100;
}
@media (min-width: 768px) {
    .chat-panel { width: 350px; right: 20px; height: 450px; border-radius: 10px 10px 0 0; }
}
.hidden { display: none !important; }

.chat-header {
    padding: 10px 15px; background: rgba(0,0,0,0.2);
    display: flex; justify-content: space-between; align-items: center;
    font-weight: bold;
}
.chat-messages { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.message { max-width: 80%; padding: 8px 12px; border-radius: 15px; font-size: 0.9rem; word-wrap: break-word;}
.message.self { align-self: flex-end; background: var(--accent); color: #000; }
.message.other { align-self: flex-start; background: rgba(255,255,255,0.1); }
.message-audio { cursor: pointer; display: flex; align-items: center; gap: 5px; }

.chat-controls { padding: 10px; display: flex; gap: 10px; background: rgba(0,0,0,0.1); }
#chat-input { flex: 1; padding: 10px; border-radius: 20px; border: none; outline: none; }
.record-btn, .send-btn {
    width: 40px; height: 40px; border-radius: 50%; border: none;
    cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.record-btn { background: #f44336; color: white; }
.record-btn.recording { animation: pulse 1s infinite; background: #d32f2f; }
.send-btn { background: var(--accent); color: #000; }

/* ========================================== */
/* SECTION 5: MODALS */
/* ========================================== */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8); z-index: 1000;
    display: flex; justify-content: center; align-items: center;
}
.modal {
    background: var(--card-bg); padding: 25px; border-radius: 10px;
    width: 90%; max-width: 400px; text-align: center;
}
.modal h2 { margin-bottom: 15px; }
.modal input { width: 100%; padding: 12px; margin: 15px 0; border-radius: 5px; border: none; font-size: 1.1rem; text-align: center; }
.modal-footer { display: flex; justify-content: center; gap: 10px; margin-top: 15px; }
.btn { padding: 10px 20px; border-radius: 5px; border: none; cursor: pointer; font-weight: bold; font-size: 1rem;}
.btn.primary { background: var(--accent); color: #000; }
.btn.danger { background: var(--accent-red); color: white; }
.divider { margin: 15px 0; font-size: 0.8rem; color: #888; }
/* ========================================== */
/* STYLES MODALE & BOUTONS (Mise à jour) */
/* ========================================== */

/* Le champ de saisie du code */
#room-code-input {
    background: #333;
    border: 2px solid #555;
    color: white;
    padding: 15px;
    border-radius: 12px;
    width: 100%;
    margin-bottom: 10px;
    transition: border-color 0.3s;
}

#room-code-input:focus {
    outline: none;
    border-color: var(--accent); /* Le vert du site */
}

/* Style commun aux gros boutons */
#btn-join-room, #btn-create-room {
    padding: 16px 0; /* Plus de hauteur */
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 12px; /* Angles bien arrondis */
    border: none;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s, box-shadow 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2); /* Ombre légère */
}

/* Bouton REJOINDRE (Vert / Action Principale) */
#btn-join-room {
    background-color: var(--accent); /* #4caf50 */
    color: white;
}

/* Bouton CRÉER (Gris / Action Secondaire) */
#btn-create-room {
    background-color: #555; /* Gris plus clair que le fond */
    color: white;
    margin-top: 0 !important; /* On gère l'espace via le HTML si besoin */
}

/* Effet au survol (Hover) */
#btn-join-room:hover, #btn-create-room:hover {
    transform: translateY(-2px); /* Le bouton "monte" un peu */
    box-shadow: 0 6px 12px rgba(0,0,0,0.3); /* L'ombre grandit */
    opacity: 0.95;
}

/* Effet au clic (Active) */
#btn-join-room:active, #btn-create-room:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* ========================================== */
/* PROGRESS BAR */
/* ========================================== */
.progress-container {
    position: fixed;
    top: 60px; /* Ajuste selon la hauteur de ton header */
    left: 0;
    width: 100%;
    height: 30px;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    transition: opacity 0.3s;
}

.progress-container.hidden {
    display: none;
}

.progress-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background-color: var(--accent); /* Le vert du thème */
    width: 0%;
    transition: width 0.2s linear;
    z-index: 1;
}

.progress-text {
    position: relative;
    z-index: 2;
    color: white;
    font-weight: bold;
    font-size: 0.9rem;
    text-shadow: 0 1px 2px black;
}

/* NOTIFICATION CHAT (Badge Rouge) */
#reopen-chat.notify::after {
    content: '!';
    position: absolute;
    /* Ajustement de la position du badge par rapport au bouton */
    top: 0px;       
    right: 0px;
    
    background-color: #ff4444;
    color: white;
    width: 18px;    /* Un peu plus petit pour être discret */
    height: 18px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    border: 2px solid #222; /* Petit bord pour séparer du bouton */
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1001; /* S'assure qu'il est au dessus */
}

@keyframes popIn {
    from { transform: scale(0); }
    to { transform: scale(1); }
}

/* LISTE DU MESSAGE DE BIENVENUE */
#modal-welcome ul li {
    margin-bottom: 8px;
    list-style-type: disc; /* Force les points */
}

