/* ================================================== */
/* HEADER LIFECRAFTER - STYLES OPTIMISÉS            */
/* Compatible avec lifecrafter-auth.js v6.1.1        */
/* ================================================== */

/* ================================= */
/* VARIABLES CSS PERSONNALISÉES     */
/* ================================= */
:root {
  --header-height: 72px; /* Hauteur de l'en-tête */
  --nav-transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); /* Transition par défaut pour la navigation */
  --dropdown-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --dropdown-shadow-lg: 0 20px 50px -10px rgba(0, 0, 0, 0.15), 0 10px 20px -5px rgba(0, 0, 0, 0.08);
}

/* ================================= */
/* HEADER PRINCIPAL                  */
/* ================================= */
.header-main {
  position: relative;
  transition: var(--nav-transition);
}

.header-main.sticky {
  backdrop-filter: blur(10px); /* Effet de flou sur l'arrière-plan */
  -webkit-backdrop-filter: blur(10px); /* Compatibilité Webkit */
  background: rgba(var(--bgr-rgb, 255, 255, 255), 0.95); /* Couleur de fond avec opacité */
}

/* ================================= */
/* BRAND ET LOGO                     */
/* ================================= */
.header-brand .brand-link {
  display: flex;
  align-items: center;
  text-decoration: none;
  color: inherit;
  transition: var(--nav-transition);
}

.header-brand .brand-link:hover {
  transform: translateY(-1px); /* Léger déplacement vers le haut au survol */
}

/* ================================= */
/* NAVIGATION PRINCIPALE             */
/* ================================= */
.nav-main {
  transition: var(--nav-transition);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.nav-main:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); /* Ombre au survol */
}

/* --- GESTION DU FLICKERING ET DE L'AFFICHAGE JS (AJOUTS CLÉS) --- */

/* Conteneur des éléments de navigation Auth (Connexion / Profil)
   Initialement masqué par défaut pour éviter le flickering.
   JavaScript (.lifecrafter-auth.js) le révélera une fois l'état d'authentification connu. */
.nav-auth-hide-until-ready {
    display: none; /* Cache complètement la <ul> pour éviter le flash initial */
    opacity: 0;    /* Pour une transition d'opacité douce */
    transition: opacity 0.3s ease-out; /* Active une transition quand JS le révèle */
}

/* Classe ajoutée par JavaScript pour révéler le conteneur principal de navigation auth */
.nav-auth-hide-until-ready.is-ready {
    display: flex; /* Révèle le conteneur (ajustez à 'block' ou 'inline-flex' si votre layout le demande) */
    opacity: 1;
}

/* --- FIN GESTION DU FLICKERING ET DE L'AFFICHAGE JS --- */


/* États de chargement de la navigation principale (gérés par .lifecrafter-auth.js) */
.nav-auth-loading {
  opacity: 0.8;
  /* Si vous voulez masquer complètement la navigation pendant le chargement,
     vous pouvez ajouter ici : pointer-events: none; */
}

.nav-auth-ready {
  opacity: 1;
  transition: opacity 0.3s ease;
}

/* Éléments de navigation individuels */
.nav-item {
  position: relative;
}

.nav-main ul .nav-item.nav-current .nav-link {
  background-color: var(--color-background-tone);
  color: var(--color-typography);
  border-radius: var(--radius);
}

[data-nav=desktop] li.nav-current:not(:has(a[href="#"])){
    background-color: transparent !important;
    border-color: transparent !important;
}

.nav-current-auth .nav-link{
  position: relative;
  font-weight: 500;
  transition: var(--nav-transition);
  background: var(--brand);
  color: var(--brand-contrast);
  border-radius: var(--radius);
}

.nav-main .nav-link:hover {
  text-decoration: none;
  border-radius: var(--nav-border-radius);
}

.nav-link::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 2px;
  background: var(--brand); /* Utilisez la variable de votre thème */
  transition: var(--nav-transition);
  transform: translateX(-50%);
}

.nav-link:hover::before {
  width: 80%;
}

/* ================================= */
/* NAVIGATION AUTH - ÉTAT INVITÉ     */
/* ================================= */
.nav-auth-guest .nav-link {
  font-weight: 600;
  color: var(--brand);
  border: 1px solid var(--brand);
  background: transparent;
}

.nav-auth-guest .nav-link:hover {
  background: var(--brand);
  color: var(--brand-contrast);
}

/* ================================= */
/* BOUTON PROFIL UTILISATEUR         */
/* ================================= */
.nav-profile-button {
  position: relative;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: var(--nav-transition);
}

.nav-profile-button:focus {
  box-shadow: 0 0 0 2px rgba(var(--brand-rgb, 59, 130, 246), 0.2);
}

.nav-profile-button[aria-expanded="true"] {
  background: var(--bgr-tone);
  color: var(--brand);
}

.nav-profile-button[aria-expanded="true"] .dropdown-arrow {
  transform: rotate(180deg);
}

/* Icône profil avec badge */
.profile-icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.profile-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 2px solid var(--bgr);
  animation: pulse-premium 2s infinite;
}

@keyframes pulse-premium {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Nom utilisateur responsive */
.profile-name {
  transition: var(--nav-transition);
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown-arrow {
  transition: transform 0.2s ease;
}

/* ================================= */
/* MENU DÉROULANT PROFIL             */
/* ================================= */
.profile-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.5rem;
  background: #ffffff;;
  border: 1px solid #e5e7eb;;
  border-radius: 12px;
  box-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.25), 0 10px 20px -5px rgba(0, 0, 0, 0.1);
  z-index: 1001;
  min-width: 18rem;
  
  /* États d'animation et de visibilité par défaut */
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px) scale(0.98);
  transition: var(--nav-transition);
  pointer-events: none; /* Empêche les interactions quand masqué */
}

/* Cette règle est activée par JavaScript en retirant la classe 'hidden' */
.profile-dropdown.show, /* Votre JS ne l'ajoute pas, mais c'est une bonne pratique */
.profile-dropdown:not(.hidden) {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto; /* Permet les interactions quand visible */
}

/* En-tête du dropdown */
.dropdown-header {
  position: relative;
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  border-bottom: 1px solid #e2e8f0;
  padding: 1.25rem 1rem;
  border-radius: 12px 12px 0 0;
}

.dropdown-header::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, var(--brd) 50%, transparent 100%);
}

/* Informations utilisateur */
.dropdown-name {
  font-weight: 700;
  color: #1e293b; /* Gris foncé pour meilleur contraste */
  font-size: 1rem;
  line-height: 1.3;
  margin-bottom: 0.25rem;
}

.dropdown-email {
  color: #64748b; /* Gris moyen */
  font-size: 0.875rem;
  line-height: 1.3;
  margin-bottom: 0.75rem;
}

/* Badges de statut améliorés */
.dropdown-status {
  font-weight: 600;
  font-size: 0.75rem;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  
  /* Statut Gratuit */
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #cbd5e1;
}
.dropdown-status.premium,
.dropdown-status[class*="premium"] {
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  color: #ffffff;
  border: 1px solid #d97706;
  box-shadow: 0 2px 4px rgba(245, 158, 11, 0.2);
}
.dropdown-status:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ================================= */
/* SECTIONS DU MENU                  */
/* ================================= */
.dropdown-section + .dropdown-section {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid #f1f5f9;
}
.dropdown-item.logout:hover,
.dropdown-item[href*="logout"]:hover,
.dropdown-item:last-child:hover {
  background: #fef2f2;
  color: #dc2626;
  border-left-color: #dc2626;
}
.dropdown-item.logout:hover .material-symbols-outlined,
.dropdown-item[href*="logout"]:hover .material-symbols-outlined,
.dropdown-item:last-child:hover .material-symbols-outlined {
  color: #dc2626;
}
/* Items du menu */
.dropdown-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0.875rem 1rem;
  text-decoration: none;
  color: #374151;
  font-size: 0.9rem;
  font-weight: 500;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  text-align: left;
  font-family: inherit;
}

.dropdown-item:hover {
  background: #f8fafc;
  color: #1e293b;
  border-left: 3px solid var(--brand, #3b82f6);
  padding-left: 0.875rem;
  transform: none;
}

.dropdown-item:focus {
  outline: none;
  background: #eff6ff;
  color: #1d4ed8;
  border-left: 3px solid var(--brand, #3b82f6);
  padding-left: 0.875rem;
}

/* Items spéciaux */
.dropdown-item.group:hover .material-symbols-outlined {
  transform: scale(1.1);
}

/* Déconnexion avec état hover rouge */
.dropdown-item:hover.group {
  background: rgba(239, 68, 68, 0.05);
  color: rgb(239, 68, 68);
}
.dropdown-item .material-symbols-outlined {
  margin-right: 0.75rem;
  font-size: 1.25rem;
  color: #6b7280; /* Gris moyen pour les icônes */
  transition: color 0.15s ease;
}
.dropdown-item:hover .material-symbols-outlined {
  color: var(--brand, #3b82f6);
}
/* ================================= */
/* ZONE ACTIONS                      */
/* ================================= */
.header-actions {
  flex-shrink: 0;
}

.action-button {
  position: relative;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: var(--nav-transition);
}

.action-button:hover {
  transform: scale(1.05);
}

.action-button:focus {
  box-shadow: 0 0 0 2px rgba(var(--brand-rgb, 59, 130, 246), 0.2);
}

/* CTA Button */
.cta-button {
  position: relative;
  font-weight: 600;
  text-decoration: none;
  overflow: hidden;
  transition: var(--nav-transition);
}

.cta-button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s ease;
}

.cta-button:hover::before {
  left: 100%;
}

.cta-button:hover {
  text-decoration: none;
  transform: translateY(-1px);
}


/* ================================= */
/* MENU MOBILE                       */
/* ================================= */
.mobile-menu-toggle {
  background: transparent;
  border: none;
  cursor: pointer;
  transition: var(--nav-transition);
}

.hamburger-line {
  transition: var(--nav-transition);
}

.mobile-menu-toggle[aria-expanded="true"] .hamburger-line:first-child {
  transform: rotate(45deg) translate(3px, 3px);
}

.mobile-menu-toggle[aria-expanded="true"] .hamburger-line:last-child {
  transform: rotate(-45deg) translate(3px, -3px);
}

/* ================================= */
/* RESPONSIVE DESIGN                 */
/* ================================= */
@media (max-width: 640px) {
  .profile-dropdown {
    min-width: calc(100vw - 2rem);
    max-width: 20rem;
    margin-top: 0.25rem;
  }
  
  .dropdown-header {
    padding: 1rem;
  }
  
  .dropdown-item {
    padding: 1rem;
    font-size: 1rem;
  }
  
  .nav-link {
    padding: 0.5rem 0.75rem;
  }
  
  .profile-name {
    display: none;
  }
    .dropdown-item .material-symbols-outlined {
    font-size: 1.5rem;
    margin-right: 1rem;
  }
}

@media (max-width: 480px) {
  .profile-dropdown {
    min-width: calc(100vw - 2rem);
    max-width: 320px;
  }
  
  .nav-main {
    padding: 0.125rem;
  }
}

/* ================================= */
/* ANIMATIONS D'ENTRÉE              */
/* ================================= */
@keyframes slideInDown {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Anime le dropdown lorsqu'il passe de masqué à visible par JS (retrait de 'hidden') */
.profile-dropdown:not(.hidden) {
  animation: slideInDown 0.2s ease-out;
}

.profile-dropdown:not(.hidden) {
  animation: dropdownFadeIn 0.2s ease-out;
}

@keyframes dropdownFadeIn {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Amélioration des transitions */
.dropdown-item,
.dropdown-status {
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Meilleure lisibilité sur fond clair */
body.light-theme .profile-dropdown,
.profile-dropdown {
  background: #ffffff;
  color: #1f2937;
}

/* Force les couleurs pour une meilleure lisibilité */
.profile-dropdown * {
  text-shadow: none;
}

/* ================================= */
/* DARK MODE SUPPORT                 */
/* ================================= */
@media (prefers-color-scheme: dark) {
  .header-main.sticky {
    background: rgba(var(--bgr-rgb, 0, 0, 0), 0.95);
  }
  
  .profile-dropdown {
    background: #1f2937;
    border-color: #374151;
    box-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.5), 0 10px 20px -5px rgba(0, 0, 0, 0.3);
  }
  
  .dropdown-header {
    background: linear-gradient(135deg, #374151 0%, #4b5563 100%);
    border-bottom-color: #4b5563;
  }
  
  .profile-badge {
    border-color: var(--bgr);
  }
    .dropdown-name {
    color: #f9fafb;
  }
  
  .dropdown-email {
    color: #d1d5db;
  }
  
  .dropdown-status {
    background: #374151;
    color: #d1d5db;
    border-color: #4b5563;
  }
  
  .dropdown-item {
    color: #e5e7eb;
  }
  
  .dropdown-item:hover {
    background: #374151;
    color: #ffffff;
  }
  
  .dropdown-section + .dropdown-section {
    border-top-color: #374151;
  }
}

/* ================================= */
/* ÉTATS DE FOCUS ACCESSIBLES        */
/* ================================= */
.nav-profile-button:focus-visible,
.action-button:focus-visible,
.mobile-menu-toggle:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--theme-border-radius, 8px);
}

.dropdown-item:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
}

/* ================================= */
/* ANIMATIONS MICRO-INTERACTIONS     */
/* ================================= */
@keyframes fadeInScale {
  0% {
    opacity: 0;
    transform: scale(0.9);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.nav-auth-ready {
  animation: fadeInScale 0.3s ease-out;
}

/* Animation du badge premium */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.dropdown-status[class*="bg-brand"]:hover {
  background: linear-gradient(90deg, var(--brand), rgba(var(--brand-rgb, 59, 130, 246), 0.8), var(--brand));
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

/* ================================= */
/* OPTIMISATIONS PERFORMANCE         */
/* ================================= */
.profile-dropdown {
  contain: layout style paint;
}

.dropdown-item {
  contain: layout style;
}

/* Optimisation GPU pour les animations */
.nav-profile-button,
.dropdown-arrow,
.profile-dropdown,
.dropdown-item {
  will-change: transform;
}

.nav-profile-button:not(:hover),
.dropdown-item:not(:hover) {
  will-change: auto;
}

/* ================================= */
/* ÉTATS D'ERREUR ET DE LOADING      */
/* ================================= */
/* Ces règles sont pour l'icône de profil elle-même (le bouton) */
.nav-auth-loading .nav-profile-button {
  opacity: 0.7;
  pointer-events: none;
}

.nav-auth-loading .nav-profile-button::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid var(--typ-tone);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* État d'erreur */
.nav-auth-error .nav-profile-button {
  color: #dc2626;
  border-color: #dc2626;
}

.nav-auth-error .profile-badge {
  background: #dc2626;
  animation: pulse-error 1s infinite;
}

@keyframes pulse-error {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(0.9); }
}

/* ================================= */
/* AMÉLIORATIONS TYPOGRAPHIQUES      */
/* ================================= */
.dropdown-name {
  font-feature-settings: "kern" 1, "liga" 1;
}

.dropdown-email {
  font-feature-settings: "tnum" 1;
  font-variant-numeric: tabular-nums;
}

.dropdown-status {
  font-feature-settings: "smcp" 1;
  letter-spacing: 0.025em;
}

/* ================================= */
/* PRINT STYLES                      */
/* ================================= */
@media print {
  .header-main {
    position: static !important;
    box-shadow: none !important;
  }
  
  .profile-dropdown,
  .mobile-menu-toggle {
    display: none !important;
  }
  
  .nav-main {
    border: none !important;
    background: transparent !important;
  }
}

/* ================================= */
/* REDUCED MOTION SUPPORT            */
/* ================================= */
@media (prefers-reduced-motion: reduce) {
  .nav-profile-button,
  .dropdown-arrow,
  .profile-dropdown,
  .dropdown-item,
  .nav-link,
  .action-button,
  .cta-button {
    transition: none;
  }
  
  .profile-badge {
    animation: none;
  }
  
  .profile-dropdown:not(.hidden) {
    animation: none;
  }
  
  .nav-auth-ready {
    animation: none;
  }
}

/* ================================= */
/* ÉTATS SPÉCIAUX GHOST              */
/* ================================= */

/* Navigation active/current */
.nav-current-auth .nav-link {
  background: var(--brand);
  color: var(--brand-contrast);
}

.nav-current-auth .nav-link:hover {
  background: var(--brand);
  opacity: 0.9;
}

/* Synchronisation Ghost + Supabase */
.nav-auth[data-sync-status="synced"] .profile-badge::after {
  content: '';
  position: absolute;
  top: -1px;
  right: -1px;
  width: 4px;
  height: 4px;
  background: #10b981;
  border-radius: 50%;
  border: 1px solid var(--bgr);
}

.nav-auth[data-sync-status="pending"] .profile-icon {
  opacity: 0.7;
}

.nav-auth[data-sync-status="error"] .profile-icon {
  opacity: 0.5;
  filter: grayscale(1);
}

/* ================================= */
/* MESSAGES D'AUTHENTIFICATION       */
/* ================================= */

/* Conteneur de messages (si présent) */
#auth-messages {
  position: fixed;
  top: var(--header-height);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1002;
  max-width: 90vw;
  width: 400px;
}

.alert {
  padding: 0.75rem 1rem;
  margin: 0.5rem 0;
  border-radius: var(--theme-border-radius, 8px);
  font-size: 0.875rem;
  font-weight: 500;
  animation: slideInFromTop 0.3s ease-out;
}

.alert-info {
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.2);
  color: #1e40af;
}

.alert-success {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.2);
  color: #065f46;
}

.alert-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: #991b1b;
}

@keyframes slideInFromTop {
  from {
    opacity: 0;
    transform: translate(-50%, -20px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* ================================= */
/* DEBUGGING HELPERS                 */
/* ================================= */

/* Mode debug pour développement */
[data-debug="true"] .nav-auth::before {
  content: attr(data-auth-state);
  position: absolute;
  top: -20px;
  left: 0;
  font-size: 10px;
  background: #000;
  color: #fff;
  padding: 2px 4px;
  border-radius: 2px;
  z-index: 1000;
}

[data-debug="true"] .nav-auth[data-member-id]::after {
  content: "ID: " attr(data-member-id);
  position: absolute;
  bottom: -20px;
  left: 0;
  font-size: 10px;
  background: var(--brand);
  color: white;
  padding: 2px 4px;
  border-radius: 2px;
  z-index: 1000;
}

/* ================================= */
/* COMPATIBILITÉ LEGACY              */
/* ================================= */

/* Ancien système de profil (rétrocompatibilité) */
#supabase-user-profile-menu {
  transition: var(--nav-transition);
}

#supabase-user-profile-menu.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.95);
}

#profile-dropdown.hidden {
  display: none !important;
}

/* Anciens boutons */
.supabase-guest-only {
  transition: var(--nav-transition);
}

.supabase-user-only {
  transition: var(--nav-transition);
}

/* ================================= */
/* OPTIMISATIONS FINALES             */
/* ================================= */

/* Préchargement des images */
.dropdown-header img {
  image-rendering: crisp-edges;
  image-rendering: -webkit-optimize-contrast;
}

/* Optimisation scroll */
.profile-dropdown {
  overscroll-behavior: contain;
}

/* Optimisation touch */
@media (hover: none) and (pointer: coarse) {
  .dropdown-item {
    min-height: 44px;
    padding: 0.875rem 1rem;
  }
  
  .nav-profile-button {
    min-height: 44px;
    min-width: 44px;
  }
  
  .action-button {
    min-height: 44px;
    min-width: 44px;
  }
}

/* ================================= */
/* VARIABLES CSS POUR CUSTOMISATION  */
/* ================================= */

/* Variables exposées pour personnalisation */
.nav-main {
  --nav-border-radius: var(--theme-border-radius, 8px);
  --nav-padding: 0.25rem;
  --nav-gap: 0.125rem;
  --nav-transition-duration: 0.2s;
  --nav-hover-bg: var(--bgr-tone);
  --nav-hover-color: var(--brand);
}

.profile-dropdown {
  --dropdown-border-radius: var(--theme-border-radius, 8px);
  --dropdown-shadow: var(--dropdown-shadow-lg);
  --dropdown-bg: var(--bgr);
  --dropdown-border: var(--brd);
  --dropdown-item-hover: var(--bgr-tone);
  --dropdown-width: 16rem;
}

/* ================================= */
/* FIN DU FICHIER CSS               */
/* ================================= */