/*!
 * FLEROS — Help System CSS v2 (Universal · Fixed-position tooltips)
 *
 * Tooltips contextuales para administradores y usuarios.
 *
 * IMPORTANTE: los tooltips usan position:fixed y son posicionados
 * por JavaScript para evitar problemas con overflow:hidden y
 * stacking context de los contenedores padre.
 *
 * Auto-detecta el modo según el body class:
 *   body.help-mode-admin  → tema oscuro técnico
 *   body.help-mode-user   → tema claro amigable (default)
 */

/* ── Botón de ayuda (?) ─────────────────────────────── */
.help, [data-help]::after {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px; height: 16px;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  cursor: help;
  margin-left: 6px;
  vertical-align: middle;
  user-select: none;
  flex-shrink: 0;
  position: relative;
  transition: all 0.15s;
  z-index: 1;
}

.help::before { content: '?'; line-height: 1; }
[data-help] { position: relative; }

/* Variante "data-help" inline: pone (?) automático tras el elemento */
[data-help]:not(.no-marker)::after {
  content: '?';
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px; height: 16px;
  border-radius: 50%;
  font-size: 10px; font-weight: 700;
  cursor: help; margin-left: 6px;
  vertical-align: middle;
  position: absolute;
  top: 8px; right: 8px;
  z-index: 2;
}

/* ── TEMA ADMIN (oscuro técnico) ─────────────────────── */
body.help-mode-admin .help,
body.help-mode-admin [data-help]:not(.no-marker)::after {
  background: rgba(96,165,250,0.2);
  color: #60a5fa;
  border: 1px solid rgba(96,165,250,0.3);
}
body.help-mode-admin .help:hover,
body.help-mode-admin .help.active,
body.help-mode-admin [data-help]:hover::after {
  background: #60a5fa;
  color: white;
  transform: scale(1.15);
  border-color: #60a5fa;
}

/* ── TEMA USER (claro amigable, default) ────────────── */
body:not(.help-mode-admin) .help,
body:not(.help-mode-admin) [data-help]:not(.no-marker)::after {
  background: rgba(99,102,241,0.18);
  color: #6366f1;
  border: 1px solid rgba(99,102,241,0.35);
}
body:not(.help-mode-admin) .help:hover,
body:not(.help-mode-admin) .help.active,
body:not(.help-mode-admin) [data-help]:hover::after {
  background: #6366f1;
  color: white;
  transform: scale(1.15);
  border-color: #6366f1;
}

/* ────────────────────────────────────────────────────────────
 * BURBUJA DEL TOOLTIP (posicionado por JS con position:fixed)
 * Vive como hijo del <body> para escapar overflow:hidden
 * ──────────────────────────────────────────────────────────── */
.help-tooltip {
  position: fixed;
  display: none;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.55;
  width: 290px;
  max-width: calc(100vw - 32px);
  white-space: normal;
  text-align: left;
  cursor: default;
  pointer-events: auto;
  z-index: 2147483647;  /* Max int para asegurar primer plano */
  box-shadow: 0 16px 50px rgba(0,0,0,0.45);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  /* Posición inicial fuera de pantalla hasta que JS la coloque */
  top: -9999px; left: -9999px;
  /* Arrow se gestiona en JS via .arrow-* classes */
  animation: helpTipIn 0.18s ease-out;
}
.help-tooltip.show { display: block; }

@keyframes helpTipIn {
  from { opacity: 0; transform: translateY(4px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Tema admin tooltip */
body.help-mode-admin .help-tooltip {
  background: #1e293b;
  color: #e0e6f0;
  border: 1px solid rgba(96,165,250,0.4);
}
body.help-mode-admin .help-tooltip strong { color: #60a5fa; }
body.help-mode-admin .help-tooltip code {
  background: rgba(0,0,0,0.4);
  color: #facc15;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}

/* Tema user tooltip */
body:not(.help-mode-admin) .help-tooltip {
  background: #ffffff;
  color: #1e293b;
  border: 1px solid #cbd5e1;
  box-shadow: 0 16px 50px rgba(15,23,42,0.18);
}
body:not(.help-mode-admin) .help-tooltip strong { color: #6366f1; }
body:not(.help-mode-admin) .help-tooltip code {
  background: #f1f5f9;
  color: #1e293b;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}

.help-tooltip strong {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
}
.help-tooltip ul { margin: 6px 0 0 0; padding-left: 18px; }
.help-tooltip li { margin-bottom: 3px; }
.help-tooltip p { margin: 4px 0; }

/* ── Flecha del tooltip (apunta al elemento) ─────────── */
.help-tooltip-arrow {
  position: absolute;
  width: 0; height: 0;
  border: 7px solid transparent;
}
/* Tooltip arriba del elemento → flecha abajo */
.help-tooltip[data-arrow="bottom"] .help-tooltip-arrow {
  bottom: -14px; left: 50%; transform: translateX(-50%);
}
body.help-mode-admin .help-tooltip[data-arrow="bottom"] .help-tooltip-arrow { border-top-color: #1e293b; }
body:not(.help-mode-admin) .help-tooltip[data-arrow="bottom"] .help-tooltip-arrow { border-top-color: #ffffff; }

/* Tooltip abajo del elemento → flecha arriba */
.help-tooltip[data-arrow="top"] .help-tooltip-arrow {
  top: -14px; left: 50%; transform: translateX(-50%);
}
body.help-mode-admin .help-tooltip[data-arrow="top"] .help-tooltip-arrow { border-bottom-color: #1e293b; }
body:not(.help-mode-admin) .help-tooltip[data-arrow="top"] .help-tooltip-arrow { border-bottom-color: #ffffff; }

/* Tooltip a la derecha → flecha izquierda */
.help-tooltip[data-arrow="left"] .help-tooltip-arrow {
  left: -14px; top: 50%; transform: translateY(-50%);
}
body.help-mode-admin .help-tooltip[data-arrow="left"] .help-tooltip-arrow { border-right-color: #1e293b; }
body:not(.help-mode-admin) .help-tooltip[data-arrow="left"] .help-tooltip-arrow { border-right-color: #ffffff; }

/* Tooltip a la izquierda → flecha derecha */
.help-tooltip[data-arrow="right"] .help-tooltip-arrow {
  right: -14px; top: 50%; transform: translateY(-50%);
}
body.help-mode-admin .help-tooltip[data-arrow="right"] .help-tooltip-arrow { border-left-color: #1e293b; }
body:not(.help-mode-admin) .help-tooltip[data-arrow="right"] .help-tooltip-arrow { border-left-color: #ffffff; }

/* Si la flecha tiene que desplazarse del centro (cuando tooltip se reposiciona) */
.help-tooltip[data-arrow="bottom"] .help-tooltip-arrow.shift-left { left: 16px; transform: none; }
.help-tooltip[data-arrow="bottom"] .help-tooltip-arrow.shift-right { left: auto; right: 16px; transform: none; }
.help-tooltip[data-arrow="top"] .help-tooltip-arrow.shift-left { left: 16px; transform: none; }
.help-tooltip[data-arrow="top"] .help-tooltip-arrow.shift-right { left: auto; right: 16px; transform: none; }

/* ── Variante grande para explicaciones largas ─────── */
.help-tooltip.wide { width: 380px; }

/* ── Variante de header (más chico) ──────────────────── */
th .help, h1 .help, h2 .help, h3 .help, h4 .help,
.panel-title .help, .kpi .help, label .help {
  width: 14px; height: 14px;
  font-size: 9px;
}

/* ── KPI / Dash-card: (?) en esquina superior derecha ─────────── */
.kpi, .dash-card, .stat-card, .card, .metric-card {
  position: relative;
}
.kpi[data-help]:not(.no-marker)::after,
.dash-card[data-help]:not(.no-marker)::after,
.stat-card[data-help]:not(.no-marker)::after,
.metric-card[data-help]:not(.no-marker)::after {
  position: absolute;
  top: 10px; right: 10px;
  margin: 0;
}

/* IMPORTANTE: forzar que los KPIs/cards NO recorten al (?)
   pero sí mantengan sus efectos visuales. El (?) está en absolute
   pero overflow visible permite que no quede tapado. */
.kpi, .dash-card, .stat-card, .metric-card { overflow: visible !important; }

/* Sidebar items: (?) inline pero compacto */
.sb-item[data-help]:not(.no-marker)::after,
.sidebar-item[data-help]:not(.no-marker)::after,
.nav-item[data-help]:not(.no-marker)::after {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 13px; height: 13px;
  font-size: 9px;
}

/* qaction (acciones rápidas): icono al final */
.qaction[data-help]:not(.no-marker)::after {
  margin-left: auto;
  position: relative;
  top: auto; right: auto;
}

/* ── Botón flotante de ayuda global (FAB) ─────────────── */
.help-fab {
  position: fixed;
  bottom: 20px; right: 20px;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  font-size: 22px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(99,102,241,0.45);
  z-index: 99999;
  transition: all 0.2s;
  border: none;
  font-family: 'Segoe UI', system-ui, sans-serif;
}
.help-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 12px 32px rgba(99,102,241,0.6);
}
body.help-mode-admin .help-fab {
  background: linear-gradient(135deg, #2563eb, #60a5fa);
  box-shadow: 0 8px 24px rgba(37,99,235,0.45);
}

/* ── Modal de tour / ayuda general ──────────────────── */
.help-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 999999;
  align-items: center; justify-content: center;
  padding: 20px;
}
.help-modal-overlay.show { display: flex; }
.help-modal {
  background: #ffffff;
  color: #1e293b;
  border-radius: 16px;
  padding: 28px;
  max-width: 600px; width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  font-family: 'Segoe UI', system-ui, sans-serif;
}
body.help-mode-admin .help-modal {
  background: #0f1420;
  color: #e0e6f0;
  border: 1px solid rgba(96,165,250,0.2);
}
.help-modal h2 {
  font-size: 22px;
  margin-bottom: 16px;
  display: flex; align-items: center; gap: 10px;
}
.help-modal-close {
  float: right;
  cursor: pointer;
  font-size: 28px; line-height: 1;
  color: #94a3b8;
  background: none; border: none;
}
.help-modal-close:hover { color: #ef4444; }
.help-modal-section {
  margin: 16px 0;
  padding: 12px 16px;
  background: rgba(99,102,241,0.06);
  border-left: 4px solid #6366f1;
  border-radius: 8px;
  font-size: 14px; line-height: 1.6;
}
body.help-mode-admin .help-modal-section {
  background: rgba(96,165,250,0.08);
  border-left-color: #60a5fa;
}
.help-modal-section strong {
  color: #6366f1;
  display: block;
  margin-bottom: 4px;
}
body.help-mode-admin .help-modal-section strong { color: #60a5fa; }

/* ── Mobile responsive ───────────────────────────────── */
@media (max-width: 600px) {
  .help-tooltip {
    width: calc(100vw - 24px) !important;
    max-width: 360px !important;
    font-size: 13px;
  }
  .help-fab {
    bottom: 12px; right: 12px;
    width: 44px; height: 44px;
    font-size: 20px;
  }
}

/* ── Print: ocultar tooltips ─────────────────────────── */
@media print {
  .help, .help-fab, .help-tooltip { display: none !important; }
}

/* ── Compatibilidad con tooltips inline antiguos (.help-tip) ── */
/* Para no romper dashboard_healing.html que tiene 124 inline */
.help-tip {
  display: none;
  position: fixed;  /* ← cambio crítico: fixed en vez de absolute */
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.55;
  width: 290px;
  max-width: calc(100vw - 32px);
  white-space: normal;
  text-align: left;
  z-index: 2147483647;
  box-shadow: 0 16px 50px rgba(0,0,0,0.45);
  pointer-events: auto;
  cursor: default;
}
body.help-mode-admin .help-tip {
  background: #1e293b;
  color: #e0e6f0;
  border: 1px solid rgba(96,165,250,0.4);
}
body:not(.help-mode-admin) .help-tip {
  background: #ffffff;
  color: #1e293b;
  border: 1px solid #cbd5e1;
}
.help-tip strong {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
}
body.help-mode-admin .help-tip strong { color: #60a5fa; }
body:not(.help-mode-admin) .help-tip strong { color: #6366f1; }
.help-tip code {
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}
body.help-mode-admin .help-tip code {
  background: rgba(0,0,0,0.4);
  color: #facc15;
}
body:not(.help-mode-admin) .help-tip code {
  background: #f1f5f9;
  color: #1e293b;
}
.help-tip ul { margin: 6px 0 0 0; padding-left: 18px; }
.help-tip li { margin-bottom: 3px; }
/* La visibilidad y posición se gestiona en JS para .help-tip también */

/* ── Animación ─────────────────────────────────────── */
.help-tooltip.show, .help-tip.show {
  animation: helpTipIn 0.18s ease-out;
}
