/* ==========================================================================
   .tp-tooltip — P1.F2.T3
   ©2026 Vexstorm Studios – All Rights Reserved

   Supplementary description for a control whose label is necessarily terse: a
   confidence abbreviation, a priority component, a column header in the audit
   viewer.

   Variants   --end  --start  --below
   Elements   __trigger  __bubble
   States     :hover  :focus-visible  :focus-within

   Three rules, all of them about not making a tooltip the only path to
   information:

   1. **A tooltip never carries information the interface needs.** WCAG 1.4.13
      and every touch device agree: hover-only content is unreachable for a
      large share of users. Anything essential is in the page.

   2. **It appears on focus as well as hover**, which is why the trigger is a
      real focusable element and the bubble is shown by :focus-within as well
      as :hover.

   3. **It is described, not labelled.** The bubble carries an id referenced by
      the trigger's aria-describedby, so the control keeps its own accessible
      name and gains a description.

   Surface-inverse, so the bubble reads as an overlay rather than as another
   panel — and text-inverse on surface-inverse is one of the pairings the
   contrast test asserts at 4.5:1 in both themes.
   ========================================================================== */

.tp-tooltip {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.tp-tooltip__trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tp-space-target-min);
  min-height: var(--tp-space-target-min);
  padding: var(--tp-space-1);
  border-radius: var(--tp-radius-sm);
  color: var(--tp-color-text-muted);
  cursor: help;
}

.tp-tooltip__trigger:hover {
  color: var(--tp-color-text-primary);
  background-color: var(--tp-color-surface-sunken);
}

.tp-tooltip__trigger:active {
  background-color: var(--tp-color-accent-subtle);
}

.tp-tooltip__trigger:disabled {
  opacity: var(--tp-opacity-disabled);
  cursor: not-allowed;
}

.tp-tooltip__trigger:focus-visible {
  outline-offset: 0;
}

.tp-tooltip__trigger-icon {
  width: var(--tp-space-icon);
  height: var(--tp-space-icon);
}

/* --------------------------------------------------------------------------
   The bubble
   -------------------------------------------------------------------------- */

.tp-tooltip__bubble {
  position: absolute;
  inset-block-end: calc(100% + var(--tp-space-2));
  inset-inline-start: 50%;
  z-index: var(--tp-z-tooltip);
  width: max-content;
  max-width: var(--tp-space-sidebar-width);
  padding: var(--tp-space-2) var(--tp-space-3);
  border-radius: var(--tp-radius-md);
  background-color: var(--tp-color-surface-inverse);
  color: var(--tp-color-text-inverse);
  font-size: var(--tp-text-xs);
  font-weight: var(--tp-weight-regular);
  line-height: var(--tp-leading-normal);
  text-align: start;
  box-shadow: var(--tp-shadow-md);
  transform: translateX(-50%);
  /* Hidden without display:none, so the bubble stays in the accessibility tree
     for aria-describedby to reach at all times. */
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity var(--tp-motion-duration-fast) var(--tp-motion-ease-standard),
    visibility var(--tp-motion-duration-fast) var(--tp-motion-ease-standard);
}

.tp-tooltip:hover .tp-tooltip__bubble,
.tp-tooltip:focus-within .tp-tooltip__bubble {
  opacity: 1;
  visibility: visible;
}

/* --------------------------------------------------------------------------
   Placement — a bubble centred over a trigger at the edge of the viewport
   overflows it, which at 320px means horizontal body scroll (UX-004). The
   template picks the variant that keeps the bubble inside.
   -------------------------------------------------------------------------- */

.tp-tooltip--start .tp-tooltip__bubble {
  inset-inline-start: 0;
  transform: none;
}

.tp-tooltip--end .tp-tooltip__bubble {
  inset-inline-start: auto;
  inset-inline-end: 0;
  transform: none;
}

.tp-tooltip--below .tp-tooltip__bubble {
  inset-block-end: auto;
  inset-block-start: calc(100% + var(--tp-space-2));
}
