/* ==========================================
   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;
}