/* ================================================================================
   SIDEBAR - Menu Latéral
   ================================================================================

   Architecture simple et scalable

   STRUCTURE :
   1. Container principal + règles globales
   2. Header (hamburger + logo)
   3. Nouvelle conversation (glass-button)
   4. Navigation principale
   5. Section récents
   6. Profil utilisateur
   7. Push effect
   8. Dark mode
   9. Responsive

   ================================================================================ */

/* ========================================
   1. CONTAINER PRINCIPAL + RÈGLES GLOBALES
   ======================================== */

/* Suppression des contours sur tous les boutons du sidebar */
.conversations button,
.conversations .glass-button,
.conversations .hamburger-icon {
  outline: none !important;
  border: none !important;
  box-shadow: none !important;
  -webkit-tap-highlight-color: transparent;
}

.conversations {
  position: fixed;
  top: 8px;
  left: 8px;
  width: 70px;
  height: calc(100vh - 16px);

  /* Glassmorphism */
  background: rgba(251, 249, 245, 0.95);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);

  /* Padding réduit pour laisser l'espace aux effets glass du bouton */
  padding: 16px 14px;

  /* Layout */
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-x: visible; /* Permet aux effets glass de dépasser horizontalement */
  overflow-y: auto; /* Scroll vertical si nécessaire */
  z-index: 999;

  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              padding 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* État ouvert */
body.sidebar-open .conversations {
  width: 280px;
  padding: 16px;
}

/* Effet subtle au survol */
.conversations::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg,
      rgba(249, 228, 121, 0.05) 0%,
      rgba(249, 228, 121, 0.01) 50%,
      rgba(249, 228, 121, 0.02) 100%);
  border-radius: inherit;
  pointer-events: none;
  z-index: -1;
}

/* Composant de base : élément cliquable du sidebar */
.sidebar-item,
.nav-item,
.user-profile,
.conversation-item {
  display: flex;
  align-items: center;
  height: 38px;
  min-height: 38px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s ease;
  overflow: hidden;
  flex-shrink: 0;
  outline: none !important;

  /* Mode collapsed : centré */
  justify-content: center;
  gap: 0;
  padding: 0;
}

body.sidebar-open .sidebar-item,
body.sidebar-open .nav-item,
body.sidebar-open .user-profile {
  justify-content: flex-start;
  gap: 12px;
  padding: 0 12px;
}

.sidebar-item:hover,
.nav-item:hover,
.user-profile:hover,
.conversation-item:hover {
  background: rgba(0, 0, 0, 0.12);
}

.sidebar-item:active {
  transform: scale(0.98);
}

/* Icônes normalisées à 24x24px */
.sidebar-icon,
.nav-item .nav-icon {
  width: 24px;
  height: 24px;
  min-width: 24px;
  min-height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-primary);
}

.sidebar-icon img,
.sidebar-icon svg,
.nav-item .nav-icon img,
.nav-item .nav-icon svg {
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.sidebar-icon i,
.nav-item i {
  font-size: 20px;
}

/* ========================================
   ICÔNES SVG INLINE ANIMÉES
   ======================================== */

/* Styles de base pour les SVG inline */
.nav-icon-svg .icon-path {
  fill: none;
  stroke: var(--text-secondary);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-icon-svg .icon-path-thin {
  stroke-width: 1.5;
}

.nav-icon-svg .icon-dot {
  fill: var(--text-secondary);
  stroke: none;
}

/* Animations au survol - Discussions (chat bubble) */
.nav-icon-svg .chat-bubble {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: center center;
}

.nav-icon-svg .chat-dot-1,
.nav-icon-svg .chat-dot-2,
.nav-icon-svg .chat-dot-3 {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: center center;
}

.nav-item:hover .chat-bubble {
  transform: translateY(-2px);
}

.nav-item:hover .chat-dot-1 {
  animation: bounce 0.6s ease infinite;
}

.nav-item:hover .chat-dot-2 {
  animation: bounce 0.6s ease 0.1s infinite;
}

.nav-item:hover .chat-dot-3 {
  animation: bounce 0.6s ease 0.2s infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(-1px); }
  50% { transform: translateY(-3px); }
}

/* Animations au survol - Agents (formes rotatives) */
.nav-icon-svg .shape-1,
.nav-icon-svg .shape-2,
.nav-icon-svg .shape-3,
.nav-icon-svg .shape-4 {
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: center center;
}

.nav-icon-svg .shape-2 {
  transform-origin: 16.5px 7.5px;
}

.nav-icon-svg .shape-4 {
  transform-origin: 7.5px 17.65px;
}

.nav-item:hover .shape-2 {
  transform: rotate(180deg);
}

.nav-item:hover .shape-4 {
  transform: rotate(180deg);
}

/* Animations au survol - Workspace (documents sortants) */
.nav-icon-svg .document {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: bottom center;
}

.nav-item:hover .document-1 {
  transform: translateY(-4px) translateX(4px) rotate(13deg);
}

.nav-item:hover .document-2 {
  transform: translateY(-3px) translateX(3px) rotate(11deg);
}

.nav-item:hover .document-3 {
  transform: translateY(-2px) translateX(1px) rotate(2deg);
}

/* ========================================
   2. HEADER - Hamburger + Logo
   ======================================== */

.sidebar-header {
  display: flex;
  align-items: center;
  height: 38px;
  padding-bottom: 2px;
  flex-shrink: 0;
  overflow: hidden;
  justify-content: center;
  gap: 0;
}

body.sidebar-open .sidebar-header {
  justify-content: flex-start;
  gap: 16px;
  padding: 0 12px 8px 12px;
}

/* Hamburger avec fond transparent pour se fondre dans le sidebar */
.hamburger-icon {
  width: 24px;
  height: 24px;
  min-width: 24px;
  min-height: 24px;
  background: transparent !important;
  color: var(--text-primary) !important;
  border: none !important;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.2s ease;
  outline: none !important;
  box-shadow: none !important;
}

.hamburger-icon:hover {
  background: rgba(0, 0, 0, 0.05) !important;
}

.hamburger-icon svg {
  width: 20px;
  height: 20px;
  color: var(--text-primary) !important;
  flex-shrink: 0;
}

/* Logo produit */
.product-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  opacity: 0;
  width: 0;
  overflow: hidden;
  transition: opacity 0.25s ease 0.1s,
              width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

body.sidebar-open .product-name {
  opacity: 1;
  width: auto;
}

/* ========================================
   3. NOUVELLE CONVERSATION
   ======================================== */

.new-conversation-section {
  display: flex;
  align-items: center;
  height: 38px;
  min-height: 38px;
  cursor: pointer;
  overflow: visible; /* Permet aux effets glass de dépasser */
  flex-shrink: 0;
  transition: background 0.2s ease;
  background: transparent;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  justify-content: center;
  gap: 0;
  padding: 0;
  border-radius: 8px;
}

body.sidebar-open .new-conversation-section {
  justify-content: flex-start;
  gap: 12px;
  padding: 0 12px;
}

/* Effet de fond au survol - comme les autres nav-items */
.new-conversation-section:hover {
  background: rgba(0, 0, 0, 0.12);
}

/* Glass button - conserve son apparence d'origine (28x28px) */
.glass-button-wrap {
  width: 28px;
  height: 28px;
  min-width: 28px;
  min-height: 28px;
  flex-shrink: 0;
  position: relative;
}

/* ✅ CORRIGÉ : Cacher la shadow du glass-button en mode collapsed pour éviter qu'elle soit coupée */
body:not(.sidebar-open) .conversations .glass-button-shadow {
  display: none;
}

/* Label */
.new-conversation-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  opacity: 0;
  width: 0;
  overflow: hidden;
  transition: opacity 0.25s ease 0.1s,
              width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

body.sidebar-open .new-conversation-label {
  opacity: 1;
  width: auto;
}

/* ========================================
   4. NAVIGATION PRINCIPALE
   ======================================== */

.main-navigation {
  display: flex;
  flex-direction: column;
  gap: 0;
  flex-shrink: 0;
}

/* Labels des nav items */
.nav-item span {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  color: var(--text-primary);
  opacity: 0;
  width: 0;
  overflow: hidden;
  transition: opacity 0.25s ease 0.1s,
              width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

body.sidebar-open .nav-item span {
  opacity: 1;
  width: auto;
}

/* Séparateur */
.nav-separator {
  height: 1px;
  background: rgba(0, 0, 0, 0.08);
  margin: 2px 0;
  flex-shrink: 0;
}

/* ========================================
   5. SECTION RÉCENTS
   ======================================== */

.recents-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

body:not(.sidebar-open) .recents-section {
  display: none;
}

/* Header */
.recents-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 32px;
  padding: 0 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.recents-header span,
.recents-header i {
  opacity: 0;
  transition: opacity 0.25s ease 0.1s;
}

body.sidebar-open .recents-header span,
body.sidebar-open .recents-header i {
  opacity: 1;
}

/* Liste des conversations */
.conversations-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.conversation-item {
  padding: 6px 8px;
  justify-content: space-between;
  gap: 8px;
  min-height: 32px;
  height: auto;
  /* Override base sidebar-item height */
  max-height: none;
}

/* Override base sidebar-item styles for conversation items */
.conversations-list .conversation-item {
  height: auto;
  min-height: 32px;
}

.conversation-item-content {
  flex: 1;
  min-width: 0; /* Allow text truncation */
  display: flex;
  align-items: center;
  padding-right: 8px; /* Space between title and menu */
}

.conversation-item-title {
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0; /* Allow text truncation */
}

.conversation-item-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.conversation-item:hover .conversation-item-actions {
  opacity: 1;
}

.conversation-item-actions i {
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background 0.15s ease;
}

.conversation-item-actions i:hover {
  background: rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] .conversation-item-actions i:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Scrollbar personnalisée */
.recents-section::-webkit-scrollbar {
  width: 6px;
}

.recents-section::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.03);
  border-radius: 3px;
}

.recents-section::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}

.recents-section::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

/* ========================================
   6. PROFIL UTILISATEUR
   ======================================== */

.user-profile {
  border-top: 1px solid var(--border-color);
  margin-top: auto;
  padding-top: 12px; /* Espace au-dessus pour éviter que le border cache l'avatar */
  overflow: visible !important; /* Important pour que l'avatar soit visible */
}

/* Container info */
.user-info {
  display: flex;
  flex-direction: row; /* ✅ Force horizontal alignment (overrides style-refactored.css) */
  align-items: center;
  flex: 1;
  /* En mode collapsed, centrer l'avatar */
  justify-content: center;
  gap: 0;
}

/* Mode ouvert : avatar + nom alignés à gauche */
body.sidebar-open .user-info {
  justify-content: flex-start;
  gap: 12px;
}

/* Avatar - augmenté à 32x32px pour meilleure visibilité */
.user-avatar {
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  background: #ffffff;
  border: 1.5px solid rgba(0, 0, 0, 0.15); /* Bordure plus visible */
  color: var(--text-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); /* Ombre légère pour plus de contraste */
}

/* Nom utilisateur - caché en mode collapsed */
.user-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  /* Mode collapsed : complètement caché */
  display: none;
}

/* Mode ouvert : visible sur la même ligne que l'avatar */
body.sidebar-open .user-name {
  display: block;
}

/* Chevron */
.user-profile > i {
  margin-left: auto;
  color: var(--text-secondary);
  font-size: 14px;
  opacity: 0;
  width: 0;
  transition: opacity 0.25s ease 0.1s,
              width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Mode collapsed : masquer complètement le chevron */
body:not(.sidebar-open) .user-profile > i {
  display: none;
}

body.sidebar-open .user-profile > i {
  opacity: 1;
  width: auto;
  display: block;
}

/* ========================================
   7. PUSH EFFECT
   ======================================== */

.chat-main-container {
  margin-left: 78px; /* 70px sidebar + 8px gap */
  transition: margin-left 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 100vh;
}

body.sidebar-open .chat-main-container {
  margin-left: 288px; /* 280px sidebar + 8px gap */
}

/* ========================================
   8. DARK MODE
   ======================================== */

[data-theme="dark"] .conversations {
  background: var(--glass-bg);
  border-color: var(--glass-border);
  box-shadow: var(--glass-shadow);
}

[data-theme="dark"] .conversations::before {
  background: transparent;
}

[data-theme="dark"] .sidebar-item:hover,
[data-theme="dark"] .new-conversation-section:hover,
[data-theme="dark"] .nav-item:hover,
[data-theme="dark"] .user-profile:hover,
[data-theme="dark"] .conversation-item:hover {
  background: rgba(0, 0, 0, 0.35);
}

[data-theme="dark"] .new-conversation-section {
  background: transparent;
}

[data-theme="dark"] .new-conversation-section:hover {
  background: rgba(0, 0, 0, 0.35);
}

/* Hamburger en dark mode avec fond transparent */
[data-theme="dark"] .hamburger-icon {
  background: transparent !important;
  color: var(--text-primary) !important;
}

[data-theme="dark"] .hamburger-icon:hover {
  background: rgba(255, 255, 255, 0.08) !important;
}

[data-theme="dark"] .hamburger-icon svg {
  color: var(--text-primary) !important;
}

[data-theme="dark"] .nav-separator {
  background: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .user-avatar {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); /* Ombre plus marquée en dark mode */
}

/* Dark mode scrollbar */
[data-theme="dark"] .recents-section::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.03);
}

[data-theme="dark"] .recents-section::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .recents-section::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Icônes img inversées en dark mode (les SVG inline utilisent var(--text-primary)) */
[data-theme="dark"] .nav-icon img,
[data-theme="dark"] .nav-item img:not(.nav-icon-svg) {
  filter: invert(1) brightness(0.9) !important;
}

[data-theme="dark"] body.sidebar-open .nav-item[data-section="workspace"]::after {
  color: var(--text-secondary);
}

/* ========================================
   9. RESPONSIVE - Mobile
   ======================================== */

@media (max-width: 768px) {
  .conversations {
    transform: translateX(calc(-100% - 8px));
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  }

  body.sidebar-open .conversations {
    transform: translateX(0);
  }

  .chat-main-container {
    margin-left: 0;
  }

  body.sidebar-open .chat-main-container {
    margin-left: 0;
  }
}

/* Hamburger mobile (hors sidebar) */
.mobile-hamburger-icon {
  display: none;
  position: fixed;
  top: 20px;
  left: 20px;
  width: 44px;
  height: 44px;
  /* ✅ CORRIGÉ : Fond transparent au lieu de glassmorphique pour éviter l'encadré blanc */
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  font-size: 20px;
  outline: none;
  /* Ajout d'une légère ombre pour visibilité sans fond blanc */
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.mobile-hamburger-icon:focus {
  outline: none;
}

.mobile-hamburger-icon:hover {
  transform: scale(1.05);
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.15));
}

[data-theme="dark"] .mobile-hamburger-icon {
  color: var(--text-primary);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

[data-theme="dark"] .mobile-hamburger-icon:hover {
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.4));
}

@media (max-width: 768px) {
  .mobile-hamburger-icon {
    display: flex;
  }
}

/* ========================================
   10. ANIMATIONS
   ======================================== */

@keyframes slideInFromLeft {
  from {
    transform: translateX(-20px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

body.sidebar-open .nav-item span,
body.sidebar-open .new-conversation-label,
body.sidebar-open .product-name,
body.sidebar-open .user-name {
  animation: slideInFromLeft 0.3s ease 0.1s both;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .conversations,
  .chat-main-container,
  .sidebar-item,
  .nav-item,
  .user-profile,
  .new-conversation-section,
  * {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
