/* ==========================================================================
   Attach action buttons (hover/focus reveal)
   ========================================================================== */

.tgx-attach-action-buttons {
    position: absolute;
    top: -1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-float, 100);
    width: fit-content;

    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.35rem;
    max-width: calc(100vw - 1rem);
}

/* Родитель, у которого есть прямой потомок .tgx-attach-action-buttons */
*:has(> .tgx-attach-action-buttons:not(.tgx-attach-action-buttons-external)) {
    position: relative;
}

/* Скрыто по умолчанию */
*:has(> .tgx-attach-action-buttons:not(.tgx-attach-action-buttons-external))
> .tgx-attach-action-buttons:not(.tgx-attach-action-buttons-external) {
    opacity: 0;
    filter: blur(5px);
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--tr-mid, 0.3s ease), filter var(--tr-mid, 0.3s ease), visibility 0s linear var(--tr-mid, 0.3s ease);
}

/* Базовая подсветка хоста с кнопками */
*:has(> .tgx-attach-action-buttons:not(.tgx-attach-action-buttons-external) > :not(:empty)):hover {
    outline: 1px dotted var(--c-primary-500, #265aca);
}

/* Показ по hover/focus-within */
*:has(> .tgx-attach-action-buttons:not(.tgx-attach-action-buttons-external)):hover
> .tgx-attach-action-buttons:not(.tgx-attach-action-buttons-external),
*:has(> .tgx-attach-action-buttons:not(.tgx-attach-action-buttons-external)):focus-within
> .tgx-attach-action-buttons:not(.tgx-attach-action-buttons-external) {
    opacity: 0.85;
    filter: blur(0);
    visibility: visible;
    pointer-events: auto;
    transition: opacity var(--tr-mid, 0.3s ease), filter var(--tr-mid, 0.3s ease), visibility 0s linear;
}

/* Если внутри есть более глубокий hover/focus-хост, скрываем кнопки предка */
*:has(> .tgx-attach-action-buttons:not(.tgx-attach-action-buttons-external)):hover:has(
    *:hover > .tgx-attach-action-buttons:not(.tgx-attach-action-buttons-external)
) {
    outline: none;
}

*:has(> .tgx-attach-action-buttons:not(.tgx-attach-action-buttons-external)):hover:has(
    *:hover > .tgx-attach-action-buttons:not(.tgx-attach-action-buttons-external)
)
> .tgx-attach-action-buttons:not(.tgx-attach-action-buttons-external),
*:has(> .tgx-attach-action-buttons:not(.tgx-attach-action-buttons-external)):focus-within:has(
    *:focus-within > .tgx-attach-action-buttons:not(.tgx-attach-action-buttons-external)
)
> .tgx-attach-action-buttons:not(.tgx-attach-action-buttons-external) {
    opacity: 0;
    filter: blur(5px);
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--tr-mid, 0.3s ease), filter var(--tr-mid, 0.3s ease), visibility 0s linear var(--tr-mid, 0.3s ease);
}

*:has(> .tgx-attach-action-buttons:not(.tgx-attach-action-buttons-external)):hover
> .tgx-attach-action-buttons:not(.tgx-attach-action-buttons-external):hover {
    opacity: 1;
}

/* Узлы без HTML-содержимого и структурные узлы таблиц используют панель в body. */
.tgx-attach-action-buttons-external {
    position: fixed;
    z-index: var(--z-float, 100);
    opacity: 0;
    filter: blur(5px);
    visibility: hidden;
    pointer-events: none;
    transform: translate(-50%, -100%);
    transition: opacity var(--tr-mid, 0.3s ease), filter var(--tr-mid, 0.3s ease), visibility 0s linear var(--tr-mid, 0.3s ease);
}

.tgx-attach-action-buttons-external.is-below {
    transform: translate(-50%, 0);
}

.tgx-attach-action-buttons-external.is-visible {
    opacity: .92;
    filter: blur(0);
    visibility: visible;
    pointer-events: auto;
    transition: opacity var(--tr-mid, 0.3s ease), filter var(--tr-mid, 0.3s ease), visibility 0s linear;
}

[data-tgx-action-host-active] {
    outline: 1px dotted var(--c-primary-500, #265aca);
    outline-offset: 2px;
}

.tgx-attach-action-buttons-external.is-visible:hover {
    opacity: 1;
}

/* Кнопки */
.tgx-attach-action-buttons > .tgx-action-button {
    cursor: pointer;
    line-height: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    flex: 0 0 2.25rem;
    width: 2.25rem;
    height: 2.25rem;

    background: linear-gradient(to right, var(--c-primary-900, #142542), var(--c-primary-600, #265aca));
    box-shadow: var(--shadow-2, 0 8px 16px rgb(0 0 0 / .2));
    color: #fff;

    border: none;
    padding: 0.45rem;
    border-radius: 50%;
    font-size: 1.2rem;
}

.tgx-attach-action-buttons > .tgx-action-button:hover {
    background: linear-gradient(to left, var(--c-primary-900, #142542), var(--c-primary-600, #265aca));
}

.tgx-attach-action-buttons > .tgx-action-button.btn-move {
    cursor: grab;
}

/* Скрываем удаление/перемещение если единственный элемент */
*:has(> *:only-child) > *:only-child > .tgx-attach-action-buttons > .btn-delete,
*:has(> *:only-child) > *:only-child > .tgx-attach-action-buttons > .btn-move {
    display: none !important;
}

/* ==========================================================================
   Bookmark login corner
   ========================================================================== */

.tgx-bookmark-login {
    --tgx-bookmark-hit-width: 2rem;
    --tgx-bookmark-indicator-size: 1rem;
    position: fixed;
    top: env(safe-area-inset-top, 0);
    left: 0;
    z-index: var(--z-top, 9999);
    display: flex;
    box-sizing: border-box;
    width: 8.75rem;
    height: 2.5rem;
    align-items: center;
    justify-content: space-between;
    gap: .625rem;
    overflow: hidden;
    padding: 0 .5rem 0 .875rem;
    border-radius: 0 0 .8rem 0;
    color: var(--brand-white, #fff);
    background: transparent;
    box-shadow: none;
    font-family: var(--font-family-ui, system-ui, -apple-system, "Segoe UI", sans-serif);
    font-size: .875rem;
    font-weight: 600;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    transform: translateX(calc(-100% + var(--tgx-bookmark-hit-width)));
    opacity: 1;
    isolation: isolate;
    cursor: pointer;
    transition: transform .2s ease, opacity .2s ease, box-shadow .2s ease;
}

.tgx-bookmark-login::before {
    position: absolute;
    z-index: -1;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--brand-graphite, #2d3235) 0%, var(--brand-primary, #386dec) 100%);
    clip-path: polygon(
            calc(100% - var(--tgx-bookmark-hit-width)) 0,
            calc(100% - var(--tgx-bookmark-hit-width) + var(--tgx-bookmark-indicator-size)) 0,
            calc(100% - var(--tgx-bookmark-hit-width)) var(--tgx-bookmark-indicator-size)
    );
    content: '';
    opacity: .22;
    transition: clip-path .2s ease, opacity .2s ease;
}

.tgx-bookmark-login:hover,
.tgx-bookmark-login:focus,
.tgx-bookmark-login:focus-visible {
    color: var(--brand-white, #fff);
    border-color: rgba(var(--brand-white-rgb, 255, 255, 255), .28);
    border-top-color: transparent;
    border-left-color: transparent;
    box-shadow: 0 .75rem 2rem rgba(2, 29, 76, .28);
    text-decoration: none;
    transform: translateX(0);
    opacity: 1;
}

.tgx-bookmark-login:hover::before,
.tgx-bookmark-login:focus::before,
.tgx-bookmark-login:focus-visible::before {
    clip-path: inset(0);
    opacity: 1;
}

.tgx-bookmark-login:focus-visible {
    outline: 3px solid rgba(var(--brand-white-rgb, 255, 255, 255), .95);
    outline-offset: -4px;
}

.tgx-bookmark-login:active {
    background: transparent;
}

.tgx-bookmark-login:active::before {
    background: linear-gradient(90deg, var(--brand-graphite, #2d3235) 0%, var(--brand-primary-active, #274fad) 100%);
}

.tgx-bookmark-login__label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0;
    transform: translateX(-.25rem);
    transition: transform .2s ease, opacity .15s ease;
}

.tgx-bookmark-login:hover .tgx-bookmark-login__label,
.tgx-bookmark-login:focus .tgx-bookmark-login__label,
.tgx-bookmark-login:focus-visible .tgx-bookmark-login__label {
    opacity: 1;
    transform: translateX(0);
}

.tgx-bookmark-login__mark {
    display: block;
    flex: 0 0 1.5rem;
    width: 1.5rem;
    height: 1.5rem;
    object-fit: contain;
    opacity: 0;
    transition: opacity .15s ease;
}

.tgx-bookmark-login:hover .tgx-bookmark-login__mark,
.tgx-bookmark-login:focus .tgx-bookmark-login__mark,
.tgx-bookmark-login:focus-visible .tgx-bookmark-login__mark {
    opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
    .tgx-bookmark-login,
    .tgx-bookmark-login::before,
    .tgx-bookmark-login__label,
    .tgx-bookmark-login__mark {
        transition: none;
    }
}
