/*
 * tvt-tooltip 1.0.0: the styles of public/js/tvt-tooltip.js. Plain CSS, loaded by URL (not processed by Vite).
 * The panel's place, its fade and its arrow: colours, size, padding and text are Tailwind classes on the panel.
 */

/* in Tailwind's base layer, so a class on the panel wins ([--tvt-tooltip-offset:4px], max-w-xs, text-*, bg-*): the
   sizes, the widest it gets, and the browser's popover colours (CanvasText on Canvas), which a panel without a text-*
   class replaces with the text colour of the markup around it */
@layer base {
    [data-tvt-tooltip-content] {
        --tvt-tooltip-arrow-size: 6px;
        --tvt-tooltip-offset: 10px; /* from the trigger: the arrow and a gap */
        --tvt-tooltip-edge: 8px; /* the closest the panel comes to the viewport's edges */
        --tvt-tooltip-bg: #ffffff; /* both set by tvt-tooltip.js from the panel's own colours */
        --tvt-tooltip-border: #90a1b9;

        max-width: calc(100vw - 2 * var(--tvt-tooltip-edge));
        color: inherit;
        background-color: transparent;
    }
}

/* panel: in the top layer (popover attribute) when it is open, placed by tvt-tooltip.js (left / top, and
   data-tvt-tooltip-side, the side of the trigger it is on). Hidden until data-tvt-tooltip-open, also before the
   script has set the popover attribute; it fades in with data-tvt-tooltip-shown. */
[data-tvt-tooltip-content] {
    position: fixed;
    inset: auto;
    z-index: 120; /* only where the top layer is missing: above the modals and the toasts */
    margin: 0;
    overflow: visible;
    opacity: 0;
    scale: 0.98;
    transition: opacity 300ms, scale 300ms;
}

[data-tvt-tooltip-content]:not([data-tvt-tooltip-open]) {
    display: none;
}

[data-tvt-tooltip-content][data-tvt-tooltip-shown] {
    opacity: 1;
    scale: 1;
}

@media (prefers-reduced-motion: reduce) {
    [data-tvt-tooltip-content] {
        scale: none;
    }
}

/* it grows from the arrow */
[data-tvt-tooltip-side="top"] {
    transform-origin: var(--tvt-tooltip-arrow-at, 50%) 100%;
}

[data-tvt-tooltip-side="bottom"] {
    transform-origin: var(--tvt-tooltip-arrow-at, 50%) 0;
}

[data-tvt-tooltip-side="left"] {
    transform-origin: 100% var(--tvt-tooltip-arrow-at, 50%);
}

[data-tvt-tooltip-side="right"] {
    transform-origin: 0 var(--tvt-tooltip-arrow-at, 50%);
}

/* arrow: ::before in the border colour, ::after in the background colour 1px inside it, over the panel's border.
   --tvt-tooltip-arrow-at is where the trigger's middle is along that edge, so the arrow still points at it when the
   panel is shifted to stay in the viewport. */
[data-tvt-tooltip-side]::before,
[data-tvt-tooltip-side]::after {
    content: "";
    position: absolute;
    width: 0;
    height: 0;
    border: 0 solid transparent;
    pointer-events: none;
}

/* above the trigger: arrow on the bottom edge, pointing down */
[data-tvt-tooltip-side="top"]::before,
[data-tvt-tooltip-side="top"]::after {
    top: 100%;
    left: var(--tvt-tooltip-arrow-at, 50%);
    translate: -50% 0;
}

[data-tvt-tooltip-side="top"]::before {
    border-width: calc(var(--tvt-tooltip-arrow-size) + 1px) calc(var(--tvt-tooltip-arrow-size) + 1px) 0;
    border-top-color: var(--tvt-tooltip-border);
}

[data-tvt-tooltip-side="top"]::after {
    margin-top: -1px;
    border-width: var(--tvt-tooltip-arrow-size) var(--tvt-tooltip-arrow-size) 0;
    border-top-color: var(--tvt-tooltip-bg);
}

/* below the trigger: arrow on the top edge, pointing up */
[data-tvt-tooltip-side="bottom"]::before,
[data-tvt-tooltip-side="bottom"]::after {
    bottom: 100%;
    left: var(--tvt-tooltip-arrow-at, 50%);
    translate: -50% 0;
}

[data-tvt-tooltip-side="bottom"]::before {
    border-width: 0 calc(var(--tvt-tooltip-arrow-size) + 1px) calc(var(--tvt-tooltip-arrow-size) + 1px);
    border-bottom-color: var(--tvt-tooltip-border);
}

[data-tvt-tooltip-side="bottom"]::after {
    margin-bottom: -1px;
    border-width: 0 var(--tvt-tooltip-arrow-size) var(--tvt-tooltip-arrow-size);
    border-bottom-color: var(--tvt-tooltip-bg);
}

/* left of the trigger: arrow on the right edge, pointing right */
[data-tvt-tooltip-side="left"]::before,
[data-tvt-tooltip-side="left"]::after {
    left: 100%;
    top: var(--tvt-tooltip-arrow-at, 50%);
    translate: 0 -50%;
}

[data-tvt-tooltip-side="left"]::before {
    border-width: calc(var(--tvt-tooltip-arrow-size) + 1px) 0 calc(var(--tvt-tooltip-arrow-size) + 1px) calc(var(--tvt-tooltip-arrow-size) + 1px);
    border-left-color: var(--tvt-tooltip-border);
}

[data-tvt-tooltip-side="left"]::after {
    margin-left: -1px;
    border-width: var(--tvt-tooltip-arrow-size) 0 var(--tvt-tooltip-arrow-size) var(--tvt-tooltip-arrow-size);
    border-left-color: var(--tvt-tooltip-bg);
}

/* right of the trigger: arrow on the left edge, pointing left */
[data-tvt-tooltip-side="right"]::before,
[data-tvt-tooltip-side="right"]::after {
    right: 100%;
    top: var(--tvt-tooltip-arrow-at, 50%);
    translate: 0 -50%;
}

[data-tvt-tooltip-side="right"]::before {
    border-width: calc(var(--tvt-tooltip-arrow-size) + 1px) calc(var(--tvt-tooltip-arrow-size) + 1px) calc(var(--tvt-tooltip-arrow-size) + 1px) 0;
    border-right-color: var(--tvt-tooltip-border);
}

[data-tvt-tooltip-side="right"]::after {
    margin-right: -1px;
    border-width: var(--tvt-tooltip-arrow-size) var(--tvt-tooltip-arrow-size) var(--tvt-tooltip-arrow-size) 0;
    border-right-color: var(--tvt-tooltip-bg);
}
