/**
 * IntelligentID - Floating Help System (Draggable FAB & Contextual Drawer)
 * Componente global reutilizable para ayuda en pantalla
 */

/* ─── Botón Flotante Arrastrable (FAB) ─────────────────────────────────────── */
.floating-help-fab {
  position: fixed;
  z-index: 100000 !important;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 8px 10px;
  background: linear-gradient(135deg, var(--ds-primary, #0ea5e9) 0%, #0284c7 100%);
  color: #ffffff !important;
  border-radius: 50px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 8px 24px -4px rgba(14, 165, 233, 0.45), 0 4px 12px rgba(0, 0, 0, 0.15);
  cursor: grab;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  overflow: visible;
}

.floating-help-fab:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 12px 28px -4px rgba(14, 165, 233, 0.6), 0 6px 16px rgba(0, 0, 0, 0.2);
  filter: brightness(1.08);
}

.floating-help-fab.is-dragging {
  cursor: grabbing !important;
  transform: scale(1.06);
  box-shadow: 0 16px 36px -4px rgba(14, 165, 233, 0.7), 0 8px 20px rgba(0, 0, 0, 0.25);
  transition: none !important;
}

.floating-help-fab-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.3);
  position: relative;
  overflow: visible;
}

/* ─── Gesto Sutil de Saludo y Atención ("Ey, acá te puedo ayudar") ─────────── */
.floating-help-fab.fh-gesture-greeting {
  animation: fhAkaGreetingWave 1.4s ease-in-out;
  box-shadow: 0 0 18px rgba(56, 189, 248, 0.8), 0 8px 24px -4px rgba(14, 165, 233, 0.55) !important;
}

@keyframes fhAkaGreetingWave {
  0% { transform: translateY(0) scale(1) rotate(0deg); }
  15% { transform: translateY(-3.5px) scale(1.05) rotate(-3deg); }
  32% { transform: translateY(-3.5px) scale(1.05) rotate(3deg); }
  50% { transform: translateY(-1.5px) scale(1.03) rotate(-1.5deg); }
  68% { transform: translateY(-0.5px) scale(1.01) rotate(1deg); }
  85%, 100% { transform: translateY(0) scale(1) rotate(0deg); }
}

.floating-help-fab.fh-gesture-greeting .fh-thinking-face {
  animation: none !important;
  transform: scale(1.08) rotate(2deg);
}

.floating-help-fab.fh-gesture-greeting .fh-mouth-thinking {
  display: none !important;
}

.floating-help-fab.fh-gesture-greeting .fh-mouth-happy {
  display: block !important;
}

/* ─── Carita Pensativa Animada Softy (Mascota Asistente Femenina) ────────── */
.fh-thinking-face {
  display: block;
  width: 28px;
  height: 28px;
  transform-origin: 18px 18px;
  transform-box: view-box;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  animation: fhHeadThink 6.5s infinite ease-in-out;
}

/* Suave movimiento orgánico y balanceo pensativo de Softy */
@keyframes fhHeadThink {
  0%, 100% {
    transform: translateY(0) rotate(0deg);
  }
  15% {
    transform: translateY(-0.8px) rotate(2deg);
  }
  32% {
    transform: translateY(-1.3px) rotate(3deg);
  }
  50% {
    transform: translateY(-0.4px) rotate(0.5deg);
  }
  68% {
    transform: translateY(-1.2px) rotate(-2.5deg);
  }
  85% {
    transform: translateY(0.4px) rotate(-0.8deg);
  }
}

/* Parpadeo dulce con micro-aleteo de pestañas / Soft Flutter Blink */
.fh-eyes-wrapper {
  transform-origin: 18px 16.5px;
  transform-box: fill-box;
  animation: fhBlink 6.5s infinite ease-in-out;
}

@keyframes fhBlink {
  0%, 42%, 46%, 70%, 74%, 100% {
    transform: scaleY(1);
  }
  44% {
    transform: scaleY(0.08);
  }
  45% {
    transform: scaleY(0.65);
  }
  72% {
    transform: scaleY(0.08);
  }
  73% {
    transform: scaleY(0.65);
  }
}

/* Accesorio Femenino Softy (Moñito con física elástica sutil) */
.softy-accessory {
  transform-origin: 26.5px 6px;
  transform-box: fill-box;
  animation: softyAccessorySway 6.5s infinite ease-in-out;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes softyAccessorySway {
  0%, 100% {
    transform: rotate(0deg) translateY(0);
  }
  20%, 35% {
    transform: rotate(3.5deg) translateY(-0.3px) scale(1.04);
  }
  65%, 80% {
    transform: rotate(-3deg) translateY(-0.2px) scale(0.97);
  }
}

/* Mejillas con sonrojo dinámico / Dynamic Rosy Blush */
.softy-blush {
  transition: opacity 0.3s ease, transform 0.3s ease;
  animation: softyBlushGlow 6.5s infinite ease-in-out;
}

@keyframes softyBlushGlow {
  0%, 100% {
    opacity: 0.48;
    transform: scale(1);
  }
  30%, 70% {
    opacity: 0.62;
    transform: scale(1.08);
  }
}

/* Pestañas femeninas que acompañan el movimiento */
.softy-eyelashes {
  transform-origin: 18px 14px;
  transform-box: fill-box;
  transition: transform 0.2s ease;
}

.softy-lash {
  transition: stroke-width 0.2s ease, transform 0.2s ease;
}

/* Pupilas que se mueven pensando con viveza */
.fh-pupils-group {
  transform-box: fill-box;
  animation: fhPupilsThinking 6.5s infinite ease-in-out;
}

@keyframes fhPupilsThinking {
  0%, 20% {
    /* Mirando al frente, neutral */
    transform: translate(0, 0);
  }
  26%, 46% {
    /* Mirando ARRIBA A LA DERECHA (pensando / procesando) */
    transform: translate(1.8px, -1.9px);
  }
  52%, 74% {
    /* Mirando ARRIBA A LA IZQUIERDA */
    transform: translate(-1.6px, -1.8px);
  }
  80%, 90% {
    /* Mirando abajo hacia el contenido */
    transform: translate(0, 1.4px);
  }
  96%, 100% {
    /* Retorno suave al centro */
    transform: translate(0, 0);
  }
}

/* Ceja derecha que se arquea pensando */
.fh-brow-right {
  transform-origin: 23px 8px;
  transform-box: fill-box;
  animation: fhBrowRightThink 6.5s infinite ease-in-out;
}

@keyframes fhBrowRightThink {
  0%, 20% {
    transform: translateY(0) rotate(0deg);
  }
  26%, 46% {
    transform: translateY(-1.5px) rotate(4deg);
  }
  52%, 74% {
    transform: translateY(-0.8px) rotate(-3deg);
  }
  80%, 100% {
    transform: translateY(0) rotate(0deg);
  }
}

/* Ceja izquierda */
.fh-brow-left {
  transform-origin: 12px 10px;
  transform-box: fill-box;
  animation: fhBrowLeftThink 6.5s infinite ease-in-out;
}

@keyframes fhBrowLeftThink {
  0%, 20% {
    transform: translateY(0);
  }
  26%, 46% {
    transform: translateY(0.3px);
  }
  52%, 74% {
    transform: translateY(-0.9px);
  }
  80%, 100% {
    transform: translateY(0);
  }
}

/* Boca por defecto sonriente y dulce, oculta la pensativa */
.fh-mouth-happy {
  display: block !important;
}
.fh-mouth-thinking {
  display: none !important;
}
.floating-help-fab.is-thinking .fh-mouth-happy {
  display: none !important;
}
.floating-help-fab.is-thinking .fh-mouth-thinking {
  display: block !important;
}

/* Reacción al interactuar / hover en el botón */
.floating-help-fab:hover .fh-thinking-face {
  animation: none !important;
  transform: scale(1.1) rotate(0deg);
}
.floating-help-fab:hover .softy-accessory {
  animation: none !important;
  transform: scale(1.12) rotate(4deg);
}
.floating-help-fab:hover .softy-blush {
  opacity: 0.72 !important;
  transform: scale(1.15) !important;
}
.floating-help-fab:hover .fh-pupils-group {
  animation: none !important;
  transform: translate(0, 0) !important;
}
.floating-help-fab:hover .fh-eyes-wrapper {
  animation: none !important;
  transform: scale(1.06) !important;
}
.floating-help-fab:hover .fh-brow-left,
.floating-help-fab:hover .fh-brow-right {
  animation: none !important;
  transform: translateY(-1.6px) !important;
}
.floating-help-fab:hover .fh-mouth-thinking {
  display: none !important;
}
.floating-help-fab:hover .fh-mouth-happy {
  display: block !important;
}

/* Reacción al arrastrar */
.floating-help-fab.is-dragging .fh-thinking-face {
  animation: none !important;
  transform: scale(1.12);
}
.floating-help-fab.is-dragging .fh-mouth-thinking {
  display: none !important;
}
.floating-help-fab.is-dragging .fh-mouth-happy {
  display: block !important;
}

/* ─── Globito de Diálogo / Speech Bubble ("Ey, yo te puedo ayudar") ────────── */
.floating-help-speech-bubble {
  position: absolute;
  bottom: calc(100% + 10px);
  right: -4px;
  z-index: 1065;
  cursor: pointer;
  pointer-events: auto;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transform: translateY(6px) scale(0.92);
  transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0.35s;
}

.floating-help-speech-bubble.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.fh-bubble-inner {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px 5px 12px;
  background: #0f172a;
  color: #f8fafc;
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.2px;
  border-radius: 50px;
  border: 1px solid rgba(56, 189, 248, 0.45);
  box-shadow: 0 8px 24px -2px rgba(0, 0, 0, 0.45), 0 0 14px rgba(14, 165, 233, 0.25);
  transition: transform 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.fh-bubble-inner:hover {
  background: #1e293b;
  border-color: #38bdf8;
  transform: translateY(-1px);
  box-shadow: 0 10px 28px -2px rgba(0, 0, 0, 0.5), 0 0 18px rgba(56, 189, 248, 0.35);
}

.fh-bubble-text {
  -webkit-user-select: none;
  user-select: none;
}

.fh-bubble-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  margin-left: 2px;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: #94a3b8;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease, transform 0.15s ease;
}

.fh-bubble-close:hover {
  color: #ffffff;
  background-color: rgba(255, 255, 255, 0.15);
  transform: scale(1.1);
}

.fh-bubble-arrow {
  position: absolute;
  bottom: -5px;
  right: 28px;
  width: 10px;
  height: 10px;
  background: #0f172a;
  border-right: 1px solid rgba(56, 189, 248, 0.45);
  border-bottom: 1px solid rgba(56, 189, 248, 0.45);
  transform: rotate(45deg);
  transition: background-color 0.15s ease;
}

.fh-bubble-inner:hover + .fh-bubble-arrow {
  background: #1e293b;
  border-color: #38bdf8;
}

/* Inversión si el FAB está cerca del borde superior */
.floating-help-speech-bubble.flip-bottom {
  bottom: auto;
  top: calc(100% + 10px);
}
.floating-help-speech-bubble.flip-bottom .fh-bubble-arrow {
  bottom: auto;
  top: -5px;
  border-right: none;
  border-bottom: none;
  border-left: 1px solid rgba(56, 189, 248, 0.45);
  border-top: 1px solid rgba(56, 189, 248, 0.45);
}

/* Alineación izquierda si el FAB está cerca del borde izquierdo */
.floating-help-speech-bubble.align-left {
  right: auto;
  left: -4px;
}
.floating-help-speech-bubble.align-left .fh-bubble-arrow {
  right: auto;
  left: 28px;
}

.floating-help-fab-text {
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.3px;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.floating-help-fab-pulse {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: #22c55e;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
  animation: floatingHelpPulse 2s infinite;
}

@keyframes floatingHelpPulse {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
  }
  70% {
    transform: scale(1);
    box-shadow: 0 0 0 6px rgba(34, 197, 94, 0);
  }
  100% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
  }
}

/* ─── Drawer Contextual de Ayuda ───────────────────────────────────────────── */
.drawer-help-offcanvas {
  width: 500px !important;
  max-width: 95vw !important;
  z-index: 100001 !important;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

.drawer-help-header {
  background: linear-gradient(135deg, var(--ds-primary, #0ea5e9) 0%, #0369a1 100%);
  color: #ffffff;
  padding: 14px 18px;
}

.drawer-help-search-wrap {
  position: sticky;
  top: 0;
  z-index: 10;
  background-color: var(--bs-body-bg);
  padding: 12px 16px;
  border-bottom: 1px solid var(--bs-border-color);
}

.help-step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  background-color: var(--ds-primary, #0ea5e9);
  color: #ffffff;
  margin-right: 8px;
}

.help-field-card {
  border: 1px solid var(--bs-border-color);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 12px;
  background-color: var(--bs-body-bg);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.help-field-card:hover {
  border-color: var(--ds-primary, #0ea5e9);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.help-field-title {
  font-size: 0.9rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.help-field-desc {
  font-size: 0.82rem;
  color: var(--bs-secondary-color);
  margin-bottom: 8px;
  line-height: 1.4;
}

.help-field-impact {
  font-size: 0.78rem;
  padding: 6px 10px;
  background-color: rgba(14, 165, 233, 0.08);
  border-left: 3px solid var(--ds-primary, #0ea5e9);
  border-radius: 0 6px 6px 0;
  color: var(--bs-body-color);
}

.help-field-impact strong {
  color: var(--ds-primary, #0284c7);
}

/* Modo oscuro */
[data-bs-theme="dark"] .help-field-card,
body.theme-dark .help-field-card {
  background-color: #1e293b;
  border-color: #334155;
}

[data-bs-theme="dark"] .help-field-impact,
body.theme-dark .help-field-impact {
  background-color: rgba(14, 165, 233, 0.15);
  color: #e2e8f0;
}

[data-bs-theme="dark"] .help-field-impact strong,
body.theme-dark .help-field-impact strong {
  color: #38bdf8;
}

/* Responsive móvil: asegura que el botón de ayuda flote en la esquina inferior derecha sin tapar pestañas ni tablas */
@media (max-width: 767.98px) {
  .floating-help-fab {
    bottom: 20px !important;
    right: 16px !important;
    top: auto !important;
    left: auto !important;
    padding: 6px 12px 6px 8px !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35) !important;
  }

  .floating-help-speech-bubble {
    max-width: 82vw;
    right: 0 !important;
    left: auto !important;
  }
}

/* ─── Micrófono y Reconocimiento de Voz de Aka ─────────────────────────────── */
.btn-aka-mic-pulsing {
  animation: akaMicPulse 1.2s infinite ease-in-out !important;
  background-color: rgba(239, 68, 68, 0.25) !important;
  border-color: #ef4444 !important;
  color: #ef4444 !important;
}

@keyframes akaMicPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
    transform: scale(1.06);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    transform: scale(1);
  }
}
