/* =====================================================
   STYLES POUR LE WIDGET D'AUTHENTIFICATION - HEADER
   ===================================================== */

/* Sur desktop LARGE uniquement : positionnement absolu */
@media (min-width: 1025px) {
  .auth-widget-item {
    position: absolute !important;
    right: 20px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    z-index: 10;
  }
}

/* Desktop moyen (769-1024px) : flex avec marge auto */
@media (min-width: 769px) and (max-width: 1024px) {
  .auth-widget-item {
    position: static !important;
    margin-left: auto !important;
    padding-left: 1rem !important;
    transform: none !important;
  }

  #main-nav ul {
    display: flex;
    align-items: center;
  }
}

/* Sur mobile : position statique dans le flux */
@media (max-width: 768px) {
  .auth-widget-item {
    position: static !important;
    transform: none !important;
    width: 100% !important;
    order: 999 !important; /* Force en dernier */
    margin-top: auto !important; /* Pousse vers le bas */
  }
  
  /* Menu en flex column pour mobile */
  #main-nav ul {
    display: flex;
    flex-direction: column;
    min-height: 100%;
  }
}

/* Bouton thème reste dans le flux normal */
.theme-toggle-item {
  position: static !important;
  right: auto !important;
}

.auth-widget {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}

/* États du widget */
.auth-state {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* =====================================================
   ÉTAT NON CONNECTÉ - BOUTONS CONNEXION/INSCRIPTION
   ===================================================== */

.auth-not-logged {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.auth-buttons {
  display: flex !important;
  flex-direction: row !important;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
}

.auth-btn {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.auth-btn-login {
  background: var(--primary-color, #333);
  color: white;
}

.auth-btn-login:hover {
  background: var(--primary-hover, #555);
  transform: translateY(-1px);
}

.auth-btn-register {
  background: var(--primary-color, #333);
  color: white;
  border: 1px solid var(--primary-color, #333);
}

.auth-btn-register:hover {
  background: var(--primary-hover, #555);
  transform: translateY(-1px);
}

.auth-icon {
  font-size: 0.9em;
}

/* Desktop LARGE uniquement : positionnement absolu */
@media (min-width: 1025px) {
  #main-nav ul li.auth-widget-item {
    width: auto !important;
    display: flex !important;
  }

  #main-nav ul li.auth-widget-item .auth-widget {
    width: auto !important;
    justify-content: center !important;
  }
}

/* Desktop moyen : gestion flex optimisée */
@media (min-width: 769px) and (max-width: 1024px) {
  #main-nav ul li.auth-widget-item {
    width: auto !important;
    display: flex !important;
    flex-shrink: 0; /* Empêche la compression */
  }

  /* Si trop serré, passe sur deux lignes */
  #main-nav ul {
    flex-wrap: wrap;
    gap: 0.4em;
    justify-content: center;
  }

  /* Réduction de la taille des liens */
  #main-nav ul li a {
    padding: 0.3em 0.6em;
    font-size: 0.85rem;
  }

  /* Réduction des boutons auth */
  .auth-btn {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
    gap: 0.2rem;
  }

  .auth-user-btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
  }
}

/* Mobile : boutons adaptés */
@media (max-width: 768px) {
  /* Widget d'auth en bas du menu */
  #main-nav ul li.auth-widget-item {
    width: 100% !important;
    padding: 1rem 0 !important;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin-top: auto !important; /* Pousse vers le bas */
  }
  
  #main-nav ul li.auth-widget-item .auth-buttons {
    display: flex !important;
    flex-direction: row !important;
    gap: 0.5rem !important;
    justify-content: center !important;
    width: 100% !important;
  }
  
  .auth-btn {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    flex: 1;
    justify-content: center;
    max-width: 150px;
  }
  
  /* Texte visible sur mobile aussi */
  .auth-text {
    display: inline;
  }
}

/* Petits écrans : texte caché */
@media (max-width: 480px) {
  .auth-text {
    display: none;
  }
  
  .auth-icon {
    font-size: 1.1em;
  }
  
  .auth-btn {
    padding: 0.4rem 0.8rem;
  }
}

/* =====================================================
   ÉTAT CONNECTÉ - MENU UTILISATEUR
   ===================================================== */

.auth-logged {
  position: relative;
}

.auth-user-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.6rem;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s ease;
  color: white;
}

.auth-user-btn:hover,
.auth-user-btn.active {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.5);
}

.auth-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-color, #a76107);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: white;
  overflow: hidden;
}

.auth-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.auth-username {
  font-weight: 500;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-dropdown-arrow {
  font-size: 0.7rem;
  transition: transform 0.2s ease;
}

.auth-user-btn.active .auth-dropdown-arrow {
  transform: rotate(180deg);
}

/* =====================================================
   MENU DÉROULANT
   ===================================================== */

.auth-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.5rem;
  min-width: 280px;
  background: white;
  border: 1px solid var(--border-color, #ddd);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  overflow: hidden;
}

.auth-dropdown-content {
  padding: 0;
}

/* Informations utilisateur */
.auth-user-info {
  padding: 1rem;
  background: var(--bg-light, #f8f9fa);
  border-bottom: 1px solid var(--border-color, #eee);
}

.auth-user-details strong {
  display: block;
  font-size: 0.95rem;
  color: var(--text-main, #333);
  margin-bottom: 0.2rem;
}

.auth-user-details small {
  color: var(--text-secondary, #666);
  font-size: 0.8rem;
}

.auth-credits-info {
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.auth-credits-label {
  color: var(--text-secondary, #666);
}

.auth-credits-count {
  font-weight: 600;
  color: var(--success-color, #28a745);
  padding: 0.1rem 0.4rem;
  background: var(--success-bg, #d4edda);
  border-radius: 12px;
  font-size: 0.75rem;
}

.auth-credits-count.auth-credits-low {
  color: var(--warning-color, #ffc107);
  background: var(--warning-bg, #fff3cd);
}

.auth-credits-count.auth-credits-empty {
  color: var(--danger-color, #dc3545);
  background: var(--danger-bg, #f8d7da);
}

.auth-premium-badge {
  background: linear-gradient(45deg, #ffd700, #ffed4e);
  color: #333;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: 12px;
  text-transform: uppercase;
}

.auth-premium-plus-badge {
  background: linear-gradient(45deg, #ff6b35, #f7931e);
  color: white;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: 12px;
  text-transform: uppercase;
  box-shadow: 0 2px 4px rgba(255, 107, 53, 0.3);
}

/* Séparateur */
.auth-separator {
  margin: 0;
  border: none;
  height: 1px;
  background: var(--border-color, #eee);
}

/* Liens du menu */
.auth-menu-links {
  padding: 0.5rem 0;
}

.auth-menu-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: var(--text-main, #333);
  text-decoration: none;
  font-size: 0.9rem;
  transition: background-color 0.2s ease;
}

.auth-menu-link:hover {
  background: var(--bg-hover, #f5f5f5);
  color: var(--primary-color, #333);
}

.auth-menu-icon {
  font-size: 1rem;
  width: 20px;
  text-align: center;
}

/* Bouton de déconnexion */
.auth-logout {
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  color: var(--danger-color, #dc3545);
}

.auth-logout:hover {
  background: var(--danger-bg-light, #f8f9fa);
  color: var(--danger-color, #dc3545);
}

/* Actions */
.auth-menu-actions {
  padding: 0.5rem 0;
  border-top: 1px solid var(--border-color, #eee);
}

/* =====================================================
   ÉTAT DE CHARGEMENT
   ===================================================== */

.auth-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
}

.auth-spinner {
  font-size: 1rem;
  animation: spin 1s linear infinite;
}

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

/* =====================================================
   RESPONSIVE - TABLETTES ET FENÊTRES RÉDUITES
   ===================================================== */

/* Zone critique : 769-1024px où on évite le positionnement absolu */
@media (min-width: 769px) and (max-width: 1024px) {
  /* Auth en flex, pas en absolu */
  .auth-widget-item {
    position: static !important;
    transform: none !important;
    margin-left: auto !important;
    padding-left: 0.8rem !important;
  }

  /* Menu peut passer sur plusieurs lignes si nécessaire */
  #main-nav ul {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.4em;
  }
}

/* Zone 600-768px : comportement mobile */
@media (min-width: 600px) and (max-width: 768px) {
  .auth-widget-item {
    position: static !important;
    transform: none !important;
    width: 100% !important;
    order: 999 !important;
    margin-top: auto !important;
  }
  
  #main-nav ul {
    display: flex;
    flex-direction: column;
    min-height: 100%;
  }
}

/* =====================================================
   RESPONSIVE - MOBILE
   ===================================================== */

@media (max-width: 768px) {
  .auth-username {
    display: none;
  }
  
  .auth-user-btn {
    padding: 0.5rem 0.8rem;
    width: auto;
    margin: 0 auto;
  }
  
  .auth-dropdown {
    right: 50%;
    transform: translateX(50%);
    min-width: 260px;
  }
}

@media (max-width: 480px) {
  .auth-dropdown {
    position: fixed;
    top: auto;
    right: 0.5rem;
    left: 0.5rem;
    transform: none;
    width: auto;
    min-width: auto;
  }
}

/* =====================================================
   THÈME SOMBRE
   ===================================================== */

.theme-dark .auth-dropdown {
  background: var(--bg-dark, #2d3748);
  border-color: var(--border-dark, #4a5568);
  color: var(--text-dark, #e2e8f0);
}

.theme-dark .auth-user-info {
  background: var(--bg-darker, #1a202c);
  border-color: var(--border-dark, #4a5568);
}

.theme-dark .auth-user-details strong {
  color: var(--text-dark, #e2e8f0);
}

.theme-dark .auth-user-details small {
  color: var(--text-dark-secondary, #a0aec0);
}

.theme-dark .auth-menu-link {
  color: var(--text-dark, #e2e8f0);
}

.theme-dark .auth-menu-link:hover {
  background: var(--bg-hover-dark, #4a5568);
}

.theme-dark .auth-separator {
  background: var(--border-dark, #4a5568);
}

.theme-dark .auth-btn-login,
.theme-dark .auth-btn-register {
  background: var(--primary-color, #333);
  color: white;
  border-color: var(--primary-color, #333);
}

.theme-dark .auth-btn-login:hover,
.theme-dark .auth-btn-register:hover {
  background: var(--primary-hover, #555);
  color: white;
}