/* Chat Sidebar - fondo y lista transparentes, sin bordes ni sombras */
.chat-sidebar {
  width: 320px;
  height: 100vh;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1000;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  color: var(--text-primary);
  font-family: inherit;
  backdrop-filter: none;
}

.chat-sidebar::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

.chat-sidebar.hidden {
  transform: translateX(-100%);
}

.sidebar-header, .header-chat-menu {
  display: none !important;
}

.chat-list {
  padding: 0 !important;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

.conversations-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: var(--spacing-md);
  overflow-y: auto;
  min-height: 0;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  scrollbar-width: none; /* Firefox */
  ms-overflow-style: none;
  overflow-x: hidden;
}

.conversations-list::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

.conversations-list:empty::after {
  content: 'No hay conversaciones guardadas';
  text-align: center;
  color: var(--text-secondary);
  font-weight: 500;
  font-style: italic;
  padding: var(--spacing-xl);
  display: block;
}

.load-history {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all 0.2s;
  display: flex;
  align-items: stretch;
  margin-bottom: 4px; /* Añadido para separar elementos */
}

.load-history:hover {
  background: var(--surface-hover) !important;
  border: none !important;
  box-shadow: none !important;
}

.load-btn {
  flex: 1;
  background: none !important;
  border: none !important;
  color: var(--text-primary);
  padding: var(--spacing-sm) var(--spacing-md);
  text-align: left;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  transition: all 0.2s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.load-btn:hover {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  color: var(--accent-primary);
  font-weight: 600;
}

.delete-btn {
  background: none !important;
  border: none !important;
  color: var(--error-bg);
  padding: var(--spacing-sm);
  cursor: pointer;
  font-size: 1.1rem;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  border-left: 2px solid var(--border-secondary);
}

.delete-btn:hover {
  background: var(--error-bg);
  color: var(--error-text);
  font-weight: 600;
}

.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(99, 102, 241, 0.08);
  backdrop-filter: blur(8px);
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
}

.sidebar-overlay.visible {
  opacity: 1;
  visibility: visible;
}

.conversations-list.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.delete-chat-btn {
  background: none !important;
  border: none !important;
  border-right: 2px solid var(--border-secondary);
  color: var(--error-bg);
  padding: 0.3em !important;
  cursor: pointer;
  font-size: 0.9rem !important;
  flex-shrink: 0;
  transition: all 0.2s;
  font-weight: 600;
}

.delete-chat-btn:hover {
  background: var(--error-bg);
  color: var(--error-text);
}

.delete-chat-btn svg {
  width: 16px !important;
  height: 16px !important;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-secondary);
  border-top: 3px solid var(--accent-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@media (max-width: 768px) {
  .chat-sidebar {
    width: 280px;
  }
}

@media (max-width: 640px) {
  .chat-sidebar {
    width: 100vw;
  }
  .header-chat-menu {
    padding: var(--spacing-md) var(--spacing-sm) var(--spacing-sm);
  }
  .conversations-list {
    padding: var(--spacing-sm);
  }
}

/* CORRECCIÓN PRINCIPAL: Estructura correcta para los elementos de chat */
.chat-item {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  transition: font-size 0.18s;
  font-size: 0.95em !important;
  display: flex;
  align-items: center;
  gap: 0.5em;
  color: var(--text-primary) !important;
  margin-bottom: 4px; /* Espacio entre elementos */
  padding: 8px 12px; /* Padding interno */
  border-radius: 8px; /* Bordes redondeados */
  min-height: 40px; /* Altura mínima */
  width: 100%; /* Ancho completo */
  box-sizing: border-box; /* Incluir padding en el cálculo del ancho */
  position: relative; /* Posicionamiento relativo para evitar superposición */
}

.chat-item:hover {
  background: var(--surface-hover) !important;
  border: none !important;
  box-shadow: none !important;
  font-size: 1.08em !important;
  color: var(--accent-primary) !important;
}

.chat-name-btn,
.chat-name-btn:hover {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  font-size: 1em !important;
  color: inherit !important; /* Heredar color del padre */
  font-weight: 600;
  transition: none;
  padding: 0.3em !important;
  flex: 1; /* Tomar el espacio disponible */
  text-align: left; /* Alinear texto a la izquierda */
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Header del ChatSidebar con estilo original, fondo y bordes suaves */
.chat-sidebar-header {
  padding-top: 16px;
  border-bottom: none !important;
  background: transparent !important;
  box-shadow: none !important;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-shrink: 0; /* No se encoge */
  color: white !important;
}

.chat-sidebar-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #f3f4f6 !important;
}

.close-chat-sidebar-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 5px;
  border-radius: 4px;
  color: #6b7280;
  display: flex;
  align-items: center;
  justify-content: center;
}
.close-chat-sidebar-btn:hover {
  background: rgba(235, 236, 248, 0.1);
  color: #87CEEB;
  box-shadow: 0 2px 4px rgba(99, 102, 241, 0.2);
}

.chat-sidebar-search {
  position: relative;
  margin-bottom: 12px;
  background: transparent;
  flex-shrink: 0; /* No se encoge */
}

.chat-sidebar-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #6b7280;
}

.chat-sidebar-search-input {
  width: 100%;
  padding: 10px 12px 10px 40px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  background: linear-gradient(135deg, rgba(135, 206, 235, 0.05), rgba(173, 216, 230, 0.05)) !important;
  color: #1f2937;
  outline: none;
  transition: border-color 0.2s;
  box-sizing: border-box;
}

.chat-sidebar-search-input:focus {
  border-color: #87CEEB;
}

.chat-sidebar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: transparent;
  flex-shrink: 0; /* No se encoge */
  margin-bottom: 12px;
}

.chat-sidebar-controls-btn {
  background: #7c3aed !important;
  color: #fff !important;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: 0.2s;
}
.chat-sidebar {
  width:100px;
  min-width:80px;
}

.chat-sidebar-controls-btn:hover {
  background: #a78bfa !important;
  color: #fff !important;
}

/* Sección de grupo de chats (por ejemplo, 'Ayer', 'Hoy') con scroll propio */
.chat-group {
  display: flex;
  flex-direction: column;
  /* Elimina cualquier flex, min-height, max-height, flex-grow, flex-shrink, etc. */
  /* Solo ocupa el alto de su contenido */
}

.chat-group-content {
  display: flex;
  flex-direction: column;
  /* Elimina cualquier flex, min-height, max-height, flex-grow, flex-shrink, etc. */
}

/* Opcional: título de la sección */
.chat-group-title {
  font-size: 15px;
  font-weight: 600;
  color: #6b7280;
  margin-bottom: 6px;
  margin-top: 2px;
  flex-shrink: 0; /* No se encoge */
}

.chat-sidebar, .chat-sidebar *,
.conversations-list, .conversations-list *,
.chat-group, .chat-group *,
.chat-group-content, .chat-group-content * {
  scrollbar-width: none !important;
  -ms-overflow-style: none !important;
}
.chat-sidebar::-webkit-scrollbar,
.chat-sidebar *::-webkit-scrollbar,
.conversations-list::-webkit-scrollbar,
.conversations-list *::-webkit-scrollbar,
.chat-group::-webkit-scrollbar,
.chat-group *::-webkit-scrollbar,
.chat-group-content::-webkit-scrollbar,
.chat-group-content *::-webkit-scrollbar {
  display: none !important;
}