diff --git a/calendario.html b/calendario.html
index 9e330c0..d27fb33 100644
--- a/calendario.html
+++ b/calendario.html
@@ -650,9 +650,35 @@
safeLoadIcons();
}
- function openService(id) {
- const s = localServices.find(x => x.id === id);
- if (!s || s.provider === 'SYSTEM_BLOCK') return;
+ async function openService(id) {
+ let s = localServices.find(x => x.id === id);
+
+ // š„ SOLUCIĆN: Si no lo encontramos en memoria, lo pedimos al servidor
+ if (!s) {
+ showToast("Cargando expediente...");
+ try {
+ const res = await fetch(`${API_URL}/services/active`, {
+ headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
+ });
+ const data = await res.json();
+ if (data.ok) {
+ // Lo buscamos en la base de datos completa de servicios activos
+ s = data.services.find(x => x.id === id);
+ if (s) {
+ // Lo aƱadimos a la memoria local para que funcione bien el modal
+ localServices.push(s);
+ }
+ }
+ } catch (e) {
+ console.error("Error buscando servicio fantasma:", e);
+ }
+ }
+
+ if (!s || s.provider === 'SYSTEM_BLOCK') {
+ showToast("No se pudo cargar el expediente", true);
+ return;
+ }
+
const raw = s.raw_data;
currentServiceId = id;
@@ -701,11 +727,20 @@
setTimeout(() => modal.classList.remove('translate-y-full'), 10);
calculateDistance(fullAddress);
- // Cerrar chat al abrir otro servicio
- document.getElementById('chatContainer').classList.add('hidden');
- document.getElementById('chatChevron').classList.remove('rotate-180');
+ // š„ MEJORA: Al abrir desde notificación, abrimos el chat automĆ”ticamente
+ if (activeNotifications.includes(id)) {
+ document.getElementById('chatContainer').classList.remove('hidden');
+ document.getElementById('chatContainer').classList.add('flex');
+ document.getElementById('chatChevron').classList.add('rotate-180');
+ loadChat(id);
+ } else {
+ document.getElementById('chatContainer').classList.add('hidden');
+ document.getElementById('chatContainer').classList.remove('flex');
+ document.getElementById('chatChevron').classList.remove('rotate-180');
+ }
safeLoadIcons();
+
}
function closeModal() {