/* ============================================================
   ECRAN DE CONNEXION (.auth-*) ET PROFIL (avatar, popup "Mon profil")
   Partagé par toutes les pages. Les styles génériques (variables, boutons,
   formulaires, modales, tableaux...) sont dans common.css, chargé avant.
   ============================================================ */

/* Pages protégées (body[data-nav] : index, settings, device, user) masquées
   jusqu'à la fin de la vérification de session (checkAuth ajoute
   .auth-checked) : sinon leur contenu (ex: la page Alertes) apparaît un
   instant avant que l'écran de connexion, chargé en asynchrone, ne soit
   injecté par-dessus.
   Cache plein écran par-dessus tout plutôt que visibility: hidden sur le
   body : un descendant peut annuler ce dernier (index.html force
   visibility: visible !important sur la liste et la carte en desktop). */
body[data-nav]:not(.auth-checked)::before {
    content: "";
    position: fixed;
    inset: 0;
    background: var(--bg-dark);
    z-index: 2147483647;
}

.auth-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(26, 26, 46, 0.98);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-container {
    background: var(--bg-card);
    padding: 40px 40px 32px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    max-width: 500px;
    width: 100%;
}

@media (max-width: 480px) {
    .auth-container { padding: 32px 22px 24px; }
}

.auth-container h2 {
    color: var(--primary);
    margin-bottom: 8px;
    font-size: 1.5rem;
}

.auth-container p {
    color: var(--text-muted);
    margin-bottom: 24px;
    font-size: 0.95rem;
}

.auth-field {
    width: 100%;
    padding: 12px 14px;
    margin-bottom: 12px;
    font-size: 1rem;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: var(--bg-dark);
    color: var(--text-primary);
    transition: border-color 0.2s;
    -webkit-appearance: none;
}

.auth-field:focus {
    outline: none;
    border-color: var(--primary);
}

.password-field-wrapper {
    position: relative;
    margin-bottom: 12px;
}

/* Cible n'importe quel input a l'interieur (pas seulement .auth-field) :
   reutilise sur user.html avec ses propres styles de champ. */
.password-field-wrapper input {
    margin-bottom: 0;
    padding-right: 44px;
    width: 100%;
    box-sizing: border-box;
}

.password-toggle-visibility {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.password-toggle-visibility svg {
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.password-toggle-visibility:hover {
    color: var(--text-primary);
}

.auth-error {
    color: #ef4444;
    font-size: 0.9rem;
    margin-bottom: 16px;
    min-height: 22px;
}

.auth-submit {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    touch-action: manipulation;
}

.auth-submit:hover,
.auth-submit:active {
    background: var(--primary-hover);
}

.auth-submit:disabled {
    background: #444;
    cursor: not-allowed;
}

/* Lien sous le formulaire de connexion ("Mot de passe oublié ?", "Retour à
   la connexion") et pages forgot-password.html / reset-password.html */
.auth-link {
    display: inline-block;
    margin-top: 16px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-decoration: none;
}

.auth-link:hover {
    color: var(--text-primary);
    text-decoration: underline;
}

.auth-container p.auth-success {
    color: var(--success);
    margin-bottom: 16px;
}

.auth-container p.auth-error-block {
    color: #ef4444;
    margin-bottom: 20px;
}

/* <a> avec l'apparence du bouton principal */
.auth-submit-link {
    display: block;
    text-decoration: none;
    box-sizing: border-box;
}

.auth-container .password-rules {
    text-align: left;
    margin-bottom: 12px;
}

.auth-container .password-mismatch {
    text-align: left;
    margin-top: -6px;
    margin-bottom: 4px;
}

.modal-error.profile-password-success {
    color: var(--success);
}

/* Regles de mot de passe en direct (tic vert quand la regle est remplie) */
.password-rules {
    list-style: none;
    margin: 8px 0 0;
    padding: 0;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.password-rules li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 0;
    transition: color 0.2s;
}

.password-rules .rule-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    border: 1.5px solid var(--text-muted);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, border-color 0.2s;
}

.password-rules li.ok { color: var(--success); }

.password-rules li.ok .rule-icon {
    background: var(--success);
    border-color: var(--success);
}

.password-rules .rule-icon svg {
    fill: none;
    stroke: var(--bg-dark);
    stroke-width: 3.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    width: 10px;
    height: 10px;
}

.password-mismatch {
    color: #ef4444;
    font-size: 0.8rem;
    margin-top: 6px;
    min-height: 16px;
}

/* Popup profil : section changement de mot de passe repliee par defaut */
.profile-password-section {
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.profile-password-open { width: 100%; }

.profile-password-section .modal-error.profile-password-success {
    margin-top: 8px;
    margin-bottom: 0;
    min-height: 0;
    text-align: center;
}

#profilePasswordForm h3 {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 14px;
}

.profile-password-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Avatar (navbar) et popup "Mon profil" */
.profile-avatar {
    width: 32px;
    height: 32px;
    margin-left: 16px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
    font-family: inherit;
    transition: background 0.2s;
}

.profile-avatar:hover {
    background: var(--primary-hover);
}

.profile-info {
    margin-bottom: 16px;
}

.profile-info-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.profile-info-row:last-child {
    border-bottom: none;
}

.profile-info-label {
    color: var(--text-secondary);
}

.profile-note {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 12px;
}
