:root {
    /* Sistema de colores mejorado */
    --primary-400: #8B5CF6;
    --primary-500: #7C3AED;
    --primary-600: #6D28D9;
    --surface-100: #0F0F12;
    --surface-200: #1A1A1F;
    --surface-300: #25252D;
    --surface-400: #2D2D35;
    --text-100: #FAFAFA;
    --text-200: #E4E4E7;
    --text-300: #A1A1AA;
    --accent-blue: #3B82F6;
    --accent-green: #10B981;
    --accent-red: #EF4444;
    --border-dark: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.15);
    
    /* Sistema de tamaño */
    --radius-3xl: 2rem;
    --radius-2xl: 1.5rem;
    --radius-xl: 1rem;
    --radius-md: 0.5rem;
    
    /* Efectos */
    --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.4);
    --glass-bg: rgba(25, 25, 30, 0.95);
    --transition-all: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Reset global mejorado */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Space Grotesk', system-ui, sans-serif;
    background: var(--surface-100);
    color: var(--text-100);
    line-height: 1.6;
    min-height: 100vh;
    display: grid;
    place-items: center;
    overflow-x: hidden;
}

/* Contenedor principal */
.glass-container {
    width: 100vw;
    height: 100vh;
    display: grid;
    grid-template-columns: 200px 1fr; /* Sidebar más pequeña */
    background: var(--glass-bg);
    backdrop-filter: blur(16px) saturate(180%);
    border: 1px solid var(--border-dark);
    box-shadow: var(--shadow-2xl);
}

/* Sidebar completa */
.chat-sidebar {
    border-right: 1px solid var(--border-dark);
    padding: 1.5rem; /* Padding reducido */
    display: flex;
    flex-direction: column;
    gap: 1rem; /* Gap reducido */
    background: linear-gradient(160deg, var(--surface-200) 40%, rgba(26,26,31,0.8));
}

.sidebar-header {
    text-align: center;
}

.ai-avatar-image {
    width: 60px; /* Imagen reducida */
    height: 60px; /* Imagen reducida */
    display: block;
    margin: 0 auto 1rem;
    border-radius: 50%;
}

.model-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-300);
    margin-top: 0.5rem;
}

.pulse-dot {
    width: 10px;
    height: 10px;
    background: var(--accent-green);
    border-radius: 50%;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Menú contextual */
.chat-context-menu {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
/* Estilos de los botones */
.sidebar-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.6rem; /* Gap reducido */
    margin-top: 1rem;
}

.btn-primary,
.btn-secondary {
    padding: 0.4rem 1rem; /* Reducción considerable en el padding */
    font-size: 0.85rem; /* Fuente más pequeña */
    font-weight: 500;
    border-radius: var(--radius-md); /* Radio más pequeño */
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    text-align: center;
    letter-spacing: 0.3px;
}

/* Botón Primario */
.btn-primary {
    background: linear-gradient(145deg, var(--primary-500), var(--primary-400));
    color: white;
    border: 2px solid var(--primary-500);
    box-shadow: 0 4px 8px rgba(124, 58, 237, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(145deg, var(--primary-400), var(--primary-500));
    box-shadow: 0 6px 12px rgba(124, 58, 237, 0.3);
    transform: translateY(-1px);
}

.btn-primary:active {
    background: var(--primary-600);
    box-shadow: 0 3px 6px rgba(124, 58, 237, 0.2);
    transform: translateY(1px);
}

/* Botón Secundario */
.btn-secondary {
    background: linear-gradient(145deg, var(--surface-300), var(--surface-200));
    color: var(--text-200);
    border: 2px solid var(--surface-300);
    box-shadow: 0 3px 6px rgba(60, 60, 60, 0.2);
}

.btn-secondary:hover {
    background: linear-gradient(145deg, var(--surface-200), var(--surface-300));
    color: var(--text-100);
    box-shadow: 0 4px 8px rgba(60, 60, 60, 0.3);
    transform: translateY(-1px);
}

.btn-secondary:active {
    background: var(--surface-300);
    color: var(--text-200);
    box-shadow: 0 3px 6px rgba(60, 60, 60, 0.2);
    transform: translateY(1px);
}


.context-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border-radius: var(--radius-md);
    background: transparent;
    border: none;
    color: var(--text-300);
    transition: var(--transition-all);
    cursor: pointer;
}

.context-item:hover {
    background: var(--surface-300);
    color: var(--text-200);
}

.context-item.active {
    background: var(--surface-400);
    color: var(--primary-400);
}

.context-item i {
    width: 24px;
    text-align: center;
}

/* Área principal del chat */
.chat-main {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.chat-history {
    flex: 1;
    padding: 1rem; /* Menor padding para más espacio en el chat */
    overflow: hidden;
    position: relative;
}

.history-scroll-container {
    height: 100%;
    overflow-y: auto;
    padding-right: 1rem;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

/* Mensajes de chat completos */
.message {
    max-width: 72%;
    margin: 1.5rem 0;
    padding: 1.5rem;
    border-radius: var(--radius-xl);
    position: relative;
    transition: var(--transition-all);
    background: var(--surface-200);
    border: 1px solid var(--border-dark);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.user-message {
    margin-left: auto;
    background: var(--primary-500);
    border: none;
    color: white;
    box-shadow: 0 4px 16px -4px rgba(var(--primary-400), 0.2);
}

.bot-message {
    margin-right: auto;
    background: var(--surface-300);
}

.bot-message::after {
    content: '';
    position: absolute;
    left: -8px;
    top: 24px;
    width: 16px;
    height: 16px;
    background: var(--surface-300);
    transform: rotate(45deg);
    border-left: 1px solid var(--border-dark);
    border-bottom: 1px solid var(--border-dark);
}

.message-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.message-header i {
    font-size: 1.2rem;
    color: var(--text-300);
}

.message-content {
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text-200);
}

.message-content pre {
    margin: 1.5rem 0;
    background: var(--surface-200) !important;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-dark);
}

.code-wrapper {
    position: relative; /* Hace que los elementos absolutos dentro se posicionen respecto a este contenedor */
  }
  
  .copy-btn {
    position: absolute;
    top: 5px; /* Ajusta el espacio superior */
    right: 5px; /* Ajusta el espacio derecho */
    background: var(--surface-400);
    color: var(--text-200);
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s ease;
  }
  
  /* Mostrar el botón al pasar el mouse por el contenedor del código */
  .code-wrapper:hover .copy-btn {
    opacity: 1;
  }
  
.message:hover .copy-btn {
    opacity: 1;
}

/* Sistema de entrada mejorado */
.chat-input-container {
    position: relative;
    padding: 0 1rem 1rem; /* Padding reducido */
}

.input-wrapper {
    position: relative;
    background: var(--surface-200);
    border-radius: var(--radius-2xl);
    border: 1px solid var(--border-dark);
    box-shadow: var(--shadow-2xl);
    width: 90%;
}

.input-decorators {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 0.75rem;
}

.ai-suggestion-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: var(--surface-300);
    border: none;
    color: var(--text-300);
    cursor: pointer;
    transition: var(--transition-all);
}

.ai-suggestion-btn:hover {
    background: var(--primary-500);
    color: white;
}

textarea#user-input {
    width: 100%;
    padding: 1rem 3rem; /* Padding y altura reducidos */
    background: transparent;
    border: none;
    color: var(--text-100);
    font-size: 0.9rem;
    line-height: 1.6;
    min-height: 40px;
    resize: none;
    scrollbar-width: thin;
    scrollbar-color: var(--primary-500) transparent;
}

textarea#user-input:focus {
    outline: none;
   border-color: var(--primary-500);
}

.input-actions {
    position: absolute;
    right: 0.75rem; /* Offset reducido */
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 0.75rem;
}

.voice-input-btn {
    width: 36px; /* Tamaño reducido */
    height: 36px; /* Tamaño reducido */
    border-radius: var(--radius-md);
    background: var(--surface-300);
    border: none;
    color: var(--text-300);
    cursor: pointer;
    transition: var(--transition-all);
}

.voice-input-btn:hover {
    background: var(--primary-500);
    color: white;
}

.send-btn {
    width: 36px; /* Tamaño reducido */
    height: 36px; /* Tamaño reducido */
    border-radius: var(--radius-md);
    background: var(--primary-500);
    border: none;
    color: white;
    cursor: pointer;
    transition: var(--transition-all);
}

.send-btn:hover {
    background: var(--primary-600);
    transform: translateY(-2px) rotate(5deg);
}

.input-meta {
    display: flex;
    justify-content: space-between;
    margin-top: 0.75rem;
    padding: 0 1.5rem;
    font-size: 0.85rem;
    color: var(--text-300);
}

.character-count {
    font-feature-settings: 'tnum';
}

.hint-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.hint-container i {
    font-size: 0.9rem;
}

/* Scrollbars personalizadas */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--surface-200);
}

::-webkit-scrollbar-thumb {
    background: var(--surface-400);
    border-radius: var(--radius-md);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-500);
}

/* Indicador de escritura */
.typing-indicator {
    background: var(--surface-300);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-2xl);
    width: fit-content;
    display: flex;
    gap: 0.75rem;
    align-items: center;
    border: 1px solid var(--border-dark);
    margin: 1rem 0;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-300);
    border-radius: 50%;
    animation: pulseWave 1.8s infinite ease-in-out;
}

@keyframes pulseWave {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Sistema de notificaciones */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--surface-300);
    border: 1px solid var(--border-dark);
    backdrop-filter: blur(12px);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-2xl);
    color: var(--text-200);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    opacity: 0;
    transform: translateY(20px);
    animation: toastIn 0.3s ease-out forwards;
}

@keyframes toastIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Modo móvil */
@media (max-width: 768px) {
    .glass-container {
        grid-template-columns: 1fr;
    }
    
    .chat-sidebar {
        display: none;
    }
    
    .chat-history {
        padding: 1rem;
    }
    
    .message {
        max-width: 90%;
        margin: 1rem 0;
        padding: 1rem;
    }
    
    .input-wrapper {
        margin: 1rem;
    }
    
    .input-decorators {
        left: 1rem;
    }
    
    .input-actions {
        right: 1rem;
    }
}

/* Estados de error */
.error-message {
    background: var(--accent-red);
    color: white;
    padding: 1rem;
    border-radius: var(--radius-md);
    margin: 1rem 0;
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.error-message i {
    font-size: 1.2rem;
}

/* Mejoras de accesibilidad */
:focus-visible {
    outline: 2px solid var(--primary-500);
    outline-offset: 2px;
}

[aria-disabled="true"] {
    opacity: 0.6;
    pointer-events: none;
}

/* Añadir estos estilos */
.context-item[data-api] {
    position: relative;
    transition: all 0.3s ease;
}
  
.context-item[data-api]::after {
    content: '';
    position: absolute;
    right: 1rem;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    opacity: 0;
    transition: opacity 0.3s ease;
}
  
.context-item.active[data-api]::after {
    opacity: 1;
}
  
.send-btn[data-api] {
    display: none;
    transition: transform 0.2s ease;
}
  
.send-btn[data-api].active {
    display: flex;
}
  
.api-badge {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-md);
    font-size: 0.8em;
    margin-left: 0.5rem;
}
  
/* Animación de cambio de API */
@keyframes apiSwitch {
    0% { opacity: 0.5; transform: scale(0.95); }
    100% { opacity: 1; transform: scale(1); }
}
  
.ai-avatar {
    animation: apiSwitch 0.3s ease;
}

/* Estilos para el selector de modos */
.mode-selector {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.65rem;
}

.mode-scroller {
    display: flex;
    gap: 0.325rem;
    overflow-x: auto;
    padding-bottom: 0.325rem;
}

.mode-btn {
    background: var(--surface-300);
    border: 1.3px solid transparent;
    border-radius: var(--radius-md);
    padding: 0.4875rem 0.8125rem;
    color: var(--text-200);
    display: flex;
    align-items: center;
    gap: 0.4875rem;
    transition: var(--transition-all);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}

.mode-btn.active {
    background: var(--primary);
    border-color: var(--primary-dark);
    color: white;
}

.mode-btn:hover:not(.active) {
    background: var(--surface-400);
}

.send-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: none;
    align-items: center;
    justify-content: center;
}

.send-btn.primary {
    background: var(--primary);
}

.send-btn:not(.primary) {
    background: var(--surface-400);
}

.mode-tag {
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-md);
    font-size: 0.8em;
    margin-left: 0.5rem;
}

/* Scrollbar personalizada para modos */
.mode-scroller::-webkit-scrollbar {
    height: 6px;
}

.mode-scroller::-webkit-scrollbar-thumb {
    background: var(--surface-400);
    border-radius: 3px;
}
pre {
    position: relative !important;
  }
  
/* Contenedor principal de los toasts */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
  }
  
  /* Estilos para cada toast */
  .toast {
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 10px 20px;
    margin-bottom: 10px;
    border-radius: 4px;
    font-size: 0.9rem;
    opacity: 0;
    animation: fadein 0.5s forwards, fadeout 0.5s 2.5s forwards;
  }
  
  /* Animación de aparición */
  @keyframes fadein {
    from {
      opacity: 0;
      transform: translateY(-20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
  
  /* Animación de desaparición */
  @keyframes fadeout {
    from {
      opacity: 1;
    }
    to {
      opacity: 0;
    }
  }


  @media (max-width: 768px) {
    /* Ajustes generales del contenedor */
    .glass-container {
        grid-template-columns: 1fr;
        min-width: 100vw;
    }
    
    /* Ocultar sidebar en móviles */
    .chat-sidebar {
        display: none;
    }
    
    /* Ajustes del área de chat principal */
    .chat-main {
        height: calc(100vh - 60px); /* Espacio para input */
        padding-bottom: 60px;
    }
    
    /* Mensajes más compactos */
    .message {
        max-width: 400px;
        padding: 0.8rem;
        margin: 0.8rem 0;
    }
    
    .message-header {
        margin-bottom: 0.5rem;
    }
    
    .message-content {
        font-size: 0.85rem;
    }
    
    /* Input area optimizada */
    .chat-input-container {
        position: fixed;
        bottom: 0;
        width: 100%;
        padding: 0.5rem;
        background: var(--surface-200);
        border-top: 1px solid var(--border-dark);
    }
    
    .input-wrapper {
        width: 100%;
        margin: 0;
    }
    
    textarea#user-input {
        padding: 0.8rem 2.5rem;
        font-size: 0.85rem;
        min-height: 45px;
    }
    
    /* Botones más compactos */
    .input-decorators,
    .input-actions {
        gap: 0.5rem;
    }
    
    .ai-suggestion-btn,
    .voice-input-btn,
    .send-btn {
        width: 32px;
        height: 32px;
    }
    
    /* Ajustes de elementos de UI */
    .model-status {
        font-size: 0.8rem;
    }
    
    .typing-indicator {
        padding: 0.8rem;
        font-size: 0.85rem;
    }
    
    .toast {
        bottom: 1rem;
        right: 1rem;
        width: 90%;
        max-width: none;
    }
    
    /* Mejoras de código responsivo */
    .code-wrapper pre {
        font-size: 0.75rem;
        padding: 0.8rem !important;
    }
    
    .copy-btn {
        padding: 0.3rem 0.8rem;
        font-size: 0.75rem;
    }
    
    /* Optimización de scroll */
    .history-scroll-container {
        padding-right: 0.5rem;
    }
}

/* Ajustes adicionales para pantallas muy pequeñas */
@media (max-width: 480px) {
    .message {
        max-width: 370px;
    }
    
    .input-decorators {
        left: 0.5rem;
    }
    
    .input-actions {
        right: 0.5rem;
    }
    
    .mode-btn {
        padding: 0.4rem 0.7rem;
        font-size: 0.8rem;
    }
}


  
  

 /* Ocultar la nueva sidebar por defecto en desktop */
.mobile-sidebar {
    display: none;
  }
  
  /* Botón para activar la nueva sidebar en mobile */
  .mobile-sidebar-toggle-btn {
    position: fixed;
    top: 1rem;
    left: 1rem;
    background: #9152f5;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    z-index: 10000;
    display: none; /* Se mostrará solo en mobile */
  }
  
  /* Estilos para la nueva sidebar en mobile */
  @media (max-width: 768px) {
    /* Mostrar el botón de la sidebar */
    .mobile-sidebar-toggle-btn {
      display: block;
    }
    
    /* La nueva sidebar se muestra como overlay y oculta inicialmente */
    .mobile-sidebar {
      display: block;
      position: fixed;
      top: 0;
      left: -300px; /* Fuera de la vista inicialmente */
      width: 300px;
      height: 100vh;
      background: linear-gradient(160deg, var(--surface-200) 40%, rgba(26,26,31,0.8));
      padding: 1rem;
      transition: left 0.3s ease;
      z-index: 9999;
      overflow-y: auto;
    }
    
    /* Clase para activar la visualización de la nueva sidebar */
    .mobile-sidebar.active {
      left: 0;
    }
    
    /* Opcional: Estilos para el selector de modos dentro de la sidebar */
    .mobile-mode-selector {
      margin-top: 1rem;
    }
    
    .mobile-mode-selector .mode-btn {
      display: block;
      width: 100%;
      text-align: left;
      background: none;
      border: none;
      padding: 0.5rem 0;
      color: var(--text-color);
      font-size: 1rem;
    }
    
    .mobile-mode-selector .mode-btn.active {
      font-weight: bold;
    }
  }
  @media (max-width: 375px) {
    .message {
        max-width: 350px;
    }
}

@media (max-width: 320px) {
    .message {
        max-width: 300px;
    }
}

#chat-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    gap: 1rem;
    color: var(--text-color);
    z-index: 100;
  }
  
  .spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--primary);
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 1s linear infinite;
  }
  
  @keyframes spin {
    to { transform: rotate(360deg); }
  }