/* ==========================================
   RESET & BASE GLOBALE
   ========================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f8f5fa;
    color: #2c1b38;
    text-align: center;
    padding: 0;
    margin: 0;
    line-height: 1.5;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* ==========================================
   GESTION DES VUES (ROUTAGE)
   ========================================== */
.view {
    display: none;
    max-width: 500px;
    margin: 0 auto;
    padding: 20px;
    /* safe-area-inset évite que ton titre soit caché par l'encoche (notch) de l'iPhone */
    padding-top: calc(20px + env(safe-area-inset-top)); 
    background: transparent;
    height: 100%;
    overflow-y: auto;
}

.view.active {
    display: block;
    animation: fadeIn 0.3s ease-out; /* Petite animation d'apparition douce */
}

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

/* ==========================================
   TYPOGRAPHIE
   ========================================== */
h1 {
    color: #5e35b1; /* Mauve principal */
    margin-bottom: 25px;
    font-size: 24px;
}

h2 {
    color: #4527a0;
    font-size: 18px;
    margin-bottom: 10px;
}

/* ==========================================
   FORMULAIRES (Inputs & Boutons)
   ========================================== */
input[type="text"],
input[type="number"],
input[type="password"] {
    width: 100%;
    padding: 14px 15px;
    margin: 10px 0;
    border: 2px solid #d1c4e9; /* Bordure mauve très clair */
    border-radius: 10px;
    font-size: 15px;
    background-color: #ffffff;
    color: #2c1b38;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus {
    outline: none;
    border-color: #7e57c2; /* Bordure mauve vif au focus */
    box-shadow: 0 0 0 3px rgba(126, 87, 194, 0.2);
}

button {
    width: 100%;
    padding: 15px;
    margin-top: 15px;
    background-color: #7e57c2; /* Mauve vif */
    color: #ffffff;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

button:hover {
    background-color: #5e35b1;
}

button:active {
    transform: scale(0.98); /* Effet d'enfoncement au clic */
}

button:disabled {
    background-color: #b39ddb;
    cursor: not-allowed;
    transform: none;
}

/* Bouton de danger (Déconnexion) */
#unlockLogoutBtn {
    background-color: #e53935;
    margin-top: 30px;
}

#unlockLogoutBtn:hover {
    background-color: #c62828;
}

/* ==========================================
   ÉCRAN CONTACTS
   ========================================== */
.profile-box {
    background-color: #ede7f6;
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 30px;
    border: 1px solid #d1c4e9;
    text-align: left;
}

.profile-box p {
    font-size: 14px;
    margin: 5px 0;
    word-break: break-all; /* Empêche les longs UUID/Hash de déborder */
}

#contactsList {
    list-style: none;
    margin-top: 20px;
    margin-bottom: 30px;
}

#contactsList li {
    background: #ffffff;
    padding: 16px;
    margin-bottom: 12px;
    border-radius: 10px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.04);
    cursor: pointer;
    font-weight: 600;
    color: #4527a0;
    transition: transform 0.2s, box-shadow 0.2s;
    text-align: left;
}

#contactsList li:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(126, 87, 194, 0.15);
}

/* ==========================================
   AJUSTEMENTS POUR LE MODE PLEIN ÉCRAN
   ========================================== */

#view-chat.active {
    display: flex;
    flex-direction: column;
    max-width: 100%;
    padding: 0;
    padding-top: env(safe-area-inset-top);
    background-color: #f8f5fa;
    overflow: hidden;
}

/* ==========================================
   TOP BAR (En-tête)
   ========================================== */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    z-index: 10;
}

.chat-header h1 {
    margin: 0;
    font-size: 18px;
    flex: 1; /* Pousse le texte au centre */
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ==========================================
   BOUTONS ICÔNES (Flèche, Refresh, Image, Avion)
   ========================================== */
.icon-btn {
    background: transparent;
    color: #7e57c2; /* Ton mauve */
    border: none;
    font-size: 22px;
    padding: 5px 10px;
    margin: 0;
    width: auto;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: transparent;
    color: #5e35b1;
    transform: scale(1.1);
}

.icon-btn:active {
    transform: scale(0.9);
}

/* ==========================================
   ZONE DES MESSAGES
   ========================================== */
#chat-box {
    flex: 1; /* Remplit automatiquement tout l'espace disponible au milieu */
    padding: 10px 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    /* Suppression des bordures et ombres pour unifier avec le fond */
    background-color: #f8f5fa;
    border: none;
    box-shadow: none;
    margin-bottom: 0;
}

/* Les bulles de messages */
.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
    position: relative;
    text-align: left;
}

.message.left.received {
    align-self: flex-start; /* Aligne à gauche */
    background-color: #f1f0f5; /* Gris très clair */
    color: #312a38;
    border-bottom-left-radius: 4px; /* Rend le coin inférieur gauche pointu */
}

.message.right.sent {
    align-self: flex-end; /* Aligne à droite */
    background-color: #7e57c2; /* Ton mauve */
    color: #ffffff;
    border-bottom-right-radius: 4px; /* Rend le coin inférieur droit pointu */
}

/* ==========================================
   ZONE DE SAISIE (Bottom bar)
   ========================================== */
.chat-input-area {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    background-color: #f8f5fa;
    /* safe-area-inset évite que la barre soit cachée par la barre d'accueil de l'iPhone */
    padding-bottom: calc(15px + env(safe-area-inset-bottom)); 
}

.chat-input-area input {
    flex: 1;
    margin: 0;
    border-radius: 20px; /* Plus arrondi pour ressembler à un vrai chat */
    padding: 12px 18px;
    border: 1px solid #d1c4e9;
    background-color: #ffffff;
}

.chat-input-area input:focus {
    border-color: #7e57c2;
}

/* ==========================================
   FLEXBOX UTILITAIRES
   ========================================== */
.flex-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}

.flex-col {
    display: flex;
    flex-direction: column;
    gap: 15px; /* Espace automatique entre les éléments enfants */
}

/* ==========================================
   EN-TÊTES D'ÉCRANS
   ========================================== */
.screen-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0 20px 0;

    position: sticky;
    top: 0;
    background-color: #f8f5fa;
    z-index: 10;
}

.screen-header h1 {
    margin: 0;
    font-size: 20px;
}

/* ==========================================
   BOUTON "+" DANS LA LISTE DE CONTACTS
   ========================================== */
.add-contact-item {
    background-color: transparent !important;
    border: 2px dashed #b39ddb;
    color: #7e57c2 !important;
    text-align: center !important;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    padding: 10px !important;
}

.add-contact-item:hover {
    background-color: rgba(126, 87, 194, 0.05) !important;
}

/* ==========================================
   CARTES DE PARAMÈTRES
   ========================================== */
.settings-group {
    padding: 10px 0;
}

.setting-card {
    background: #ffffff;
    padding: 20px;
    border-radius: 12px;
    border: 1px solid #d1c4e9;
    box-shadow: 0 2px 6px rgba(0,0,0,0.02);
}

.setting-card label {
    font-weight: 600;
    color: #4527a0;
}

/* Personnalisation basique du slider (range) */
input[type=range] {
    width: 100%;
    margin-top: 10px;
    accent-color: #7e57c2; /* Teinte la barre en mauve (navigateurs modernes) */
}

input[type=checkbox] {
    width: 20px;
    height: 20px;
    accent-color: #7e57c2;
}

/* ==========================================
   DROPDOWN TELEPHONE
   ========================================== */
.call-dropdown {
    position: absolute;
    top: 45px;
    right: 35px; /* Décalé pour ne pas passer sous le bouton refresh */
    background-color: #ffffff;
    border: 1px solid #d1c4e9;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(126, 87, 194, 0.15);
    min-width: 220px;
    z-index: 100;
    text-align: left;
}
.call-dropdown ul {
    list-style: none;
    padding: 0;
    margin: 0;
}
.call-dropdown li {
    padding: 12px 15px;
    border-bottom: 1px solid #f1f0f5;
    color: #4527a0;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.2s;
}
.call-dropdown li:last-child {
    border-bottom: none;
}
.call-dropdown li:hover {
    background-color: #f8f5fa;
}
.call-dropdown li.empty-call {
    color: #e53935; /* Rouge erreur */
    cursor: not-allowed;
    text-align: center;
    font-weight: normal;
}
.call-dropdown li.empty-call:hover {
    background-color: #ffffff;
}

.voip-list-item{
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding: 8px;
    background-color: #f8f5fa;
    border-radius: 6px;
}

/* ==========================================
    APPEL VIDEO
   ========================================== */

.video-container {
    background-color: #111;
    padding: 0;
    position: relative;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

/* Vidéo de l'interlocuteur */
.video-remote {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Vidéo de l'utilisateur (vignette) */
.video-local {
    position: absolute;
    top: env(safe-area-inset-top, 20px);
    right: 20px;
    width: 110px;
    height: 150px;
    object-fit: cover;
    border-radius: 12px;
    border: 2px solid #7e57c2;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    z-index: 10;
}

/* Barre de contrôles */
.video-controls {
    position: absolute;
    bottom: calc(30px + env(safe-area-inset-bottom, 0px));
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 20px;
    z-index: 10;
}

/* Style de base des boutons ronds */
.video-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 25px;
    border: none;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.3s ease; /* Animation fluide lors du changement de couleur */
}

/* --- CLASSE POUR LE TOGGLE --- */
.video-btn-off {
    background: #ff3b30 !important;
    color: white !important;
}

/* ==========================================
   APPEL VOIP AUDIO (SANS CAMERA)
   ========================================== */

#view-voip-call.active {
    display: flex;
}

.voip-call-container {
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #2c1b38 0%, #1a0f2e 100%); /* Fond sombre basé sur tes couleurs */
    padding: 0;
    padding-top: calc(40px + env(safe-area-inset-top));
    padding-bottom: calc(40px + env(safe-area-inset-bottom));
    height: 100%;
    width: 100%;
    overflow: hidden;
}

/* En-tête : Nom et Status */
.voip-header {
    text-align: center;
    color: #ffffff;
    margin-top: 5vh;
    z-index: 10;
}

.voip-header h2 {
    color: #ffffff;
    font-size: 28px;
    margin-bottom: 5px;
    font-weight: 600;
}

.voip-header p {
    font-size: 16px;
    color: #d1c4e9; /* Ton mauve clair */
    opacity: 0.9;
    margin: 0;
}

/* Zone centrale de l'Avatar */
.voip-avatar-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1; /* Prend l'espace du milieu */
    width: 100%;
}

.voip-avatar {
    width: 130px;
    height: 130px;
    background-color: #7e57c2; /* Ton mauve vif */
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.voip-avatar svg {
    width: 65px;
    height: 65px;
    color: #ffffff;
}

/* Animation de pulsation (Ondes autour de l'avatar) */
.voip-pulse {
    position: absolute;
    width: 130px;
    height: 130px;
    background-color: #7e57c2;
    border-radius: 50%;
    z-index: 1;
    animation: voip-pulse-anim 2.5s infinite ease-out;
}

.voip-pulse.delay {
    animation-delay: 1.25s;
}

@keyframes voip-pulse-anim {
    0% { transform: scale(1); opacity: 0.7; }
    100% { transform: scale(2.5); opacity: 0; }
}

/* Contrôles du bas */
.voip-controls {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 2vh;
    z-index: 10;
    width: 100%;
}

/* Boutons ronds du VoIP */
.voip-btn {
    width: 65px;
    height: 65px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    font-size: 24px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px); /* Effet verre dépoli */
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    margin: 0;
}

.voip-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

.voip-btn:active {
    transform: scale(0.95);
}

/* Bouton Raccrocher rouge */
.voip-btn.hangup {
    background: #ff3b30;
    border-color: #ff3b30;
    transform: scale(1.1); /* Légèrement plus gros */
}

.voip-btn.hangup:hover {
    background: #e53935;
    transform: scale(1.15);
}

.voip-btn.hangup:active {
    transform: scale(1.05);
}

/* Classe pour l'état désactivé/off du micro ou haut-parleur */
.voip-btn.off {
    background: #ffffff;
    color: #2c1b38;
}

/* ==========================================
   TOASTS & ERREUR FATALE (gestion d'erreurs)
   ========================================== */
#toast-container {
    position: fixed;
    left: 0;
    right: 0;
    top: calc(10px + env(safe-area-inset-top));
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    z-index: 10000;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    max-width: 480px;
    width: fit-content;
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.4;
    color: #fff;
    background: #4527a0;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    animation: toastIn 0.25s ease-out;
    cursor: pointer;
}
.toast-error   { background: #c62828; }
.toast-warning { background: #ef6c00; }
.toast-success { background: #2e7d32; }
.toast-info    { background: #4527a0; }
.toast-hide    { opacity: 0; transform: translateY(-8px); transition: all 0.25s; }

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

#fatal-error-overlay {
    position: fixed;
    inset: 0;
    z-index: 20000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(248, 245, 250, 0.97);
}
#fatal-error-overlay .fatal-box { max-width: 360px; }
#fatal-error-overlay p { margin-bottom: 20px; }

/* Message illisible / corrompu dans le chat */
.message-error { font-style: italic; opacity: 0.8; }