/* ==========================================================================
   VARIABLES Y CONFIGURACIÓN BASE
   ========================================================================== */
:root {
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --primary: #0ea5e9;
  --primary-hover: #0284c7;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  
  /* Burbujas de chat */
  --chat-user-bg: #0ea5e9;
  --chat-user-text: #ffffff;
  --chat-bot-bg: #f1f5f9;
  --chat-bot-text: #0f172a;
  
  /* Sombras y bordes */
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -1px rgba(0,0,0,0.03);
  --transition: all 0.25s ease;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Modificación en el body base */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* Mantiene la app fija sin scroll general */
}

/* ==========================================================================
   COMPONENTES DE LA INTERFAZ (SPA)
   ========================================================================== */

/* Banner de Notificaciones */
.toast-notification {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: white;
  padding: 12px 20px;
  text-align: center;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 15px;
  z-index: 1000;
}

.toast-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
  transition: var(--transition);
}

.toast-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Contenedor del Chat (Layout Principal) */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-w: 768px;
  width: 100%;
  margin: 0 auto;
  background-color: var(--bg-card);
  box-shadow: var(--shadow-md);
  position: relative;
}

/* Encabezado */
.chat-header {
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
  color: white;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.header-title h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.header-title p {
  font-size: 0.75rem;
  opacity: 0.85;
  margin-top: 2px;
}

/* Botón de Instalación PWA */
.btn-install {
  background-color: rgba(255, 255, 255, 0.2);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.4);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: var(--transition);
}

.btn-install:hover {
  background-color: white;
  color: var(--primary);
  transform: translateY(-1px);
}

/* ==========================================================================
   ÁREA DEL CHAT Y BURBUJAS
   ========================================================================== */
.chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  background-color: var(--bg-main);
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

/* Estructura del Mensaje */
.message-wrapper {
  display: flex;
  width: 100%;
}

.message-wrapper.user {
  justify-content: flex-end;
}

.message-wrapper.bot {
  justify-content: flex-start;
}

/* Burbuja Base */
.message-bubble {
  max-width: 75%;
  padding: 12px 16px;
  font-size: 0.925rem;
  line-height: 1.5;
  box-shadow: var(--shadow-sm);
  animation: fadeIn 0.3s ease-out forwards;
}

/* Burbuja Paciente */
.message-wrapper.user .message-bubble {
  background-color: var(--chat-user-bg);
  color: var(--chat-user-text);
  border-radius: var(--radius-lg) var(--radius-lg) 2px var(--radius-lg);
}

/* Burbuja ChatGPT / RAG */
.message-wrapper.bot .message-bubble {
  background-color: var(--chat-bot-bg);
  color: var(--chat-bot-text);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 2px;
  border: 1px solid var(--border-color);
}

/* ==========================================================================
   BARRA DE ENTRADA (INPUT)
   ========================================================================== */
.chat-footer {
  padding: 14px 20px;
  background-color: var(--bg-card);
  border-top: 1px solid var(--border-color);
}

.chat-form {
  display: flex;
  gap: 10px;
  align-items: center;
}

.chat-input {
  flex: 1;
  height: 44px;
  padding: 0 16px;
  background-color: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  color: var(--text-main);
  transition: var(--transition);
}

.chat-input:focus {
  outline: none;
  border-color: var(--primary);
  background-color: var(--bg-card);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

.chat-input::placeholder {
  color: var(--text-muted);
}

.btn-send {
  height: 44px;
  padding: 0 20px;
  background-color: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-send:hover {
  background-color: var(--primary-hover);
}

.btn-send:active {
  transform: scale(0.98);
}

/* ==========================================================================
   FORMULARIO DE REGISTRO INICIAL (CORREGIDO Y ESTILIZADO)
   ========================================================================== */
.register-view-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 16px;
  overflow-y: auto;
  background-color: var(--bg-main);
}

.register-card {
  max-width: 440px;
  width: 100%;
  background-color: var(--bg-card);
  padding: 24px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  box-sizing: border-box;
}

.register-card h2 {
  color: var(--primary);
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 6px;
  text-align: center;
}

.register-card p {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  margin-bottom: 20px;
  line-height: 1.4;
}

/* Manejo de grupos de campos */
.form-group {
  display: flex;
  flex-direction: column;
  margin-bottom: 14px;
  width: 100%;
  box-sizing: border-box;
}

/* Filas paralelas de dos columnas perfectamente alineadas */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  width: 100%;
  box-sizing: border-box;
}

.form-group label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
  letter-spacing: 0.05em;
  text-align: left;
}

/* Estilo explícito y moderno para los inputs */
.form-group input {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  background-color: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  color: var(--text-main);
  box-sizing: border-box;
  transition: var(--transition);
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary);
  background-color: #ffffff;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

.form-group input::placeholder {
  color: #cbd5e1;
}

/* Botón de envío */
.btn-submit {
  width: 100%;
  height: 46px;
  background-color: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 10px;
  box-sizing: border-box;
  transition: var(--transition);
}

.btn-submit:hover {
  background-color: var(--primary-hover);
}

.btn-submit:active {
  transform: scale(0.99);
}

/* UTILIDADES */
.hidden { display: none !important; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}


/* ==========================================================================
   ANIMACIÓN DE CARGA (TRES PUNTOS)
   ========================================================================== */
.typing-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 18px !important;
  background-color: var(--chat-bot-bg) !important;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 2px !important;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background-color: var(--text-muted);
  border-radius: 50%;
  opacity: 0.4;
  animation: typingBounce 1.4s infinite both;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  50% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* ==========================================================================
   PANTALLA DE BLOQUEO / COMPROBACIÓN PWA
   ========================================================================== */
.gate-view-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 20px;
  background-color: var(--bg-main);
}

.gate-card {
  max-width: 400px;
  width: 100%;
  background-color: var(--bg-card);
  padding: 35px 25px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  text-align: center;
  box-sizing: border-box;
}

.gate-icon {
  font-size: 3.5rem;
  margin-bottom: 16px;
  animation: pulseIcon 2s infinite ease-in-out;
}

.gate-card h2 {
  color: #0f172a;
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.gate-card p {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 24px;
}

.btn-gate-submit {
  width: 100%;
  height: 48px;
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.25);
}

.btn-gate-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(14, 165, 233, 0.35);
}

.gate-hint {
  font-size: 0.8rem !important;
  background-color: var(--bg-main);
  padding: 10px;
  border-radius: var(--radius-sm);
  margin-top: 20px;
  margin-bottom: 0 !important;
  border: 1px dashed var(--border-color);
}

.share-icon {
  display: inline-block;
  font-weight: bold;
  color: var(--primary);
}

@keyframes pulseIcon {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}
