/* The bubble of Components/Shared/Tooltip.razor. interop.js opens it as a popover and sets its top/left. */
.tooltip {
  /* Undo the browser's popover defaults (centered, bordered, Canvas colors). */
  position: fixed;
  inset: auto;
  margin: 0;
  border: none;
  overflow: visible;

  width: max-content;
  max-width: min(220px, calc(100vw - 16px));
  padding: 0.5rem 0.625rem;
  border-radius: 0.375rem;
  background: var(--color-text-primary);
  color: var(--color-white);
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.4;
  text-align: left;
  white-space: normal;

  /* Quick fade in and out. display and overlay are switched at the end of the fade-out rather than the start,
     so the bubble stays visible, and in the top layer, until it has faded. */
  opacity: 0;
  transition:
    opacity var(--motion-duration-exit) var(--motion-ease-exit),
    display var(--motion-duration-exit) allow-discrete,
    overlay var(--motion-duration-exit) allow-discrete;
}

.tooltip:popover-open {
  opacity: 1;
  transition:
    opacity var(--motion-duration-enter) var(--motion-ease-enter),
    display var(--motion-duration-enter) allow-discrete,
    overlay var(--motion-duration-enter) allow-discrete;
}

/* Where the fade-in starts, since a popover that has just opened has no earlier style to transition from. */
@starting-style {
  .tooltip:popover-open {
    opacity: 0;
  }
}

/* While fading out it can't be hovered, which would show it again. */
.tooltip:not(:popover-open) {
  pointer-events: none;
}

/* Fills the 6px gap to the element it belongs to, so the pointer can move onto the bubble without it closing. */
.tooltip::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 6px;
}

.tooltip[data-placement="top"]::before {
  top: 100%;
}

.tooltip[data-placement="bottom"]::before {
  bottom: 100%;
}
