/* Chat list sidebar */
.chat-list-sidebar {
  padding-top: 0;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: 585px; /* 25% más ancho */
  max-width: calc(100vw - 40px);
  height: auto;
  min-height: 100vh;
  min-height: 100dvh; /* Compatibilidad con navegadores móviles */
  background: linear-gradient(180deg, rgba(50, 54, 71, 0.98), rgba(38, 42, 58, 0.98));
  border-right: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 22px 48px rgba(14, 16, 24, 0.6);
  z-index: 1400;
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  
  /* Soluciones para WebView - forzar visibilidad y renderizado */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -webkit-perspective: 1000;
  perspective: 1000;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
}

/* Ensure sidebar is fully visible when open */
.chat-list-sidebar.open {
  width: min(85vw, 420px);
  max-width: min(85vw, 420px);
  transform: translateX(0);
  visibility: visible;
  opacity: 1;
}

/* Fallback for different screen ratios */
@media (max-aspect-ratio: 1/1) {
  .chat-list-sidebar {
    width: min(80vw, 380px);
    max-width: min(80vw, 380px);
  }

  .chat-list-sidebar.open {
    width: min(80vw, 380px);
    max-width: min(80vw, 380px);
  }
}

@media (max-aspect-ratio: 2/3) {
  .chat-list-sidebar {
    width: min(75vw, 350px);
    max-width: min(75vw, 350px);
  }

  .chat-list-sidebar.open {
    width: min(75vw, 350px);
    max-width: min(75vw, 350px);
  }
}

@supports (backdrop-filter: blur(10px)) {
  .chat-list-sidebar {
    backdrop-filter: blur(10px);
  }
}

.sidebar-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar-top-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: calc(22px + var(--status-bar-height, 0px)) 22px 18px; /* Ajuste para la barra de estado */
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(62, 67, 86, 0.92); /* Fondo opaco para cubrir el área de la barra de estado */
}

.sidebar-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-shadow: 0 6px 20px rgba(99, 102, 241, 0.25);
}

.chat-list-container {
  padding: 16px 12px;
}

.chat-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  margin-bottom: 12px;
}

.chat-list-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
}

.new-chat-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-medium);
}

.new-chat-btn:hover {
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
  transform: translateY(-1px);
}

.new-chat-btn:active {
  transform: translateY(0);
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-list-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: linear-gradient(180deg, rgba(74, 79, 97, 0.92), rgba(55, 59, 76, 0.9));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition-medium);
}

.chat-list-item:hover {
  background: linear-gradient(180deg, rgba(91, 59, 227, 0.28), rgba(74, 79, 97, 0.95));
  border-color: rgba(138, 99, 255, 0.45);
  transform: translateY(-1px);
}

.chat-list-item:active {
  transform: translateY(0);
}

.chat-list-item .chat-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-list-item .chat-meta {
  font-size: 0.7rem;
}

@media (max-width: 480px) {
  .chat-list-header {
    padding: 10px 12px;
  }

  .chat-list-item .chat-title {
    font-size: 0.8rem;
  }

  .chat-list-item .chat-meta {
    font-size: 0.65rem;
  }
}

.chat-list-item .chat-meta {
  font-size: 0.7rem;
}

.chat-list-sidebar * {
  user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  pointer-events: auto;
}

/* Solución para problemas de teclado en WebView */
html, body {
  height: 100%;
  overflow: hidden;
}

/* Solución para problemas de posicionamiento en dispositivos con notch */
@supports (padding: max(0px)) {
  .app-container {
    padding-top: max(0px, env(safe-area-inset-top, 0px));
    padding-right: max(0px, env(safe-area-inset-right, 0px));
    padding-bottom: max(0px, env(safe-area-inset-bottom, 0px));
    padding-left: max(0px, env(safe-area-inset-left, 0px));
  }
}

/* Firefox scrollbar styles */
.chat-list-sidebar {
  scrollbar-width: thin;
}

.chat-list-sidebar::-webkit-scrollbar,
.chat-list-container::-webkit-scrollbar {
  width: 8px;
}

.chat-list-sidebar::-webkit-scrollbar-track,
.chat-list-container::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 6px;
}

.chat-list-sidebar::-webkit-scrollbar-thumb,
.chat-list-container::-webkit-scrollbar-thumb {
  background: rgba(99, 102, 241, 0.3);
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.chat-list-sidebar::-webkit-scrollbar-thumb:hover,
.chat-list-container::-webkit-scrollbar-thumb:hover {
  background: rgba(99, 102, 241, 0.5);
}

/* Better responsive handling - removed the problematic max-aspect-ratio rule */
@media (orientation: portrait) and (max-height: 1000px) {
  .chat-list-sidebar {
    width: min(85vw, 420px);
    max-width: min(85vw, 420px);
  }
}

@media (orientation: landscape) and (min-width: 768px) {
  .chat-list-sidebar {
    width: min(55vw, 550px);
    max-width: min(55vw, 550px);
  }
}
