@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  /* --- PALETA DE COLORES (Clean Pharma) --- */
  --primary-500: #059669; /* Emerald rico */
  --primary-600: #047857;
  --primary-glow: rgba(5, 150, 105, 0.3);
  
  --bg-app: #f1f5f9;      /* Slate muy claro */
  --bg-surface: #ffffff;
  
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-tertiary: #94a3b8;
  
  --border-light: #e2e8f0;
  
  /* Gradientes */
  --gradient-primary: linear-gradient(135deg, #10b981 0%, #059669 100%);
  --gradient-bg: radial-gradient(circle at 0% 0%, rgba(16, 185, 129, 0.15), transparent 40%),
                 radial-gradient(circle at 100% 100%, rgba(59, 130, 246, 0.1), transparent 40%);

  /* Sombras y Efectos */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --shadow-float: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
  
  --radius-msg: 18px;
  --radius-input: 24px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-app);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  height: 100vh;
  overflow: hidden;
}

/* --- LAYOUT PRINCIPAL --- */
.app-layout {
  display: flex;
  justify-content: center;
  height: 100dvh; /* Usamos dvh para mejor soporte en móviles */
  width: 100%;
  background-image: var(--gradient-bg);
  background-attachment: fixed; /* El fondo se queda quieto */
}
.main-container {
  width: 100%;
  max-width: 900px; /* Ancho máximo para que no se vea estirado en monitores grandes */
  height: 100%;     /* Ocupa toda la altura disponible */
  display: flex;
  flex-direction: column;
  position: relative;
  
  /* Mantenemos el efecto cristal */
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(20px);
  
  /* Quitamos los bordes redondeados externos y márgenes para que toque los bordes */
  margin: 0;
  border-radius: 0;
  border: none;
  box-shadow: 0 0 60px rgba(0,0,0,0.05);
}
@media (min-width: 820px) {
  .main-container {
    margin: 20px;
    border-radius: 24px;
    height: calc(100% - 40px);
    border: 1px solid rgba(255,255,255,0.8);
  }
}
.header-controls {
  display: flex;
  align-items: center;
  gap: 12px; /* Espacio entre los botones */
}
/* --- HEADER --- */
.app-header {
  flex: 0 0 auto;
  /* Cambiamos height fijo por min-height para que se adapte si crece el padding */
  min-height: 70px;
  height: auto; 
  
  display: flex;
  align-items: center;
  justify-content: space-between;
  
  /* --- MAGIA PARA IPHONE --- */
  /* En PC usará 12px. En iPhone usará el espacio del notch (aprox 47px) + un poquito extra */
  padding-top: max(12px, env(safe-area-inset-top));
  padding-bottom: 12px;
  padding-left: 24px;
  padding-right: 24px;
  
  border-bottom: 1px solid rgba(0,0,0,0.05);
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(10px);
  z-index: 10;
  
  /* Quitamos el border-radius superior en móvil para que parezca una app nativa */
  border-radius: 0; 
}

/* Solo devolvemos el borde redondeado si estamos en PC/Tablet */
@media (min-width: 820px) {
  .app-header {
    border-radius: 24px 24px 0 0;
    padding-top: 0; /* En el modal flotante de PC no necesitamos el espacio del notch */
    height: 70px;   /* Volvemos a altura fija en PC */
  }
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-wrapper {
  width: 40px;
  height: 40px;
  background: white;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

.logo-wrapper img {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.brand-text h1 {
  font-size: 1.0rem;
  font-weight: 700;
  margin: 0;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.badge {
  font-size: 0.6rem;
  background: #dbeafe;
  color: #1e40af;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
  margin-top: 2px;
  display: inline-block;
}

/* --- CHAT AREA --- */
.chat-scroll-area {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding-bottom: 20px;
  background: transparent;
}

.chat-content {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.message-row {
  display: flex;
  width: 100%;
  animation: slideUp 0.3s ease-out;
}

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

.message-row.user { justify-content: flex-end; }
.message-row.ai { justify-content: flex-start; }

.message-bubble {
  max-width: 85%;
  padding: 0;
  position: relative;
}

.message-text {
  padding: 14px 18px;
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-wrap;
  white-space: pre-line;
}

/* Estilos específicos de burbuja */
.ai .message-bubble {
  background: var(--bg-surface);
  border-radius: 4px var(--radius-msg) var(--radius-msg) var(--radius-msg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
}

.user .message-bubble {
  background: var(--gradient-primary);
  color: white;
  border-radius: var(--radius-msg) var(--radius-msg) 4px var(--radius-msg);
  box-shadow: 0 4px 12px var(--primary-glow);
}

.message-time {
  font-size: 0.65rem;
  margin-top: 4px;
  text-align: right;
  opacity: 0.6;
  padding: 0 4px;
}
.user .message-time { color: rgba(255,255,255,0.9); }

/* --- CITAS / REFERENCIAS --- */
.citations-wrapper {
  margin: 0 12px 12px 12px;
  background: #f8fafc;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  overflow: hidden;
}

.citations-header {
  padding: 8px 12px;
  background: #f1f5f9;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid #e2e8f0;
}

.citations-list {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.citation-card {
  background: white;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  transition: all 0.2s;
  cursor: default;
}

.citation-card:hover { border-color: var(--primary-500); }

.citation-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary-600);
  margin-bottom: 2px;
}

.citation-snippet {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-style: italic;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* --- TYPING INDICATOR --- */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: white;
  border-radius: 4px 18px 18px 18px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
  width: fit-content;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background: var(--text-tertiary);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

.composer-dock {
  flex: 0 0 auto;
  
  /* Padding base: Arriba 12px, Lados 14px. 
     Abajo: calculamos 10px base + el espacio seguro del iPhone */
  padding: 12px 14px calc(10px + env(safe-area-inset-bottom)) 14px;
  
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(15px);
  border-top: 1px solid rgba(0,0,0,0.05);
  
  /* En móvil, quitamos el borde redondeado inferior para que toque el fondo de pantalla */
  border-radius: 0;
}

@media (min-width: 820px) {
  .composer-dock {
    /* En PC sí queremos bordes redondeados y padding normal */
    border-radius: 0 0 24px 24px;
    padding-bottom: 12px; 
  }
}

.auth-banner {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
  background: #f1f5f9;
  padding: 6px;
  border-radius: 8px;
}

.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  background: white;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-input);
  padding: 8px;
  box-shadow: var(--shadow-sm);
  transition: all 0.3s ease;
}

.input-bar:focus-within {
  border-color: var(--primary-500);
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.1);
}

.input-bar.disabled { opacity: 0.7; background: #f8fafc; }

textarea {
  flex: 1;
  border: none;
  background: transparent;
  padding: 12px 8px 12px 16px;
  font-family: inherit;
  font-size: 0.95rem;
  resize: none;
  outline: none;
  max-height: 120px;
  color: var(--text-primary);
}

.send-fab {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--text-primary); /* Dark button for contrast */
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, background 0.2s;
  flex-shrink: 0;
}

.send-fab:hover:not(:disabled) {
  background: var(--primary-500);
  transform: scale(1.05);
}
.send-fab:disabled { background: #cbd5e1; cursor: not-allowed; }

.legal-footer {
  text-align: center;
  font-size: 0.60rem;
  color: var(--text-tertiary);
  margin-top: 8px;
  /* El padding bottom ya lo maneja el .composer-dock, aquí lo quitamos */
  padding-bottom: 0; 
}
/* --- BOTONES --- */
.btn {
  padding: 8px 16px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary-500);
  color: white;
  box-shadow: 0 4px 10px var(--primary-glow);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-600); transform: translateY(-1px); }

.btn-secondary { background: #e2e8f0; color: var(--text-primary); }
.btn-secondary:hover { background: #cbd5e1; }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: rgba(0,0,0,0.05); color: var(--text-primary); }

.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.full-width { width: 100%; }

/* --- MODAL --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4); /* Slate dark backdrop */
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  background: white;
  width: 100%;
  max-width: 420px;
  border-radius: 24px;
  box-shadow: var(--shadow-float);
  overflow: hidden;
  animation: modalIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.modal-header {
  padding: 24px 24px 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.modal-title-group h2 { margin: 0; font-size: 1.5rem; color: var(--text-primary); }
.modal-subtitle { margin: 6px 0 0 0; color: var(--text-secondary); font-size: 0.9rem; }

.modal-body { padding: 24px; display: flex; flex-direction: column; gap: 16px; }

.input-field {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  font-size: 1rem;
  outline: none;
  transition: all 0.2s;
  background: #f8fafc;
}
.input-field:focus {
  background: white;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.1);
}

.modal-footer {
  padding: 0 24px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-links {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.modal-links span { cursor: pointer; transition: color 0.2s; }
.modal-links span:hover { color: var(--primary-500); }

.icon-btn {
  background: none; border: none; cursor: pointer; color: var(--text-tertiary);
  padding: 4px; border-radius: 50%; transition: all 0.2s;
}
.icon-btn:hover { background: #f1f5f9; color: var(--text-primary); }

.input-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.input-grid .full-width { grid-column: span 2; }
.info-box { font-size: 0.8rem; color: #854d0e; background: #fef9c3; padding: 10px; border-radius: 8px; }

/* --- TOAST --- */
.toast-notification {
  /* Cambio clave: de absolute a fixed */
  position: fixed; 
  /* Ajustamos la altura para que se vea bien arriba */
  top: 30px; 
  left: 50%;
  transform: translateX(-50%);
  
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  border-radius: 50px;
  
  /* Z-index muy alto, superior al del modal (que suele ser 100 o 200) */
  z-index: 9999; 
  
  background: rgba(30, 41, 59, 0.95);
  color: white;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  backdrop-filter: blur(8px);
  font-size: 0.9rem;
  font-weight: 500;
  
  /* Animación */
  animation: slideDownToast 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none; /* Para que no bloquee clicks si es transparente */
}
.toast-notification.error { background: rgba(220, 38, 38, 0.9); }

.toast-icon {
  width: 20px; height: 20px;
  background: rgba(255,255,255,0.2);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: bold; font-size: 0.8rem;
}

@keyframes slideDownToast {
  from { opacity: 0; transform: translate(-50%, -20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
.citations-wrapper {
  margin-top: 12px;
  background: rgba(0, 0, 0, 0.03); /* Fondo muy sutil */
  border-radius: 8px;
  padding: 10px;
  border: 1px solid rgba(0,0,0,0.05);
}

.citation-card {
  background: white;
  padding: 8px;
  margin-bottom: 6px;
  border-radius: 4px;
  border: 1px solid #eee;
  font-size: 0.85rem;
}


/* Links legales en el footer */
.legal-footer {
  text-align: center;
  font-size: 0.75rem;
  color: #999;
  padding: 1rem 0;
  margin-top: auto; /* Empuja el footer al fondo si usas flex column */
}

.legal-links-row {
  margin-top: 5px;
  display: flex;
  justify-content: center;
  gap: 8px;
}

.legal-links-row a {
  color: #888;
  text-decoration: none;
  transition: color 0.2s;
}

.legal-links-row a:hover {
  color: #2b7de9; /* Color primario */
  text-decoration: underline;
}

.separator {
  color: #ccc;
}

/* Enlaces dentro del modal (Checkbox) */
.link-legal {
  color: #2b7de9;
  text-decoration: none;
  font-weight: 500;
}
.link-legal:hover {
  text-decoration: underline;
}

/* Estado deshabilitado del botón para que se note */
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
/* Estilos para las páginas legales */
.legal-page-container {
  display: flex;
  justify-content: center;
  padding: 40px 20px;
  background-color: #f9fafb;
  min-height: 100vh;
  overflow-y: auto;
}

.legal-card {
  background: white;
  max-width: 800px;
  width: 100%;
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.05);
}

.legal-content-body h3 {
  margin-top: 25px;
  color: #111827;
  font-size: 1.2rem;
}

.legal-content-body p, .legal-content-body ul {
  color: #4b5563;
  line-height: 1.6;
  margin-bottom: 15px;
}

/* Links en el footer y modal que parecen botones */
.link-legal-footer, .link-legal {
  cursor: pointer;
  color: #2b7de9;
  text-decoration: none;
}
.link-legal-footer:hover, .link-legal:hover {
  text-decoration: underline;
}
/* Botón de peligro */
.btn-danger {
  background-color: #dc2626;
  color: white;
  border: none;
}
.btn-danger:hover:not(:disabled) {
  background-color: #b91c1c;
}

/* Caja de advertencia en el modal */
.warning-box {
  background-color: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  margin-bottom: 16px;
  line-height: 1.4;
}
/* Zona de peligro en el footer */
.footer-danger-zone {
  margin-top: 12px; /* Separación de los links legales */
  display: flex;
  justify-content: center;
}

.link-danger-footer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem; /* Mismo tamaño que el footer */
  color: #dc2626;     /* Color rojo */
  cursor: pointer;
  opacity: 0.8;
  transition: all 0.2s ease;
  padding: 4px 8px;
  border-radius: 4px;
}

.link-danger-footer:hover {
  opacity: 1;
  background-color: #fef2f2; /* Fondo rojo muy suave al pasar el ratón */
  text-decoration: underline;
}

.link-danger-footer svg {
  width: 14px;
  height: 14px;
}
/* Contenedor principal de sugerencias */
.suggestions-grid {
  margin: 20px 0;
  padding: 0 10px;
  animation: fadeIn 0.5s ease-in-out;
}

.suggestions-title {
  font-size: 0.85rem;
  color: #888;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

/* Grid para los botones */
.suggestions-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); /* Ajustable según ancho */
  gap: 10px;
}

/* Estilo del botón de sugerencia */
.suggestion-btn {
  background-color: var(--bg-card, #fff); /* Usa tus variables de tema */
  border: 1px solid var(--border-color, #e0e0e0);
  padding: 12px 16px;
  border-radius: 12px;
  text-align: left;
  font-size: 0.9rem;
  color: var(--text-primary, #333);
  cursor: pointer;
  transition: all 0.2s ease;
  line-height: 1.4;
  box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.suggestion-btn:hover {
  background-color: var(--primary-color-light, #f0f7ff); /* Color suave al hover */
  border-color: var(--primary-color, #007bff);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.05);
}

/* Animación simple */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- MARKDOWN EN BURBUJAS --- */
.message-text {
  white-space: normal;
}
.message-text p { margin: 4px 0; line-height: 1.6; }
.message-text ol,
.message-text ul { padding-left: 20px; margin: 8px 0; }
.message-text li { margin-bottom: 6px; line-height: 1.5; }
.message-text li > p { margin: 0; }
.message-text h1,
.message-text h2,
.message-text h3 { font-size: 0.95rem; font-weight: 700; margin: 8px 0 4px; }
.message-text hr { border: none; border-top: 1px solid var(--border-light); margin: 10px 0; }
.message-text a { color: var(--primary-500); text-decoration: none; }
.message-text a:hover { text-decoration: underline; }
.message-text strong { font-weight: 600; }



/* --- FOOTER COMPACTO EN MÓVIL --- */
@media (max-width: 819px) {
  .legal-footer {
    margin-top: 4px;
  }
  .legal-footer p {
    margin: 0 0 2px 0;
    font-size: 0.58rem;
  }
  .legal-links-row {
    margin-top: 2px;
    gap: 5px;
  }
  .footer-danger-zone {
    margin-top: 6px;
  }
  .link-danger-footer {
    font-size: 0.68rem;
  }
}
