/* ==========================================================================
   Adapto UI — Tooltip
   Contextual hints with directional positioning.
   Uses data-tooltip attribute for text and data-tooltip-pos for direction.
   ========================================================================== */

[data-tooltip] {
  position: relative;
  cursor: help;
}

[data-tooltip]::before,
[data-tooltip]::after {
  position: absolute;
  z-index: var(--au-z-tooltip);
  pointer-events: none;
  opacity: 0;
  transition:
    opacity var(--au-duration-fast) var(--au-ease-default),
    transform var(--au-duration-fast) var(--au-ease-default);
}

/* Tooltip body */
[data-tooltip]::after {
  content: attr(data-tooltip);
  padding: var(--au-space-1) var(--au-space-2);
  font-family: var(--au-font-family);
  font-size: var(--au-text-xs);
  font-weight: var(--au-weight-medium);
  line-height: var(--au-leading-tight);
  white-space: nowrap;
  color: #FFFFFF;
  background-color: var(--au-gray-900);
  border-radius: var(--au-radius-sm);
  box-shadow: var(--au-shadow-md);
}

@media (prefers-color-scheme: dark) {
  [data-tooltip]::after {
    background-color: var(--au-gray-700);
    color: var(--au-color-text);
  }
}

/* Arrow */
[data-tooltip]::before {
  content: "";
  width: 0;
  height: 0;
}

/* -----------------------------------------------------------------------
   Show on hover / focus
   ----------------------------------------------------------------------- */

[data-tooltip]:hover::before,
[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::before,
[data-tooltip]:focus-visible::after {
  opacity: 1;
}

/* -----------------------------------------------------------------------
   Position: top (default)
   ----------------------------------------------------------------------- */

[data-tooltip]::after,
[data-tooltip][data-tooltip-pos="top"]::after {
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
}

[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after,
[data-tooltip][data-tooltip-pos="top"]:hover::after,
[data-tooltip][data-tooltip-pos="top"]:focus-visible::after {
  transform: translateX(-50%) translateY(0);
}

[data-tooltip]::before,
[data-tooltip][data-tooltip-pos="top"]::before {
  bottom: calc(100% + 3px);
  left: 50%;
  transform: translateX(-50%);
  border-inline: 5px solid transparent;
  border-block-start: 5px solid var(--au-gray-900);
}

@media (prefers-color-scheme: dark) {
  [data-tooltip]::before,
  [data-tooltip][data-tooltip-pos="top"]::before {
    border-block-start-color: var(--au-gray-700);
  }
}

/* -----------------------------------------------------------------------
   Position: bottom
   ----------------------------------------------------------------------- */

[data-tooltip][data-tooltip-pos="bottom"]::after {
  top: calc(100% + 8px);
  bottom: auto;
  left: 50%;
  transform: translateX(-50%) translateY(-4px);
}

[data-tooltip][data-tooltip-pos="bottom"]:hover::after,
[data-tooltip][data-tooltip-pos="bottom"]:focus-visible::after {
  transform: translateX(-50%) translateY(0);
}

[data-tooltip][data-tooltip-pos="bottom"]::before {
  top: calc(100% + 3px);
  bottom: auto;
  left: 50%;
  transform: translateX(-50%);
  border-inline: 5px solid transparent;
  border-block-start: none;
  border-block-end: 5px solid var(--au-gray-900);
}

@media (prefers-color-scheme: dark) {
  [data-tooltip][data-tooltip-pos="bottom"]::before {
    border-block-end-color: var(--au-gray-700);
  }
}

/* -----------------------------------------------------------------------
   Position: left
   ----------------------------------------------------------------------- */

[data-tooltip][data-tooltip-pos="left"]::after {
  top: 50%;
  bottom: auto;
  inset-inline-end: calc(100% + 8px);
  left: auto;
  transform: translateY(-50%) translateX(4px);
}

[data-tooltip][data-tooltip-pos="left"]:hover::after,
[data-tooltip][data-tooltip-pos="left"]:focus-visible::after {
  transform: translateY(-50%) translateX(0);
}

[data-tooltip][data-tooltip-pos="left"]::before {
  top: 50%;
  bottom: auto;
  inset-inline-end: calc(100% + 3px);
  left: auto;
  transform: translateY(-50%);
  border-block: 5px solid transparent;
  border-inline-start: 5px solid var(--au-gray-900);
  border-inline-end: none;
}

@media (prefers-color-scheme: dark) {
  [data-tooltip][data-tooltip-pos="left"]::before {
    border-inline-start-color: var(--au-gray-700);
  }
}

/* -----------------------------------------------------------------------
   Position: right
   ----------------------------------------------------------------------- */

[data-tooltip][data-tooltip-pos="right"]::after {
  top: 50%;
  bottom: auto;
  left: auto;
  inset-inline-start: calc(100% + 8px);
  transform: translateY(-50%) translateX(-4px);
}

[data-tooltip][data-tooltip-pos="right"]:hover::after,
[data-tooltip][data-tooltip-pos="right"]:focus-visible::after {
  transform: translateY(-50%) translateX(0);
}

[data-tooltip][data-tooltip-pos="right"]::before {
  top: 50%;
  bottom: auto;
  left: auto;
  inset-inline-start: calc(100% + 3px);
  transform: translateY(-50%);
  border-block: 5px solid transparent;
  border-inline-end: 5px solid var(--au-gray-900);
  border-inline-start: none;
}

@media (prefers-color-scheme: dark) {
  [data-tooltip][data-tooltip-pos="right"]::before {
    border-inline-end-color: var(--au-gray-700);
  }
}

/* -----------------------------------------------------------------------
   Reduced motion
   ----------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  [data-tooltip]::before,
  [data-tooltip]::after {
    transition: none;
  }
}

/* -----------------------------------------------------------------------
   Programmatic tooltip component (class-based alternative)
   ----------------------------------------------------------------------- */

.au-tooltip {
  position: absolute;
  z-index: var(--au-z-tooltip);
  padding: var(--au-space-1) var(--au-space-2);
  font-family: var(--au-font-family);
  font-size: var(--au-text-xs);
  font-weight: var(--au-weight-medium);
  line-height: var(--au-leading-tight);
  white-space: nowrap;
  color: #FFFFFF;
  background-color: var(--au-gray-900);
  border-radius: var(--au-radius-sm);
  box-shadow: var(--au-shadow-md);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--au-duration-fast) var(--au-ease-default);
}

.au-tooltip--visible {
  opacity: 1;
}
