/* ==========================================================================
   CONFIGURATION ET VARIABLES
   ========================================================================== */
:root {
    --background-color: #121212;
    --surface-color: #1e1e1e;
    --primary-color: #9333ea;
    --primary-variant-color: #7e22ce;
    --on-background-color: #e0e0e0;
    --on-surface-color: #cccccc;
    --error-color: #cf6679;
    --success-color: #03dac6;
    
    --font-main: 'Inter', sans-serif;
}

/* ==========================================================================
   STYLES DE BASE ET MISE EN PAGE
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
}
body {
    font-family: var(--font-main);
    margin: 0;
    background-color: var(--background-color);
    color: var(--on-background-color);
    overflow: hidden;
    
    height: 100vh; /* Fallback pour vieux navigateurs */
    height: 100dvh; /* La vraie solution moderne */
    
    overscroll-behavior: none; 
    -webkit-tap-highlight-color: transparent;
}
.app-container {
    width: 100%;
    max-width: 450px;
    
    height: 100vh; /* Fallback */
    height: 100dvh; /* S'adapte aux barres du navigateur */
    
    background-color: var(--background-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    margin: 0 auto;

    padding-top: env(safe-area-inset-top); 
    padding-bottom: env(safe-area-inset-bottom);
}

.friends-content { 
    flex-grow: 1; 
    display: flex; 
    flex-direction: column; 
    min-height: 0; /* AJOUTEZ CETTE LIGNE IMPÉRATIVEMENT */
}

.main-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    margin-bottom: 16px; 
    position: relative; 
}

.live-clock {
    position: absolute; /* On la sort du flux pour la centrer */
    left: 50%;
    transform: translateX(-50%); /* Centrage parfait */
    font-size: 1.1rem; /* Plus petit (était 1.5rem) */
    font-weight: 600;
    color: var(--on-background-color);
    letter-spacing: 1px;
    font-variant-numeric: tabular-nums;
    pointer-events: none; /* Empêche de cliquer dessus par erreur */
}

.score-description {
    text-align: center;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-top: 0;
    margin-bottom: 24px;
    padding: 0 16px;
    min-height: 1.5em; /* Empêche la page de sauter si le texte change de taille */
    transition: opacity 0.2s ease;
}

/* ==========================================================================
   GESTION DES VUES (ÉCRANS)
   ========================================================================== */
.view {
    padding: 24px;
    position: absolute;
    inset: 0;
    opacity: 0;
    transform: scale(0.98);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    text-align: center;
}
.view.active-view {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}
#main-view {
    justify-content: space-between;
}
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 16px;
}
.main-actions {
    padding-bottom: 24px;
}

/* ==========================================================================
   TYPOGRAPHIE
   ========================================================================== */
h1 { font-size: 2rem; margin: 0; }
h2 { font-size: 1.5rem; color: var(--primary-color); margin-bottom: 24px; }
h3 { font-size: 1.1rem; color: var(--on-background-color); margin-bottom: 16px; }
p { color: var(--on-surface-color); font-size: 1rem; margin: 0; }

/* ==========================================================================
   COMPOSANTS DIVERS (SLIDER, BOUTONS, ETC.)
   ========================================================================== */
.score-input-container { position: relative; width: 260px; height: 260px; margin: 24px auto; display: flex; justify-content: center; align-items: center; }
#score-value-display { position: absolute; font-size: 3.5rem; font-weight: 600; color: var(--on-background-color); user-select: none; pointer-events: none; z-index: 10; }
.rs-control .rs-bg-color { background-color: var(--surface-color); }
.rs-range-color { background-color: var(--primary-color); }
.rs-path-color { background-color: #444; }
.rs-handle { background-color: #ffffff; padding: 4px; border: 4px solid var(--primary-color); }
.rs-tooltip-text { display: none !important; }
.btn { padding: 16px 32px; font-size: 1rem; font-weight: 600; border: none; border-radius: 99px; cursor: pointer; transition: all 0.2s ease; margin: 8px auto; width: 80%; max-width: 320px; display: block; }
.btn-primary { background-color: var(--primary-color); color: white; box-shadow: 0 4px 15px rgba(147, 51, 234, 0.2); }
.btn-primary:hover { background-color: var(--primary-variant-color); transform: translateY(-2px); }
.btn-primary:disabled { background-color: #444; cursor: not-allowed; }
.btn-secondary { background-color: var(--surface-color); color: var(--on-surface-color); }
.btn-secondary:hover { background-color: #333; }
.btn-icon { background: none; border: none; color: var(--on-surface-color); cursor: pointer; padding: 8px; border-radius: 50%; position: relative; display: flex; justify-content: center; align-items: center; width: 40px; height: 40px; }
.btn-icon:hover { background-color: rgba(255, 255, 255, 0.1); color: var(--primary-color); }
.btn-danger { width: 100%; background-color: var(--error-color); color: white; }
.btn-danger:hover { background-color: #b04f5f; }
.btn-link { background: none; border: none; color: var(--primary-color); cursor: pointer; font-size: 0.9rem; padding: 0; }

/* ==========================================================================
   HEADERS ET NAVIGATION
   ========================================================================== */
.main-header, .history-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.history-header h2 { margin-bottom: 0; }
#welcome-message { font-size: 1rem; color: var(--on-surface-color); }
.header-actions { display: flex; gap: 8px; align-items: center; }

/* *** CORRECTION APPLIQUÉE ICI *** */
/* Style spécifique pour le bouton profil afin qu'il gère une image sans padding */
#profile-btn {
    padding: 0;
    overflow: hidden;
}

/* Style pour l'image de profil DANS le bouton du header */
#profile-btn .profile-picture-icon {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ==========================================================================
   VUE HISTORIQUE & LISTES
   ========================================================================== */
#history-view { overflow: hidden; }
.history-content { flex-grow: 1; display: flex; flex-direction: column; min-height: 0; }
.chart-container { flex-shrink: 0; height: 250px; position: relative; }
.list-container { flex-shrink: 1; overflow: hidden; transition: max-height 0.5s ease-in-out, opacity 0.5s ease-in-out; max-height: 0; opacity: 0; }
.list-container.visible { max-height: 50vh; opacity: 1; }
#scores-list { height: 100%; overflow-y: auto; padding-right: 10px; }
.day-group { background-color: var(--surface-color); border-radius: 16px; padding: 16px; margin-bottom: 16px; text-align: left; }
.day-group h3 { margin: 0 0 12px 0; color: var(--primary-color); font-size: 1rem; border-bottom: 1px solid #333; padding-bottom: 12px; display: flex; justify-content: space-between; align-items: center; }
.score-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 8px; border-bottom: 1px solid #2c2c2c; }
.score-item:last-child { border-bottom: none; }
.score-time { font-size: 0.9rem; color: var(--on-surface-color); }
.score-value { font-size: 1.1rem; font-weight: 600; }
.score-actions { display: flex; gap: 8px; }

/* ==========================================================================
   FILTRE DU GRAPHIQUE
   ========================================================================== */
.chart-filter-dropdown { position: relative; display: inline-block; margin-bottom: 16px; width: 100%; }
.btn-dropdown { display: flex; justify-content: space-between; align-items: center; width: 100%; }
.dropdown-panel { display: none; position: absolute; background-color: var(--surface-color); box-shadow: 0 8px 16px 0 rgba(0,0,0,0.5); border-radius: 12px; padding: 12px; z-index: 10; width: 100%; max-height: 200px; overflow-y: auto; border: 1px solid #333; margin-top: 8px; text-align: left; }
.dropdown-panel.visible { display: block; }
.dropdown-actions { display: flex; justify-content: space-between; padding-bottom: 8px; margin-bottom: 8px; border-bottom: 1px solid #333; }
.filter-item { display: flex; align-items: center; padding: 8px; cursor: pointer; border-radius: 4px; transition: background-color 0.2s ease; }
.filter-item:hover { background-color: #333; }
.filter-item label { cursor: pointer; flex-grow: 1; }
.filter-item input[type="checkbox"] { margin-right: 12px; cursor: pointer; }

/* ==========================================================================
   MODALES ET SCROLLBAR
   ========================================================================== */
.modal-overlay { position: fixed; inset: 0; background-color: rgba(0, 0, 0, 0.7); display: flex; justify-content: center; align-items: center; z-index: 1000; opacity: 0; pointer-events: none; transition: opacity 0.3s ease; }
.modal-overlay.visible { opacity: 1; pointer-events: auto; }
.modal-content { background-color: var(--surface-color); padding: 24px; border-radius: 16px; width: 90%; max-width: 350px; text-align: center; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3); transform: scale(0.95); transition: transform 0.3s ease; }
.modal-overlay.visible .modal-content { transform: scale(1); }
.modal-content h3 { margin: 0 0 16px 0; color: var(--on-background-color); }
.modal-input { width: 100%; padding: 12px; font-size: 1.2rem; text-align: center; background-color: var(--background-color); border: 1px solid #444; color: var(--on-background-color); border-radius: 8px; margin-bottom: 24px; }
.modal-actions { display: flex; justify-content: space-between; gap: 16px; }
.modal-actions .btn { width: 100%; margin: 0; }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #555; border-radius: 3px; }

/* ==========================================================================
   STYLES POUR L'AUTHENTIFICATION ET LE PROFIL
   ========================================================================== */
#auth-view { justify-content: center; }
.auth-container { width: 100%; max-width: 320px; margin: 0 auto; }
#auth-form { display: flex; flex-direction: column; gap: 16px; margin: 24px 0; }
.error-message { color: var(--error-color); background-color: rgba(207, 102, 121, 0.1); border: 1px solid var(--error-color); border-radius: 8px; padding: 12px; margin-bottom: 16px; font-size: 0.9rem; display: none; }
.form-extra-options { display: flex; justify-content: center; align-items: center; margin-bottom: 16px; font-size: 0.9rem; color: var(--on-surface-color); }
.form-extra-options label { cursor: pointer; display: flex; align-items: center; gap: 8px; }
.form-extra-options input[type="checkbox"] { cursor: pointer; }
#profile-view {
    justify-content: flex-start;
    overflow-y: auto; /* PERMET LE SCROLL SUR LA PAGE PROFIL */
}
.profile-content { text-align: left; margin-top: 24px; }
.profile-section { background-color: var(--surface-color); border-radius: 16px; padding: 24px; margin-bottom: 24px; }
.profile-section h3 { margin-top: 0; color: var(--primary-color); }
.profile-picture-section { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.profile-picture { width: 120px; height: 120px; border-radius: 50%; object-fit: cover; border: 4px solid var(--surface-color); box-shadow: 0 4px 10px rgba(0,0,0,0.2); }
#upload-picture-form { display: flex; flex-direction: column; align-items: center; gap: 16px; }
#upload-picture-form .btn { width: auto; padding: 12px 24px; }
.accordion { margin-bottom: 24px; }
.accordion-header { background-color: var(--surface-color); color: var(--on-background-color); cursor: pointer; padding: 18px 24px; width: 100%; border: none; text-align: left; outline: none; font-size: 1rem; font-weight: 600; transition: all 0.3s ease; display: flex; justify-content: space-between; align-items: center; border-radius: 16px; }
.accordion-header:hover { background-color: #333; }
.accordion-header.active { background-color: #333; border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.accordion-header .material-icons { transition: transform 0.3s ease; }
.accordion-header.active .material-icons { transform: rotate(180deg); }
.accordion-panel { max-height: 0; overflow: hidden; transition: max-height 0.3s ease-out; margin-bottom: 8px; }
.accordion-panel .profile-section { margin-bottom: 0; border-top-left-radius: 0; border-top-right-radius: 0; }

/* ==========================================================================
   STYLES POUR LA PAGE AMIS
   ========================================================================== */
#friends-view { justify-content: flex-start; }
.friends-content { flex-grow: 1; display: flex; flex-direction: column; }
.tabs { display: flex; border-bottom: 1px solid #333; margin-bottom: 24px; }
.tab-link { background: none; border: none; color: var(--on-surface-color); padding: 14px 16px; cursor: pointer; font-size: 1rem; font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -1px; position: relative; }
.tab-link.active { color: var(--primary-color); border-bottom-color: var(--primary-color); }
.badge { background-color: var(--primary-color); color: white; font-size: 0.7rem; padding: 2px 6px; border-radius: 50%; position: absolute; top: 8px; right: 0px; display: none; }
.tab-content { display: none; flex-grow: 1; overflow-y: auto; }
.tab-content.active { display: block; }
.search-container { margin-bottom: 16px; }
.user-list { display: flex; flex-direction: column; gap: 12px; }
.user-item { background-color: var(--surface-color); border-radius: 12px; padding: 12px; display: flex; align-items: center; gap: 16px; transition: background-color 0.2s ease; }
.user-item.clickable:hover { background-color: #333; cursor: pointer; }
.user-item-avatar { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; }
.user-item-info { flex-grow: 1; text-align: left; display: flex; flex-direction: column; justify-content: center; }
.user-item-info strong { font-weight: 600; }
.user-item-info small { font-size: 0.8rem; color: var(--on-surface-color); font-weight: 400; }
.user-item-actions { display: flex; gap: 8px; }
.user-item-actions .btn-icon { background-color: #333; }
.user-item-actions .btn-icon.accept { color: var(--success-color); }
.user-item-actions .btn-icon.decline { color: var(--error-color); }
.suggestions-container { margin-top: 32px; text-align: left; }
.suggestions-container h3 { font-size: 1rem; color: var(--on-surface-color); margin-bottom: 16px; padding-bottom: 8px; border-bottom: 1px solid #333; }

/* ==========================================================================
   STYLES POUR LA MODALE D'INFORMATION ET NOTIFICATIONS
   ========================================================================== */
#info-btn { margin-right: auto; }
.info-content { text-align: left; margin: 24px 0; font-size: 0.95rem; line-height: 1.6; }
.info-content p { margin-bottom: 16px; }
.info-signature { margin-top: 24px; font-size: 0.85rem; text-align: center; color: var(--on-surface-color); opacity: 0.8; }
#close-info-modal-btn { width: 100%; }
.btn-icon.has-notification::after { content: ''; position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; background-color: var(--error-color); border-radius: 50%; border: 2px solid var(--background-color); }

/* ==========================================================================
   STYLES POUR LES SOIRÉES COMMUNES
   ========================================================================== */
#friend-profile-view { justify-content: flex-start; }
#friend-profile-username { margin-top: 0; color: var(--on-background-color); }
.evening-item { background-color: var(--surface-color); border-radius: 12px; padding: 16px; text-align: left; cursor: pointer; transition: background-color 0.2s ease; border-left: 4px solid var(--primary-color); }
.evening-item:hover { background-color: #333; }
.evening-item .date { font-weight: 600; font-size: 1.1rem; margin-bottom: 8px; }
.evening-item .names { font-size: 0.9rem; color: var(--on-surface-color); }

#shared-evening-view { justify-content: flex-start; overflow: hidden; }
#shared-evening-view .chart-container { height: 300px; flex-shrink: 0; }
.attendees-container { margin-top: 24px; text-align: left; background-color: var(--surface-color); border-radius: 16px; padding: 16px; flex-grow: 1; overflow-y: auto; min-height: 0; }
.attendees-container h3 { margin-top: 0; font-size: 1rem; color: var(--on-background-color); border-bottom: 1px solid #333; padding-bottom: 12px; margin-bottom: 12px; }
.attendees-container .user-item { background-color: transparent; padding: 8px; }

/* ==========================================================================
   STYLES POUR LA DESCRIPTION DU PROFIL
   ========================================================================== */
.profile-description-section { padding: 16px 24px; }
#description-display { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
#profile-description-text { flex-grow: 1; font-style: italic; color: var(--on-surface-color); text-align: left; white-space: pre-wrap; }
#profile-description-textarea { margin-bottom: 16px; height: 100px; resize: vertical; text-align: left; }
.description-actions { display: flex; gap: 16px; justify-content: flex-end; }
.description-actions .btn { width: auto; padding: 10px 20px; margin: 0; }
#friend-profile-description-text { text-align: center; width: 100%; font-style: italic; color: var(--on-surface-color); white-space: pre-wrap; }