/* =========================================================================
   Widget flotante de GeotechnIA
   Botón persistente (FAB) que expande un panel con el chatbot en un <iframe>.
   Todo va namespaced bajo #gt-chat-widget para no colisionar con el resto del sitio.
   ========================================================================= */

#gt-chat-widget {
  --gt-blue: #1a4b8c;
  --gt-blue-dark: #153d77;
  --gt-panel-w: 400px;
  --gt-panel-h: 600px;
  --gt-radius: 18px;
  --gt-z-fab: 9000;
  --gt-z-panel: 9001;
}

/* ----------------------------- Botón flotante (FAB) ----------------------------- */
#gt-chat-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: var(--gt-z-fab);
  width: 60px;
  height: 60px;
  padding: 0;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  background: linear-gradient(135deg, var(--gt-blue) 0%, var(--gt-blue-dark) 100%);
  box-shadow: 0 6px 20px rgba(21, 61, 119, 0.35), 0 2px 6px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.4s ease;
  -webkit-tap-highlight-color: transparent;
}

#gt-chat-fab:hover {
  transform: scale(1.06);
  box-shadow: 0 10px 28px rgba(21, 61, 119, 0.45), 0 3px 8px rgba(0, 0, 0, 0.16);
}

#gt-chat-fab:active {
  transform: scale(0.98);
}

#gt-chat-fab:focus-visible {
  outline: 3px solid rgba(26, 75, 140, 0.5);
  outline-offset: 3px;
}

#gt-chat-fab img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  pointer-events: none;
}

/* Estado oculto (se usa para el fade en el hero del inicio) */
#gt-chat-fab.gt-hidden {
  opacity: 0;
  pointer-events: none;
}

/* El FAB se atenúa mientras el panel está abierto (en desktop sigue visible y sirve de toggle) */
#gt-chat-widget.gt-open #gt-chat-fab {
  transform: scale(0.9);
  opacity: 0.85;
}

/* ----------------------------- Panel ----------------------------- */
#gt-chat-panel {
  position: fixed;
  right: 24px;
  bottom: 96px;
  z-index: var(--gt-z-panel);
  width: var(--gt-panel-w);
  height: var(--gt-panel-h);
  max-height: calc(100vh - 120px);
  max-width: calc(100vw - 48px);
  background: #ffffff;
  border-radius: var(--gt-radius);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.22), 0 6px 16px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  transform-origin: bottom right;
  opacity: 0;
  transform: scale(0.96) translateY(8px);
  pointer-events: none;
  transition: opacity 0.22s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.22s cubic-bezier(0.4, 0, 0.2, 1),
              width 0.34s cubic-bezier(0.22, 1, 0.36, 1),
              height 0.34s cubic-bezier(0.22, 1, 0.36, 1),
              right 0.34s cubic-bezier(0.22, 1, 0.36, 1),
              bottom 0.34s cubic-bezier(0.22, 1, 0.36, 1),
              border-radius 0.34s cubic-bezier(0.22, 1, 0.36, 1);
}

#gt-chat-widget.gt-open #gt-chat-panel {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

#gt-chat-iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: transparent;
}

/* ----------------------------- Botón de cerrar (✕) ----------------------------- */
#gt-chat-close {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 3;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  /* Fondo oscuro translúcido para que la ✕ se vea sobre cualquier fondo (blanco o azul) */
  background: rgba(15, 23, 42, 0.55);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  /* El chatbot embebido trae su propia ✕ en el header, y el skeleton de carga replica
     ese header (incluida su ✕). Por eso la ✕ del host queda siempre oculta. */
  display: none;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.15s ease;
}

#gt-chat-close:hover {
  background: rgba(15, 23, 42, 0.78);
  transform: scale(1.08);
}

#gt-chat-close:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.8);
  outline-offset: 2px;
}

#gt-chat-close svg {
  width: 18px;
  height: 18px;
  pointer-events: none;
}

/* ----------------------------- Overlay de carga (skeleton premium) ----------------------------- */
#gt-chat-loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  opacity: 1;
  transition: opacity 0.4s ease;
}

#gt-chat-loading.gt-fade-out {
  opacity: 0;
  pointer-events: none;
}

/* Faux-header: REPLICA EXACTA del header real del chatbot (.chatbot-header en su layout
   angosto ≤768px, que es el que usa el panel de ~400px) para que el swap skeleton → real
   no produzca ningún salto. Mismos colores, padding, tipografía e iconos. */
.gt-skel-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  /* = .chatbot-header @≤768/≤639: 8px vertical; izq 1rem (más margen para el título), der 0.625rem */
  padding: 0.5rem 0.625rem 0.5rem 1rem;
  background: linear-gradient(135deg, var(--gt-blue) 0%, var(--gt-blue-dark) 100%);
  border-bottom: 1px solid rgba(96, 165, 250, 0.10);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.08);
}

.gt-skel-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

/* «Geotechn IA» bicolor, en negrita — idéntico al span del header real. */
.gt-skel-title {
  color: #ffffff;
  font-family: "Inter", Arial, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 700;
  font-size: 1.3rem;
  line-height: 1;
  letter-spacing: -0.025em;
  white-space: nowrap;
}

.gt-skel-title-ia {
  color: #60a5fa;
}

/* La «i» de información. En el header real (#chat-info-btn) es un <button>, así que la
   regla de la cabecera lo fuerza a 36×36 (≤768px); replicamos esa caja para que el círculo
   y su posición coincidan. El borde de 1px dibuja el círculo de 36px. */
.gt-skel-info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: rgba(255, 255, 255, 0.7);
  font: italic 600 11px/1 Georgia, "Times New Roman", serif;
}

/* Separador disponible para futuras variantes del faux-header; no se usa en el
   layout angosto del widget porque los controles desktop reales no ocupan espacio. */
.gt-skel-divider {
  width: 1px;
  height: 24px;
  flex-shrink: 0;
  margin: 0 0.125rem;
  background: transparent;
}

/* Grupo de iconos a la derecha (⚙ ⛶ ✕), 36×36 como los botones del header real. */
.gt-skel-actions {
  display: flex;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
}

.gt-skel-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #ffffff;
}

.gt-skel-btn svg {
  width: 18px;
  height: 18px;
}

.gt-skel-close {
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.gt-skel-close:hover {
  background: rgba(255, 255, 255, 0.22);
  transform: scale(1.04);
}

.gt-skel-close:active {
  transform: scale(0.96);
}

.gt-skel-close:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.8);
  outline-offset: -2px;
}

.gt-skel-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 26px 20px;
}

.gt-skel-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  /* Aparición escalonada y suave de cada burbuja. */
  opacity: 0;
  animation: gt-skel-in 0.5s ease forwards;
}

.gt-skel-row:nth-child(1) { animation-delay: 0.05s; }
.gt-skel-row:nth-child(2) { animation-delay: 0.22s; }

.gt-skel-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--gt-blue) 0%, var(--gt-blue-dark) 100%);
  opacity: 0.22;
  animation: gt-skel-pulse 1.8s ease-in-out infinite;
}

.gt-skel-stack {
  display: flex;
  flex-direction: column;
  gap: 9px;
  max-width: 78%;
  flex: 1 1 auto;
}

.gt-skel-bubble {
  background: #eaeff5;
  border-radius: 14px 14px 14px 4px;
  padding: 13px 16px;
}

.gt-skel-line {
  height: 11px;
  border-radius: 7px;
  position: relative;
  overflow: hidden;
  background: #e2e8f0;
}

.gt-skel-line.gt-w-85 { width: 85%; }
.gt-skel-line.gt-w-65 { width: 65%; }
.gt-skel-line.gt-w-45 { width: 45%; }

/* Shimmer suave y lento que recorre las líneas. */
.gt-skel-line::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.65), transparent);
  animation: gt-shimmer 1.8s ease-in-out infinite;
}

/* Indicador de "escribiendo": tres puntos que rebotan dentro de la burbuja del bot. */
.gt-skel-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.gt-skel-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gt-blue);
  opacity: 0.45;
  animation: gt-skel-dot 1.3s ease-in-out infinite;
}

.gt-skel-typing span:nth-child(2) { animation-delay: 0.18s; }
.gt-skel-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes gt-shimmer {
  100% { transform: translateX(100%); }
}

@keyframes gt-skel-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 0.85; }
}

@keyframes gt-skel-pulse {
  0%, 100% { opacity: 0.18; }
  50% { opacity: 0.32; }
}

@keyframes gt-skel-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ----------------------------- Fullscreen: panel a toda la ventana del navegador ----------------------------- */
/* Lo dispara el botón ⛶ del header del chatbot (vía postMessage). El panel se expande
   sobre toda la ventana; el FAB se oculta porque queda tapado. */
/* Se animan width/height/right/bottom (no `inset:0`) para que el panel crezca con
   suavidad desde su esquina inferior-derecha hasta llenar la ventana. top/left quedan
   en auto y se resuelven a 0 al fijar right/bottom + 100vw/100dvh. */
#gt-chat-widget.gt-fullscreen #gt-chat-panel {
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: 100vw;
  max-height: 100vh;
  max-height: 100dvh;
  border-radius: 0;
}

#gt-chat-widget.gt-fullscreen #gt-chat-fab {
  opacity: 0;
  pointer-events: none;
}

/* ----------------------------- Móvil: panel a pantalla completa ----------------------------- */
@media (max-width: 640px) {
  #gt-chat-panel {
    inset: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
  }

  #gt-chat-fab {
    right: 18px;
    bottom: 18px;
  }

  /* En fullscreen el FAB queda tapado por el panel; el cierre se hace con la ✕ */
  #gt-chat-widget.gt-open #gt-chat-fab {
    opacity: 0;
    pointer-events: none;
  }
}

/* ----------------------------- Modo oscuro (host) ----------------------------- */
body.dark #gt-chat-panel {
  background: #1f2937;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5), 0 6px 16px rgba(0, 0, 0, 0.3);
}

body.dark #gt-chat-loading {
  background: #111827;
}

/* El faux-header replica también el gradiente oscuro del header real. */
body.dark .gt-skel-header {
  background: linear-gradient(135deg, #0f2545 0%, #0c1f3a 100%);
  border-bottom: 1px solid rgba(59, 130, 246, 0.12);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.18);
}

body.dark .gt-skel-bubble {
  background: #1f2937;
}

body.dark .gt-skel-line {
  background: #374151;
}

body.dark .gt-skel-line::after {
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.08), transparent);
}

body.dark .gt-skel-typing span {
  background: #60a5fa;
}

/* ----------------------------- Accesibilidad: menos movimiento ----------------------------- */
@media (prefers-reduced-motion: reduce) {
  #gt-chat-fab,
  #gt-chat-panel,
  #gt-chat-close {
    transition: opacity 0.2s ease;
  }

  .gt-skel-line::after,
  .gt-skel-typing span,
  .gt-skel-avatar,
  .gt-skel-row {
    animation: none;
  }

  .gt-skel-row {
    opacity: 1;
  }
}
