/* Chat Container  */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 64px);
  height: calc(100dvh - 64px); /* Dynamic viewport height para Safari */
  background: transparent;
  position: relative;
  /* Safari específico para scroll */
  min-height: -webkit-fill-available;
  /* Permitir scroll vertical para leer mensajes previos */
  overflow-y: auto;
}

/* Header del Chat */
.chat-header {
  padding: var(--space-6) 0 var(--space-4) 0;
  background: transparent;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-header .tokens-info {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
}

.chat-header .tokens-badge {
  background: var(--surface-bg);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--border-radius);
  color: var(--accent-primary);
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Lista de Mensajes */
.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  scroll-behavior: smooth;
  /* Fixes para Safari mobile scroll */
  -webkit-overflow-scrolling: touch;
  min-height: 0; /* Necesario para flex scroll en Safari */
  position: relative; /* Para Safari webkit */
  /* Correcciones adicionales Safari */
  will-change: scroll-position;
  contain: layout style;
}

/* Mensajes  */
.message {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  animation: fadeIn 0.5s ease-out;
  max-width: 100%;
}

.message.user {
  flex-direction: row-reverse;
  align-self: flex-end;
  max-width: 80%;
}

.message.assistant {
  align-self: flex-start;
  max-width: 85%;
}

.message.system {
  align-self: center;
  max-width: 60%;
  opacity: 0.8;
}

/* Avatares  */
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  flex-shrink: 0;
  box-shadow: var(--shadow-md);
  border: 2px solid rgba(135, 206, 235, 0.3);
}

.avatar.user {
  background: var(--primary-bg);
  color: var(--text-primary);
}

.avatar.assistant {
  background: var(--surface-bg);
  color: var(--accent-primary);
  border-color: #b983ff;
}

/* Contenido de Mensajes */
.message-content {
  background: var(--card-bg);
  border-radius: var(--border-radius-lg);
  padding: var(--space-4) var(--space-6);
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(255, 255, 255, 0.1);
  position: relative;
  overflow: hidden;
}

.message.user .message-content {
  background: var(--primary-bg);
  color: var(--text-primary);
}

.message.assistant .message-content {
  background: var(--surface-bg);
  color: var(--text-primary);
}

.message.system .message-content {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  text-align: center;
  font-style: italic;
}

/* Efectos de Hover */
.message-content:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  transition: all var(--transition-fast);
}

/* Indicador de Escritura */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4);
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-primary);
  animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  30% {
    opacity: 1;
    transform: scale(1.2);
  }
}

/* Código y Markdown */
.message-content pre {
  background: var(--secondary-bg);
  border-radius: var(--border-radius);
  padding: var(--space-4);
  margin: var(--space-3) 0;
  overflow-x: auto;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.message-content code {
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.1);
  padding: var(--space-1) var(--space-2);
  border-radius: 4px;
  font-size: 14px;
}

.message-content pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
}

/* Bienvenida */
.welcome-message {
  text-align: center;
  padding: var(--space-12);
  color: var(--text-secondary);
}

.welcome-message h2 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: var(--space-4);
  background: var(--primary-bg);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-message p {
  font-size: 16px;
  opacity: 0.8;
}

/* Footer y Controles  */
.footer {
  background: var(--surface-bg);
  backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: var(--space-6);
  margin-top: auto;
  box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Controles de Herramientas */
.tools-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-8);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.tool-group label {
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 14px;
}

/* Switch  */
.ios8-switch {
  position: relative;
  width: 52px;
  height: 28px;
  background: var(--secondary-bg);
  border-radius: 14px;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 2px solid rgba(255, 255, 255, 0.1);
}

.ios8-switch::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text-primary);
  top: 2px;
  left: 2px;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-md);
}

input[type="checkbox"]:checked + .ios8-switch {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

input[type="checkbox"]:checked + .ios8-switch::before {
  transform: translateX(24px);
}

input[type="checkbox"] {
  display: none;
}

/* Botones de Sidebar */
.sidebar-buttons {
  display: flex;
  justify-content: center;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.sidebar-buttons button {
  width: 48px;
  height: 48px;
  background: var(--card-bg);
  border-radius: var(--border-radius);
  color: var(--text-secondary);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow-sm);
}

.sidebar-buttons button:hover {
  background: var(--accent-primary);
  color: var(--text-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.sidebar-buttons button:active {
  transform: translateY(0);
}

/* YouTube Embeds */
.youtube-embed {
  margin: var(--space-4) 0;
  padding: var(--space-2);
  border-radius: var(--border-radius-lg);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.youtube-embed iframe {
  width: 100%;
  max-width: 560px;
  height: 315px;
  border-radius: var(--border-radius);
  border: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Responsive YouTube Embeds */
@media (max-width: 768px) {
  .youtube-embed iframe {
    max-width: 100%;
    height: 200px;
  }
}

@media (max-width: 480px) {
  .youtube-embed {
    margin: var(--space-3) 0;
    padding: var(--space-1);
  }
  
  .youtube-embed iframe {
    height: 180px;
  }
}

/* Responsive  */
@media (max-width: 768px) {  .chat-container {
    height: calc(100dvh - 60px); /* Dynamic viewport height para Safari */
    /* Safari móvil específico */
    min-height: -webkit-fill-available;
    /* Permitir scroll vertical para leer mensajes previos */
    overflow-y: auto;
  }
  
  .chat-header {
    padding: var(--space-3) 0 var(--space-2) 0;
    flex-wrap: wrap;
    gap: var(--space-2);
  }
  
  .chat-header .tokens-info {
    font-size: 12px;
    gap: var(--space-1);
  }
  
  .chat-header .tokens-badge {
    padding: var(--space-1) var(--space-2);
    font-size: 11px;
  }    .chat-list {
    padding: var(--space-3) 0;
    gap: var(--space-4);
    /* Correcciones específicas Safari móvil */
    overflow-y: auto; /* Scroll vertical explícito */
    -webkit-overflow-scrolling: touch;
    max-height: calc(100vh - 180px);
    max-height: calc(100dvh - 180px);
    min-height: 0;
    will-change: scroll-position;
    contain: layout style;
  }
  
  .message {
    gap: var(--space-2);
  }
  
  .message.user, .message.assistant {
    max-width: 100%;
  }
  
  .message.user {
    margin-left: 5%;
    margin-right: 0;
  }
  
  .message.assistant {
    margin-right: 5%;
    margin-left: 0;
  }
  
  .avatar {
    width: 32px;
    height: 32px;
    font-size: 14px;
    flex-shrink: 0;
  }
  
  .message-content {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--border-radius);
    font-size: 14px;
    line-height: 1.5;
  }
  
  .footer {
    padding: var(--space-3);
    background: var(--surface-bg);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    position: sticky;
    bottom: 0;
    z-index: 10;
  }
  
  .tools-container {
    gap: var(--space-4);
    margin-bottom: var(--space-3);
  }
  
  .sidebar-buttons {
    gap: var(--space-2);
    justify-content: center;
  }
  
  .sidebar-buttons button {
    width: 40px;
    height: 40px;
    font-size: 16px;
    padding: var(--space-2);
  }
}

@media (max-width: 480px) {
  .chat-container {
    height: calc(100vh - 55px);
    height: calc(100dvh - 55px); /* Dynamic viewport height para Safari */
    min-height: -webkit-fill-available;
    overflow-y: auto; /* Permitir scroll vertical */
  }
  
  .chat-header {
    padding: var(--space-2) 0;
  }
  
  .chat-header .tokens-info {
    font-size: 11px;
  }
  
  .chat-header .tokens-badge {
    font-size: 10px;
    padding: 2px var(--space-1);
  }    .chat-list {
    padding: var(--space-2) 0;
    gap: var(--space-3);
    /* Correcciones específicas Safari móvil */
    overflow-y: auto; /* Scroll vertical explícito */
    -webkit-overflow-scrolling: touch;
    max-height: calc(100vh - 160px);
    max-height: calc(100dvh - 160px);
    min-height: 0;
    will-change: scroll-position;
  }
  
  .message.user {
    margin-left: 2%;
  }
  
  .message.assistant {
    margin-right: 2%;
  }
  
  .avatar {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }
  
  .message-content {
    padding: var(--space-2) var(--space-3);
    font-size: 13px;
  }
  
  .footer {
    padding: var(--space-2);
  }
  
  .sidebar-buttons button {
    width: 36px;
    height: 36px;
    font-size: 14px;
  }
}
