:root {
  --robot-image: url('../images/robot.png');
  --robot3-image: url('../images/robot3.png');
}

/* ========= Popup principal ========= */

.popup {
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 55%;
  right: 0;
  transform: translateY(-50%);
  width: 23.2%;
  height: 82%;
  background: #f4f4f4;
  border: 1px solid #fff;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  z-index: 9999;
  transition: all .3s ease;
  min-height: 0;
}

.popup .chat-footer {
  flex: 0 0 auto;
}

/* ========= Estado minimizado ========= */
.popup.minimized {
  width: 84px;
  height: 84px;
  background: #2B5C9E;
  border: none;
  border-radius: 50%;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
  cursor: pointer;
  position: fixed;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
}
.popup.minimized::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: var(--robot-image);
  background-size: 95%;
  background-position: center;
  background-repeat: no-repeat;
  border-radius: 50%;
}
.popup.minimized .header,
.popup.minimized .content,
.popup.minimized .chat-footer,
.popup.minimized .powered-by {
  display: none !important;
}

/* ========= Header ========= */
.popup .header {
  flex: 0 0 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #2B5C9E;
  color: #fff;
  padding: 0 16px;
  border-radius: 10px 10px 0 0;
}
.popup .header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.popup .header img.robot-header {
  width: 26px;
  height: 26px;
}
.popup .header span {
  flex-grow: 1;
  font-weight: bold;
  font-size: 16px;
}
.popup .header-buttons {
  display: flex;
  gap: 6px;
}
.popup .header-buttons button {
  background: #fff;
  color: #2B5C9E;
  border: none;
  border-radius: 5px;
  font-weight: bold;
  padding: 4px 8px;
  cursor: pointer;
}
.popup .header-buttons button:hover {
  background: #e6e6e6;
}

/* ========= Contenido ========= */
.popup .content {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
  padding: 12px;
  background: #f4f4f4;
}
.popup .content::-webkit-scrollbar {
  width: 6px;
}
.popup .content::-webkit-scrollbar-track {
  background: #ddd;
  border-radius: 3px;
}
.popup .content::-webkit-scrollbar-thumb {
  background-color: #2B5C9E;
  border-radius: 3px;
}
.popup .content {
  scrollbar-width: thin;
  scrollbar-color: #2B5C9E #ddd;
}

/* ========= Mensajes ========= */
.user-message {
  background: #2B5C9E;
  color: #fff;
  padding: 10px 12px;
  border-radius: 5px;
  margin-bottom: 8px;
  margin-top: 8px;  
  max-width: 90%;
}
.response-container {
  margin-left: 40px;
  background: #fff;
  padding: 10px 12px;
  border-radius: 12px;
  margin-top: 5px;
  max-width: 80%;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  position: relative;
}
.response-container::before {
  content: "";
  position: absolute;
  left: -35px;
  top: 8px;
  width: 28px;
  height: 28px;
  background-image: var(--robot3-image);
  background-size: 28px 28px;
  background-repeat: no-repeat;
}
.response-text {
  font-family: Arial, sans-serif;
  font-size: 14px;
  color: #333;
  white-space: pre-wrap;
}

/* ========= Footer ========= */
.chat-footer {
  flex: 0 0 auto;
  background: #f4f4f4;
  padding: 8px 16px;
}
.chat-footer .input-row {
  display: flex;
  gap: 8px;
}
.chat-footer .input-row input {
  flex: 1;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
}
.chat-footer .input-row .send-btn {
  background: #2B5C9E;
  color: #fff;
  border: none;
  border-radius: 4px;
  width: 40px;
  font-size: 16px;
  cursor: pointer;
}
.chat-footer .btn-row {
  margin-top: 8px;
  display: flex;
}
.chat-footer .btn-row .reset-btn {
  flex: 1;
  padding: 8px;
  background: #1E4480;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-weight: bold;
  cursor: pointer;
}

/* ========= Powered by ========= */
.powered-by {
  flex: 0 0 30px;
  background: linear-gradient(to bottom, #2B5C9E, #1E4480);
  color: #fff;
  text-align: center;
  font-size: 12px;
  line-height: 30px;
  border-radius: 0 0 10px 10px;
}

/* ========= Formularios ========= */
.email-form-inline input,
.email-form-inline textarea {
  font-size: 14px;
  padding: 6px;
  border-radius: 6px;
  border: 1px solid #ccc;
  margin-bottom: 6px;
  background: #f9f9f9;
}
.email-form-inline button {
  padding: 6px 12px;
  background-color: #2B5C9E;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
.email-form-inline button:hover {
  background-color: #1E4480;
}

/* ========= Welcome bubble ========= */
.welcome-bubble {
  position: fixed;
  right: 100px;
  top: 50%;
  transform: translateY(-50%);
  background: #2B5C9E;
  color: white;
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  font-size: 14px;
  z-index: 9999;
  opacity: 1;
  transition: opacity 0.5s ease;
}

.user-message .response-text {
  color: #fff !important;
}

#popup.oculto {
  display: none !important;
}

#popup {
  display: flex !important;
  flex-direction: column !important;
  height: 82vh !important;
  min-height: 350px !important;
  max-height: 95vh !important;
}

#popup .content {
  flex: 1 1 0 !important;
  min-height: 0 !important;
  overflow-y: auto !important;
}

#popup .chat-footer,
#popup .powered-by {
  flex-shrink: 0 !important;
  flex-grow: 0 !important;
}

#popup.minimized {
  display: block !important;
  height: 84px !important;
  width: 84px !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow: visible !important;
  padding: 0 !important;
  flex-direction: unset !important;
}

/* ========= ESTILOS MÓVILES ========= */
@media (max-width: 768px) {
  
  /* Overlay oscuro de fondo */
  .mobile-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    display: none;
  }

  /* Círculo minimizado en móvil */
  .popup.minimized {
    width: 60px;
    height: 60px;
    right: 15px;
    bottom: 15px;
    top: auto;
    transform: none;
    z-index: 9999;
  }
  
  .popup.minimized::before {
    background-size: 70%;
  }

  /* Popup expandido en móvil - ocupa casi toda la pantalla */
  .popup:not(.minimized) {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 400px;
    height: 80vh;
    max-height: 600px;
    border-radius: 15px;
    z-index: 9999;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  }

  /* Ajustar welcome bubble para móvil */
  .welcome-bubble {
    right: 80px !important;
    bottom: 25px !important;
    top: auto !important;
    transform: none !important;
    font-size: 12px;
    padding: 10px 12px;
    max-width: 220px;
    line-height: 1.3;
  }

  /* Ajustar mensajes para móvil */
  .user-message {
    max-width: 85%;
    font-size: 14px;
  }

  .response-container {
    max-width: 85%;
    margin-left: 35px;
    font-size: 14px;
  }

  .response-container::before {
    width: 24px;
    height: 24px;
    left: -30px;
    background-size: 24px 24px;
  }

  /* Ajustar inputs para móvil */
  .chat-footer .input-row input {
    font-size: 16px; /* Evita zoom en iOS */
    padding: 10px;
  }

  .chat-footer .input-row .send-btn {
    width: 45px;
    font-size: 18px;
  }

  .chat-footer .btn-row .reset-btn {
    padding: 10px;
    font-size: 14px;
  }

  /* Formulario de email en móvil */
  .email-form-inline input,
  .email-form-inline textarea {
    font-size: 16px; /* Evita zoom en iOS */
    padding: 8px;
  }

  .email-form-inline button {
    padding: 10px 12px;
    font-size: 16px;
  }

  /* Header en móvil */
  .popup .header {
    flex: 0 0 55px;
  }

  .popup .header span {
    font-size: 15px;
  }

  .popup .header img.robot-header {
    width: 24px;
    height: 24px;
  }

  /* Powered by en móvil */
  .powered-by {
    flex: 0 0 35px;
    line-height: 35px;
    font-size: 11px;
  }
}

/* Para pantallas muy pequeñas */
@media (max-width: 380px) {
  .popup:not(.minimized) {
    width: 95%;
    height: 85vh;
  }

  .popup.minimized {
    width: 55px;
    height: 55px;
    right: 10px;
    bottom: 10px;
  }

  .popup.minimized::before {
    background-size: 65%;
  }
}
