/* ── UMA, LA GUÍA DE LA APP ───────────────────────────────────────────────── */
/* Botón flotante y panel de chat (public/js/uma.js). Solo tokens de
   styles.css: el modo oscuro sale solo. z-index por debajo de modales y
   overlays (1000+), por encima del contenido, incluida la pantalla de
   ingreso (.login-screen no tiene z-index propio; su spinner es 10 local). */

.uma-root {
  position: fixed;
  right: calc(16px + env(safe-area-inset-right, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 950;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  font-family: inherit;
}
.uma-root[hidden] { display: none; }

/* Avatar: imagen o, si no carga, la inicial en un círculo.
   El dibujo es de línea terracota sobre transparente: con el fondo del modo
   oscuro casi no se ve, así que el círculo es siempre claro, en los dos temas. */
.uma-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border-radius: 50%;
  overflow: hidden;
  background: #FFFFFF;
  color: #8A6A2A;
  font-weight: 700;
}
.uma-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.uma-avatar--fallback { border: 2px solid var(--ia); }
.uma-avatar--fab { width: 60px; height: 60px; font-size: 26px; }
.uma-avatar--head { width: 48px; height: 48px; font-size: 20px; }

/* Botón flotante: 64px, en la franja de los lanzadores de chat habituales
   (56 a 64px), con el borde claro para que se recorte en los dos temas. */
.uma-fab {
  width: 64px;
  height: 64px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 2px solid var(--ia-border);
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s ease, box-shadow .15s ease;
}
.uma-fab:hover { transform: translateY(-2px); box-shadow: 0 0 0 6px var(--ia-glow), var(--shadow-lg); }
.uma-fab:focus-visible { outline: 3px solid var(--ia); outline-offset: 2px; }

/* Panel */
.uma-panel {
  width: min(380px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 110px - env(safe-area-inset-bottom, 0px)));
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--borde);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.uma-panel[hidden] { display: none; }

.uma-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 12px 14px;
  border-bottom: 1px solid var(--borde);
  background: var(--bg-tint);
}
.uma-titles { flex: 1; min-width: 0; }
.uma-title { margin: 0; font-size: 16px; font-weight: 700; color: var(--text-primary); }
.uma-subtitle { margin: 0; font-size: 12px; color: var(--text-secondary); }
.uma-close {
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.uma-close:hover { background: var(--fondo-alt); color: var(--text-primary); }
.uma-close:focus-visible { outline: 2px solid var(--ia); }

.uma-notice {
  margin: 0;
  padding: 8px 14px;
  font-size: 12px;
  color: var(--ia-dark);
  background: var(--ia-soft);
  border-bottom: 1px solid var(--ia-border);
}

.uma-log {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--fondo);
}

.uma-msg { display: flex; flex-direction: column; max-width: 88%; gap: 6px; }
.uma-msg--assistant { align-self: flex-start; }
.uma-msg--user { align-self: flex-end; }
.uma-msg-body {
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.uma-msg--assistant .uma-msg-body {
  background: var(--bg-card);
  border: 1px solid var(--borde);
  border-bottom-left-radius: 4px;
}
.uma-msg--user .uma-msg-body {
  background: var(--tierra);
  color: var(--on-brand);
  border-bottom-right-radius: 4px;
}

.uma-whatsapp {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  background: var(--success);
  color: var(--on-brand);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}
.uma-whatsapp:hover { background: var(--success-dark); }

/* Indicador de escritura */
.uma-dots { display: inline-flex; gap: 4px; align-items: center; min-height: 20px; }
.uma-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: uma-blink 1.2s infinite ease-in-out;
}
.uma-dots span:nth-child(2) { animation-delay: .2s; }
.uma-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes uma-blink {
  0%, 80%, 100% { opacity: .25; }
  40% { opacity: 1; }
}

/* Entrada */
.uma-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px;
  border-top: 1px solid var(--borde);
  background: var(--bg-card);
}
.uma-input {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 11px 12px;
  resize: none;
  font: inherit;
  /* 16px como mínimo: con menos, Safari de iPhone agranda toda la página al
     enfocar el campo. */
  font-size: 16px;
  line-height: 1.4;
  color: var(--text-primary);
  background: var(--fondo);
  border: 1px solid var(--borde);
  border-radius: var(--radius-sm);
}
.uma-input:focus { outline: none; border-color: var(--ia); box-shadow: 0 0 0 3px var(--ia-glow); }
.uma-input:disabled { opacity: .6; }
.uma-send {
  min-height: 44px;
  min-width: 44px;
  padding: 0 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--tierra);
  color: var(--on-brand);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.uma-send:hover:not(:disabled) { background: var(--tierra-dark); }
.uma-send:disabled { opacity: .5; cursor: default; }
.uma-send:focus-visible { outline: 2px solid var(--ia); outline-offset: 2px; }

/* Celular: el panel ocupa el ancho y respeta los bordes seguros */
@media (max-width: 640px) {
  .uma-root {
    right: calc(12px + env(safe-area-inset-right, 0px));
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  /* Abierto, el chat ocupa el área visible (--uma-vv-*, uma.js): con el
     teclado arriba es la parte de la pantalla que queda libre. */
  .uma-root--open {
    left: calc(8px + env(safe-area-inset-left, 0px));
    right: calc(8px + env(safe-area-inset-right, 0px));
    top: calc(var(--uma-vv-top, 0px) + 8px + env(safe-area-inset-top, 0px));
    bottom: auto;
    align-items: stretch;
  }
  .uma-root--open .uma-fab { display: none; }
  .uma-panel {
    width: 100%;
    height: calc(100vh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    height: calc(var(--uma-vv-h, 100dvh) - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }
  /* Con el chat abierto, la página de atrás no se desplaza ni se estira. */
  html.uma-lock, html.uma-lock body { overflow: hidden; }
}

/* La barra flotante de navegación (.float-nav, styles.css) también vive abajo
   y en pantallas angostas ocupa casi todo el ancho: el botón se sube encima. */
body:has(.float-nav) .uma-root:not(.uma-root--open) {
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
}

@media (prefers-reduced-motion: reduce) {
  .uma-fab { transition: none; }
  .uma-dots span { animation: none; opacity: .7; }
}
