/* Tooltip contestuale riusabile: icona "?" con popover esplicativo su hover/focus.
   Solo CSS, nessun JS. Accessibile via tastiera (tabindex + :focus-visible).

   Markup:
   <span class="help-tip" tabindex="0" role="button" aria-label="Aiuto">?
     <span class="help-tip__popover" role="tooltip">Testo di aiuto.</span>
   </span> */

.help-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-left: var(--space-1);
  border: 1px solid var(--color-brand-primary);
  border-radius: 50%;
  color: var(--color-brand-primary);
  background-color: var(--color-surface);
  font-family: var(--font-sans);
  font-size: 0.6875rem;
  font-weight: var(--fw-bold);
  line-height: 1;
  cursor: help;
  vertical-align: middle;
  user-select: none;
}

.help-tip:hover {
  color: var(--color-surface);
  background-color: var(--color-brand-primary);
}

.help-tip:focus-visible {
  outline: 2px solid var(--color-brand-secondary);
  outline-offset: 2px;
}

.help-tip__popover {
  position: absolute;
  top: calc(100% + var(--space-2));
  left: 0;
  z-index: var(--z-tooltip);
  width: 280px;
  max-width: 90vw;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-button);
  background-color: var(--color-brand-primary);
  color: var(--color-surface);
  box-shadow: var(--shadow-raised);
  font-size: var(--fs-caption);
  font-weight: var(--fw-regular);
  line-height: var(--lh-body);
  text-align: left;
  white-space: normal;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s ease;
  pointer-events: none;
}

/* Freccia che collega popover e icona. */
.help-tip__popover::before {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 6px;
  border: 6px solid transparent;
  border-bottom-color: var(--color-brand-primary);
}

.help-tip:hover .help-tip__popover,
.help-tip:focus .help-tip__popover,
.help-tip:focus-within .help-tip__popover {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Variante allineata a destra quando l'icona è a fine riga. */
.help-tip__popover--right {
  left: auto;
  right: 0;
}

.help-tip__popover--right::before {
  left: auto;
  right: 6px;
}

@media (prefers-reduced-motion: reduce) {
  .help-tip__popover {
    transition: opacity 0.15s ease, visibility 0.15s ease;
    transform: none;
  }

  .help-tip:hover .help-tip__popover,
  .help-tip:focus .help-tip__popover,
  .help-tip:focus-within .help-tip__popover {
    transform: none;
  }
}
