/* === VARIABLES DE COLORES MINISTERIO DE VIVIENDA === */
:root {
  /* Colores principales del Ministerio */
  --primary-red: #d32f2f;        /* Rojo principal */
  --primary-blue: #1976d2;       /* Azul principal */
  --primary-white: #ffffff;      /* Blanco */
  
  /* Variaciones del rojo */
  --red-light: #ef5350;         /* Rojo claro */
  --red-dark: #c62828;          /* Rojo oscuro */
  --red-background: #ffebee;    /* Fondo rojo muy claro */
  
  /* Variaciones del azul */
  --blue-light: #42a5f5;        /* Azul claro */
  --blue-dark: #1565c0;         /* Azul oscuro */
  --blue-background: #e3f2fd;   /* Fondo azul muy claro */
  
  /* Colores neutros */
  --gray-50: #fafafa;
  --gray-100: #f5f5f5;
  --gray-200: #eeeeee;
  --gray-300: #e0e0e0;
  --gray-400: #bdbdbd;
  --gray-500: #9e9e9e;
  --gray-600: #757575;
  --gray-700: #616161;
  --gray-800: #424242;
  --gray-900: #212121;
  
  /* Sombras */
  --shadow-light: 0 2px 8px rgba(25, 118, 210, 0.15);
  --shadow-medium: 0 4px 16px rgba(25, 118, 210, 0.2);
  --shadow-strong: 0 8px 24px rgba(25, 118, 210, 0.25);
}

/* Estilos generales */
body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: var(--gray-50);
}

/* Botón flotante removido - chat siempre visible */

/* Caja del chat - Responsive para iframe */
#chat-box {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100%;
  max-height: 100%;
  margin: 0;
  padding: 0;
  background: var(--primary-white); 
  border-radius: 0;
  display: flex; 
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
}

/* Asegurar que ocupe todo el contenedor padre */
html, body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Cabecera */
.chat-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  background: var(--primary-blue);
  padding: 8px 12px;
  color: var(--primary-white);
  gap: 12px;
  position: relative;
  box-shadow: var(--shadow-light);
  flex-shrink: 0;
  min-height: 60px;
}

.chat-toggle-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: var(--primary-white);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.chat-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

.chat-header-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-white);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  overflow: hidden;
  box-shadow: var(--shadow-medium);
  border: 2px solid rgba(255, 255, 255, 0.8);
  flex-shrink: 0;
}

.chat-logo {
  width: 90%;
  height: 90%;
  object-fit: contain;
}

.chat-header-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  text-align: left;
  flex: 1;
  overflow: hidden;
}
.chat-header-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.chat-header-subtitle {
  margin: 2px 0 0 0;
  font-size: 11px;
  opacity: 0.95;
  font-weight: 400;
  text-align: left;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

/* Área de mensajes */
#panel {
  flex: 1;
  padding: 20px 4px 0 4px; /* Eliminado padding inferior para que no haya espacio en el bottom */
  overflow-y: auto;
  background: var(--gray-50);
  display: flex;
  flex-direction: column;
  gap: 4px; /* Reducido de 12px a 6px para menos espacio entre elementos */
  width: 100%; /* Asegurar ancho completo */
  height: 100%;
  box-sizing: border-box; /* Incluir padding en el cálculo del ancho */
}

/* Responsive para diferentes tamaños de pantalla */
@media (max-width: 480px) {
  #panel {
    padding: 16px 2px 0 2px; /* Eliminado padding inferior para que no haya espacio en el bottom */
  }

  .welcome-message {
    padding: 8px !important;
    margin-bottom: 8px !important;
  }

  .welcome-message .welcome-content p {
    font-size: 0.85rem !important;
  }

  .welcome-message .welcome-content > div > div {
    font-size: 0.8rem !important;
    padding: 3px 7px !important;
  }
}

@media (max-width: 320px) {
  #panel {
    padding: 12px 1px 0 1px; /* Eliminado padding inferior para que no haya espacio en el bottom */
  }
  
  .welcome-message .welcome-content > div {
    gap: 4px !important;
  }
  
  .welcome-message .welcome-content > div > div {
    font-size: 0.75rem !important;
    padding: 2px 6px !important;
  }
}

/* Estilos para tags interactivos */
.tag-item:hover {
  background: #d6e9ff !important;
  transform: scale(1.02);
  box-shadow: 0 2px 4px rgba(53,120,229,0.15);
}

/* Responsive text para tags */
@media (max-width: 600px) {
  .tag-text {
    display: none;
  }
  
  .tag-item {
    min-width: 35px;
    justify-content: center;
  }
  
  .tag-item span:first-child {
    margin-right: 0 !important;
  }
}

/* Para iframes y contenedores pequeños */
@media (max-height: 500px) {
  .chat-header {
    padding: 6px 10px !important;
    min-height: 50px !important;
  }
  
  .chat-header-logo {
    width: 36px !important;
    height: 36px !important;
  }
  
  .chat-header-title {
    font-size: 14px !important;
  }
  
  .chat-header-subtitle {
    font-size: 10px !important;
  }
  
  .welcome-message {
    padding: 6px !important;
    margin-bottom: 6px !important;
  }
  
  .welcome-content p {
    font-size: 0.8rem !important;
    margin: 4px 0 2px 0 !important;
  }
  
  .tags-container {
    margin-bottom: 4px !important;
    gap: 4px !important;
  }
  
  .tag-item {
    padding: 2px 6px !important;
    font-size: 0.8rem !important;
  }
}

/* Media query para pantallas muy pequeñas */
@media (max-width: 300px) {
  .chat-header {
    padding: 4px 8px !important;
    min-height: 45px !important;
  }
  
  .chat-header-logo {
    width: 32px !important;
    height: 32px !important;
  }
  
  .chat-header-title {
    font-size: 13px !important;
  }
  
  .chat-header-subtitle {
    font-size: 9px !important;
  }
}

/* Área de input */
#input-area {
  background: var(--primary-white);
  border-top: 2px solid var(--gray-200);
  padding: 16px 16px 0 16px; /* Eliminado padding inferior para que no haya espacio en el bottom */
}

.input-container {
  display: flex;
  background: var(--gray-100);
  border-radius: 25px;
  border: 2px solid var(--gray-300);
  overflow: hidden;
  transition: all 0.3s ease;
}

.input-container:focus-within {
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.1);
  background: var(--primary-white);
}

#input-area input {
  flex: 1;
  border: none;
  padding: 14px 18px;
  outline: none;
  font-size: 14px;
  background: transparent;
  color: var(--gray-800);
  font-family: inherit;
}

#input-area input::placeholder {
  color: var(--gray-500);
  font-style: italic;
}

#input-area button {
  background: var(--primary-blue);
  border: none;
  color: var(--primary-white);
  padding: 12px 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  border-radius: 50%;
  margin: 4px;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-light);
}

#input-area button:hover:not(:disabled) {
  background: var(--blue-dark);
  transform: scale(1.1);
  box-shadow: var(--shadow-medium);
}

#input-area button:disabled {
  background: var(--gray-400);
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
  box-shadow: none;
}

.input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 10px 0 0 0; /* Eliminado margin-bottom para que no haya espacio en el bottom */
  font-size: 12px;
  color: var(--gray-600);
}

.char-counter {
  font-size: 11px;
  color: var(--gray-500);
  font-weight: 500;
}

.powered-by {
  font-size: 11px;
  color: var(--gray-600);
  opacity: 0.8;
  font-weight: 500;
}

/* Burbujas */
/* Contenedor del mensaje */
.msg {
  max-width: 80%; /* Aumentado de 70% a 80% para mensajes más anchos */
  margin: 4px 16px 0 16px; /* Eliminado margin-bottom para evitar espacio extra en el bottom */
  padding: 14px 18px;
  border-radius: 18px;
  position: relative;
  display: inline-block;
  word-wrap: break-word;
  box-shadow: var(--shadow-light);
  font-size: 15px;
  line-height: 1.5;
  border: 1.5px solid transparent;
}

/* Agregar espacio solo entre mensajes consecutivos */
.msg:not(:last-child) {
  margin-bottom: 4px;
}

/* Mensajes del bot */
.msg.bot {
  background: var(--blue-background);
  color: var(--gray-900);
  align-self: flex-start;
  border-radius: 18px 18px 10px 18px;
  border: 1.5px solid var(--blue-light);
  margin-left: 16px; /* Margen desde el borde izquierdo */
  margin-right: auto; /* Se alinea a la izquierda */
  box-shadow: 0 2px 12px rgba(25, 118, 210, 0.10);
  position: relative;
  padding-left: 22px;
}
.msg.bot::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 18px;
  width: 10px;
  height: 10px;
  background: var(--blue-light);
  border-radius: 50%;
  opacity: 0.15;
}

/* Mensajes del usuario */
.msg.user {
  background: var(--primary-blue);
  color: var(--primary-white);
  align-self: flex-end;
  border-radius: 18px 18px 18px 10px;
  margin-right: 16px; /* Margen desde el borde derecho */
  margin-left: auto; /* Se alinea a la derecha */
  font-weight: 500;
  box-shadow: 0 2px 12px rgba(25, 118, 210, 0.12);
  border: 1.5px solid var(--primary-blue);
  position: relative;
  padding-right: 22px;
}
.msg.user::after {
  content: "";
  position: absolute;
  right: 8px;
  top: 18px;
  width: 10px;
  height: 10px;
  background: var(--primary-blue);
  border-radius: 50%;
  opacity: 0.18;
}

/* Texto del mensaje */
.msg-text {
  display: block;
  margin-bottom: 2px;
}

/* Hora del mensaje */
.msg-time-bot {
  font-size: 0.7rem;
  color: var(--gray-500);
  position: absolute;
  bottom: 4px;
  right: 8px;
  font-weight: 400;
}

.msg-time-user {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.8);
  align-self: flex-end;
  margin-top: 2px;
  font-weight: 400;
}

/* Opciones (botones sugeridos) */
.options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.options button {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-white);
  border: 2px solid var(--primary-blue);
  border-radius: 20px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  color: var(--primary-blue);
  transition: all 0.3s ease;
  font-weight: 500;
}

.options button:hover {
  background: var(--primary-blue);
  color: var(--primary-white);
  transform: translateY(-1px);
  box-shadow: var(--shadow-light);
}

#chat-box {
  pointer-events: auto;
}

/* Mensaje de bienvenida */
.welcome-message {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  background: var(--blue-background);
  border: 2px solid var(--blue-light);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 16px;
  animation: fadeInUp 0.6s ease-out;
  box-shadow: var(--shadow-light);
}

.bot-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--primary-white);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-medium);
  border: 2px solid var(--primary-blue);
}

.bot-avatar img {
  width: 26px;
  height: 26px;
}

.welcome-content {
  flex: 1;
}

.welcome-content p {
  margin: 0 0 10px 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--gray-800);
  font-weight: 400;
}

.welcome-content p:last-child {
  margin-bottom: 0;
  font-weight: 500;
  color: var(--primary-blue);
}

/* Indicador de escritura */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: var(--primary-white);
  border-top: 2px solid var(--gray-200);
  animation: slideInUp 0.3s ease-out;
}

.typing-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--blue-background);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid var(--primary-blue);
}

.typing-avatar img {
  width: 20px;
  height: 20px;
  opacity: 0.8;
}

.typing-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.typing-text {
  font-size: 12px;
  color: var(--gray-600);
  font-style: italic;
  font-weight: 500;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dots .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary-blue);
  animation: typingAnimation 1.4s infinite ease-in-out;
  box-shadow: var(--shadow-light);
}

.typing-dots .dot:nth-child(1) {
  animation-delay: 0s;
}

.typing-dots .dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots .dot:nth-child(3) {
  animation-delay: 0.4s;
}

/* Animaciones */
@keyframes typingAnimation {
  0%, 60%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  30% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Mejoras en los mensajes */
.msg {
  animation: fadeInUp 0.3s ease-out;
}

@keyframes fadeOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-20px);
  }
}

/* Mejoras responsive */
@media (max-width: 600px) {
  #chat-box {
    width: 100%;
    height: 100%;
    bottom: 0px;
    right: 0px;
  }

  .chat-header-logo {
    width: 80px;
    height: 80px;
  }

  .chat-header-title {
    font-size: 16px;
  }

  .chat-header-subtitle {
    font-size: 12px;
  }
}
