/* AI-CHAT-OMNI.CSS - VERSIÓN OPTIMIZADA Y MEJORADA */

/* --- Animaciones --- */
@keyframes blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.4;
  }
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes pulse {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.05);
  }
}

/* --- Variables CSS con colores más vibrantes --- */
:root {
  /* Colores principales */
  --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --secondary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  --success-gradient: linear-gradient(135deg, #00d2ff 0%, #3a7bd5 100%);

  /* Backgrounds */
  --background-main: #ffffff;
  --background-sidebar: linear-gradient(180deg, #f5f7fa 0%, #c3cfe2 100%);
  --background-input: #f8f9fa;
  --background-user-message: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --background-bot-message: linear-gradient(135deg, #ffffff 0%, #f5f7fa 100%);
  --background-hover: rgba(102, 126, 234, 0.1);

  /* Textos */
  --text-primary: #2c3e50;
  --text-secondary: #7f8c8d;
  --text-accent: #667eea;
  --text-success: #27ae60;
  --text-danger: #e74c3c;
  --text-warning: #f39c12;

  /* Otros */
  --border-color: rgba(0, 0, 0, 0.08);
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.16);
  --font-family: "Roboto", -apple-system, BlinkMacSystemFont, sans-serif;
  --sidebar-width: 280px;
  --border-radius: 12px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Reset y Base --- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  font-family: var(--font-family);
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  color: var(--text-primary);
  height: 100%;
  /* Usar 100% para evitar problemas con vh en móviles */
  display: flex;
  overflow: hidden;
  font-size: 16px;
  line-height: 1.6;
}

.app-container {
  display: flex;
  width: 100%;
  height: 100%;
  /* Heredar la altura del body */
  background: var(--background-main);
  box-shadow: var(--shadow-lg);
}

/* --- Material Icons --- */
.material-symbols-outlined {
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
  font-size: 20px;
  vertical-align: middle;
  line-height: 1;
}

/* --- Sidebar --- */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--background-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: relative;
  transition: var(--transition);
  flex-shrink: 0;
  z-index: 1000;
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.08);
}

.sidebar-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  background: var(--primary-gradient);
  color: white;
}

.sidebar-header img {
  width: 60px;
  height: 60px;
  object-fit: contain;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.3);
  box-shadow: var(--shadow-md);
}

.sidebar-title {
  font-size: 18px;
  font-weight: 600;
  color: white;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Botón Nuevo Chat */
.new-chat-button {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 12px 20px;
  margin: 16px;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: var(--transition);
  font-size: 15px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
}

.new-chat-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.new-chat-button:active {
  transform: translateY(0);
}

/* Historial */
.chat-history-container {
  flex-grow: 1;
  overflow-y: auto;
  padding: 0 8px 16px 8px;
}

.history-title {
  padding: 12px 16px 8px 16px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.8;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--border-radius);
  margin-bottom: 4px;
  cursor: pointer;
  transition: var(--transition);
  font-size: 14px;
  color: var(--text-primary);
  position: relative;
  overflow: hidden;
}

.chat-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 3px;
  background: var(--primary-gradient);
  transform: scaleY(0);
  transition: transform 0.3s ease;
}

.chat-item:hover {
  background: var(--background-hover);
  padding-left: 20px;
}

.chat-item:hover::before {
  transform: scaleY(1);
}

/* Footer Sidebar */
.sidebar-footer {
  padding: 8px;
  border-top: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.5);
}

.footer-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--border-radius);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: var(--transition);
}

.footer-link:hover {
  background: var(--background-hover);
  color: var(--text-accent);
  transform: translateX(4px);
}

/* --- Main Content --- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
  position: relative;
  overflow: hidden;
}

/* Header */
.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: white;
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

#toggle-button {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: var(--transition);
}

#toggle-button:hover {
  background: var(--background-hover);
  color: var(--text-accent);
}

.main-title {
  font-size: 20px;
  font-weight: 600;
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Controles Header */
.header-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.response-type-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

#response-type-select {
  font-family: var(--font-family);
  font-size: 14px;
  padding: 8px 16px;
  border: 2px solid transparent;
  border-radius: var(--border-radius);
  background: linear-gradient(white, white) padding-box,
    var(--primary-gradient) border-box;
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition);
  font-weight: 500;
}

#response-type-select:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.user-profile-area {
  cursor: pointer;
  transition: var(--transition);
}

.user-profile-area:hover {
  transform: scale(1.1);
}

.user-profile-area .material-symbols-outlined {
  font-size: 32px;
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* --- Chat Container --- */
.chat-container {
  flex-grow: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

/* Scrollbar personalizada */
.chat-container::-webkit-scrollbar {
  width: 10px;
}

.chat-container::-webkit-scrollbar-track {
  background: #f1f3f4;
  border-radius: 10px;
}

.chat-container::-webkit-scrollbar-thumb {
  background: var(--primary-gradient);
  border-radius: 10px;
}

.chat-container::-webkit-scrollbar-thumb:hover {
  background: var(--secondary-gradient);
}

/* --- Mensajes --- */
.message {
  display: flex;
  gap: 12px;
  max-width: 95%;
  padding: 16px 20px;
  border-radius: 20px;
  line-height: 1.6;
  position: relative;
  animation: slideInUp 0.4s ease-out;
  box-shadow: var(--shadow-md);
}

.message .icon {
  font-size: 24px;
  flex-shrink: 0;
  align-self: flex-start;
  padding: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
}

.message-content {
  flex-grow: 1;
  overflow-x: auto;
}

/* Mensaje Usuario */
.user-message {
  align-self: flex-end;
  background: var(--background-user-message);
  color: white;
  border-bottom-right-radius: 4px;
  margin-left: auto;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.user-message .icon {
  color: white;
  background: rgba(255, 255, 255, 0.2);
}

.user-message .message-content {
  color: white;
}

/* Mensaje Bot */
.bot-message {
  align-self: flex-start;
  background: var(--background-bot-message);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-color);
}

.bot-message .icon {
  color: var(--text-accent);
  background: rgba(102, 126, 234, 0.1);
}

/* Mensaje Error */
.bot-message.error-message {
  background: linear-gradient(135deg, #fff5f5 0%, #ffe0e0 100%);
  border-left: 4px solid var(--text-danger);
}

/* --- Estilos para contenido HTML en mensajes --- */

/* Tablas mejoradas */
.message-content table {
  border-collapse: separate !important;
  border-spacing: 0;
  width: 100%;
  margin: 20px 0;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  font-size: 14px;
  background: white;
}

.message-content table th,
.message-content table td {
  border: none !important;
  padding: 14px 18px !important;
  text-align: left;
  border-bottom: 1px solid #e8e8e8;
  border-right: 1px solid #e8e8e8;
  transition: background-color 0.2s ease;
}

.message-content table th:last-child,
.message-content table td:last-child {
  border-right: none;
}

.message-content table tr:last-child td {
  border-bottom: none;
}

.message-content table th {
  background: var(--primary-gradient);
  color: white !important;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.5px;
}

.message-content table tr:nth-child(even) {
  background-color: #f8f9fa;
}

.message-content table tr:hover {
  background: linear-gradient(90deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
  transform: scale(1.01);
  transition: all 0.2s ease;
}

/* Valores numéricos con colores */
.message-content td {
  position: relative;
}

/* Resaltar valores negativos */
.message-content span[style*="color: red"],
.message-content span[style*="color:#ff0000"],
.message-content span[style*="color:#dc3545"],
.message-content span[style*="color: #dc3545"] {
  color: #e74c3c !important;
  font-weight: 700;
  padding: 2px 6px;
  background: rgba(231, 76, 60, 0.1);
  border-radius: 4px;
}

/* Resaltar valores positivos */
.message-content span[style*="color: green"],
.message-content span[style*="color:#008000"],
.message-content span[style*="color:#28a745"],
.message-content span[style*="color: #28a745"] {
  color: #27ae60 !important;
  font-weight: 700;
  padding: 2px 6px;
  background: rgba(39, 174, 96, 0.1);
  border-radius: 4px;
}

/* Código mejorado */
.message-content code {
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
  color: #764ba2;
  padding: 3px 8px;
  border-radius: 6px;
  font-family: 'Fira Code', 'Courier New', monospace;
  font-size: 0.9em;
  font-weight: 500;
  border: 1px solid rgba(118, 75, 162, 0.2);
}

.message-content pre {
  background: linear-gradient(135deg, #1e1e2e 0%, #2d2d44 100%);
  color: #e0e0e0;
  padding: 20px;
  border-radius: 12px;
  overflow-x: auto;
  margin: 16px 0;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, 0.1);
  position: relative;
}

.message-content pre::before {
  content: 'CODE';
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.4);
  font-weight: 700;
  letter-spacing: 1px;
}

.message-content pre code {
  background: none;
  border: none;
  color: #e0e0e0;
  padding: 0;
}

/* Listas */
.message-content ul,
.message-content ol {
  margin: 16px 0 16px 30px;
  line-height: 1.8;
}

.message-content li {
  margin-bottom: 10px;
  position: relative;
  padding-left: 8px;
}

.message-content ul li::before {
  content: "▸";
  color: var(--text-accent);
  font-weight: bold;
  position: absolute;
  left: -20px;
  font-size: 1.2em;
}

/* Headers */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
  margin: 24px 0 16px 0;
  font-weight: 600;
  color: var(--text-primary);
  position: relative;
}

.message-content h1 {
  font-size: 2em;
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  padding-bottom: 12px;
  border-bottom: 2px solid transparent;
  border-image: var(--primary-gradient) 1;
}

.message-content h2 {
  font-size: 1.6em;
  color: #667eea;
}

.message-content h3 {
  font-size: 1.3em;
  color: #764ba2;
}

/* Párrafos */
.message-content p {
  margin: 16px 0;
  line-height: 1.7;
}

/* Enlaces */
.message-content a {
  color: var(--text-accent);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
  font-weight: 500;
  position: relative;
}

.message-content a:hover {
  color: #764ba2;
  border-bottom-color: #764ba2;
}

/* Blockquotes */
.message-content blockquote {
  border-left: 4px solid transparent;
  border-image: var(--primary-gradient) 1;
  margin: 20px 0;
  padding: 16px 24px;
  background: linear-gradient(90deg, rgba(102, 126, 234, 0.05) 0%, transparent 100%);
  border-radius: 8px;
  font-style: italic;
  position: relative;
}

.message-content blockquote::before {
  content: '"';
  font-size: 3em;
  color: rgba(102, 126, 234, 0.2);
  position: absolute;
  top: -10px;
  left: 10px;
}

/* HR */
.message-content hr {
  border: none;
  height: 2px;
  background: var(--primary-gradient);
  margin: 32px 0;
  border-radius: 2px;
  opacity: 0.3;
}

/* Marks */
.message-content mark {
  background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 500;
  color: #333;
}

/* Table wrapper responsive */
.message-content .table-wrapper {
  overflow-x: auto;
  margin: 20px 0;
  border-radius: 12px;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.05);
}

/* --- Loader mejorado --- */
.loader {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  align-self: center;
  animation: pulse 1.5s infinite;
}

.loader svg {
  filter: drop-shadow(0 4px 8px rgba(102, 126, 234, 0.3));
}

/* --- Input Area --- */
.input-area {
  padding: 20px 24px;
  background: white;
  border-top: 1px solid var(--border-color);
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.05);
  flex-shrink: 0;
}

.input-container {
  display: flex;
  align-items: flex-end;
  background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
  border-radius: 16px;
  padding: 8px 8px 8px 20px;
  border: 2px solid transparent;
  background-clip: padding-box;
  border: 2px solid #e8e8e8;
  transition: var(--transition);
  gap: 8px;
}

.input-container:focus-within {
  border-color: var(--text-accent);
  box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
  transform: translateY(-2px);
}

.input-container textarea {
  flex: 1;
  border: none;
  background: transparent;
  padding: 12px 0;
  font-size: 16px;
  line-height: 1.5;
  outline: none;
  resize: none;
  min-height: 24px;
  max-height: 150px;
  color: var(--text-primary);
  font-family: inherit;
  overflow-y: auto;
}

.input-container textarea::placeholder {
  color: var(--text-secondary);
  opacity: 0.6;
}

/* Botones de input */
.input-container button {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  padding: 10px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  color: white;
  box-shadow: var(--shadow-sm);
}

.input-container button:hover:not(:disabled) {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.input-container button:active:not(:disabled) {
  transform: scale(0.95);
}

.input-container button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  background: linear-gradient(135deg, #95a5a6 0%, #7f8c8d 100%);
}

.input-container button .material-symbols-outlined {
  font-size: 22px;
  font-variation-settings: 'FILL' 1, 'wght' 500;
}

/* Estados especiales de botones */
#dictate-text-button.dictating {
  background: linear-gradient(135deg, #00d2ff 0%, #3a7bd5 100%);
  animation: pulse 1.2s infinite;
}

#record-audio-button.recording {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  animation: pulse 1s infinite;
}

/* --- Overlay --- */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
  z-index: 999;
  display: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.overlay.show {
  display: block;
  opacity: 1;
}

/* --- Responsive --- */

/* --- TABLET VIEW (hasta 1024px) --- */
/* En tablets, colapsamos el sidebar a un modo de solo iconos */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 80px;
    /* Ancho del sidebar colapsado */
  }

  .sidebar {
    padding-top: 16px;
  }

  .sidebar-header {
    flex-direction: column;
    gap: 12px;
    padding: 12px;
  }

  .sidebar-header img {
    width: 48px;
    /* Imagen más pequeña */
    height: 48px;
  }

  .sidebar-title {
    display: none;
    /* Ocultamos el título */
  }

  .new-chat-button {
    margin: 16px 8px;
    padding: 12px;
    justify-content: center;
  }

  .new-chat-button span:last-child {
    display: none;
    /* Ocultamos texto "Nuevo Chat" */
  }

  .history-title {
    text-align: center;
    padding: 12px 0;
  }

  .chat-item {
    justify-content: center;
    padding: 12px;
  }

  .chat-item span:last-child {
    display: none;
    /* Ocultamos texto del historial */
  }

  .chat-item:hover {
    padding-left: 12px;
    /* Mantenemos padding al hacer hover */
  }

  .footer-link {
    justify-content: center;
    padding: 12px;
  }

  .footer-link span:last-child {
    display: none;
    /* Ocultamos texto del footer */
  }

  .footer-link:hover {
    transform: none;
    /* Quitamos la animación de traslación */
  }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    --sidebar-width: 280px;
    /* Restauramos el ancho original para el slide-in */
    padding-top: 0;
    /* Restauramos padding */
  }

  .sidebar-header {
    flex-direction: row;
    /* Restauramos la dirección para la vista móvil */
  }

  .sidebar.show {
    transform: translateX(0);
  }

  #toggle-button {
    display: block;
  }

  /* Hacemos el header principal más compacto */
  .main-header {
    padding: 12px 16px;
  }

  .message {
    max-width: 95%;
    /* Permitimos que los mensajes sean un poco más anchos */
  }

  .chat-container {
    padding: 16px;
  }

  .input-area {
    padding: 12px 16px;
    /* Ajustamos padding */
  }

  .response-type-container label {
    display: none;
  }

  #response-type-select {
    min-width: auto;
    font-size: 13px;
    padding: 6px 10px;
  }

  .message-content table {
    font-size: 12px;
  }

  .message-content table th,
  .message-content table td {
    padding: 10px 12px !important;
  }

  /* Restauramos la visibilidad de los textos dentro del sidebar cuando se abre en móvil */
  .sidebar.show .sidebar-title,
  .sidebar.show .new-chat-button span:last-child,
  .sidebar.show .chat-item span:last-child,
  .sidebar.show .footer-link span:last-child {
    display: inline;
  }

  /* Ajustamos el sidebar para que no sea tan grande cuando se abre en móvil */
  .sidebar.show .sidebar-header img {
    width: 40px;
    height: 40px;
  }

  .sidebar.show .sidebar-title {
    font-size: 16px;
  }
}
