/* ==========================================================================
   Refactor: модалки + tgx компоненты + уменьшение повторов
   (Ориентировано на токены из предыдущего CSS: цвета/градиенты/тени/радиусы)
   ========================================================================== */

/* Локальные токены (если :root уже есть в общем файле — можно убрать этот блок) */
:root {
    --c-primary-900: #021d4c;
    --c-primary-600: #3174b8;
    --c-primary-500: #2761a1;

    --c-modal-bg: #edf2f7;
    --c-border: #bfbfbf;

    --grad-primary: linear-gradient(90deg, var(--c-primary-900) 0%, var(--c-primary-600) 100%);
    --grad-primary-rev: linear-gradient(270deg, var(--c-primary-900) 0%, var(--c-primary-600) 100%);
    --grad-text: linear-gradient(to right, var(--c-primary-900), var(--c-primary-600));

    --shadow-1: 0 0 7px 1px rgba(0, 0, 0, 0.5);
    --shadow-2: 0 15px 15px rgba(0, 0, 0, 0.25), inset 0 4px 4px rgba(0, 0, 0, 0.25);
    --shadow-3: 0 5px 5px rgba(0, 0, 0, 0.25), inset 0 4px 4px rgba(0, 0, 0, 0.25);

    --r-sm: 0.5rem;
    --r-md: 0.7rem;
    --r-lg: 10px;
    --r-xl: 2rem;

    --z-backdrop: 1;
    --z-modal: 2;
    --z-float: 100;
    --z-top: 9999;

    --tr-fast: 0.2s ease;
    --tr-mid: 0.3s ease;
}

/* ==========================================================================
   System modal
   ========================================================================== */

.system__modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--z-backdrop);
}

.system__modal {
    position: fixed;
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    max-width: 800px;
    z-index: var(--z-modal);

    box-shadow: var(--shadow-1);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    overflow: hidden; /* чтобы шапка/тело не выходили за радиус */
}

.system__modal_title {
    padding: 10px;
    background: var(--c-modal-bg);
    border-bottom: 1px solid var(--c-border);

    text-align: center;
    font-weight: 700;
    font-size: 16px !important;
    color: #003681;

    text-wrap: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.system__modal_body {
    padding: 10px;
    background: #fff;
    max-height: 80vh;
    overflow-y: auto;
}

.system__modal_footer {
    border-top: 1px solid var(--c-border);
    padding: 5px;
    background: var(--c-modal-bg);

    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
}

.system__modal_footer-button {
    border: 1px solid var(--c-border);
    padding: 7px;
    min-width: 100px;

    text-align: center;
    font-weight: 700;
    background: #f1f1f1;
}

.system__modal_footer-link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* ==========================================================================
   Text wrapper / ellipsis
   ========================================================================== */

.text-wrapper {
    max-width: 25rem;
    overflow: hidden;

    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.text-wrapper .text-container {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    flex: 1;
}

.text-wrapper .more-link {
    display: none;
}

.text-wrapper .text-container.expanded {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
}

/* ==========================================================================
   Attach action buttons (hover/focus reveal)
   ========================================================================== */

.tgx-attach-action-buttons {
    position: absolute;
    top: -1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-float);

    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}

/* Родитель, у которого есть прямой потомок .tgx-attach-action-buttons */
*:has(> .tgx-attach-action-buttons) {
    position: relative;
}

/* Скрыто по умолчанию */
*:has(> .tgx-attach-action-buttons) > .tgx-attach-action-buttons {
    opacity: 0;
    filter: blur(5px);
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--tr-mid), filter var(--tr-mid), visibility 0s linear var(--tr-mid);
}

/* Подсветка контейнера (когда есть реальные кнопки) */
*:has(> .tgx-attach-action-buttons:hover > :not(:empty)):hover {
    outline: 1px dotted var(--c-primary-500);
}

/* Показ по hover/focus-within */
*:has(> .tgx-attach-action-buttons):hover > .tgx-attach-action-buttons,
*:has(> .tgx-attach-action-buttons):focus-within > .tgx-attach-action-buttons {
    opacity: 0.85;
    filter: blur(0);
    visibility: visible;
    pointer-events: auto;
    transition: opacity var(--tr-mid), filter var(--tr-mid), visibility 0s linear;
}

*:has(> .tgx-attach-action-buttons):hover > .tgx-attach-action-buttons:hover {
    opacity: 1;
}

/* Кнопки */
.tgx-attach-action-buttons > .tgx-action-button {
    cursor: pointer;
    line-height: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    width: 100%;
    height: 100%;

    background: linear-gradient(to right, var(--c-primary-900), var(--c-primary-600));
    box-shadow: var(--shadow-2);
    color: #fff;

    border: none;
    padding: 0.5rem;
    border-radius: 50%;
    font-size: 1.2rem;
}

.tgx-attach-action-buttons > .tgx-action-button:hover {
    background: linear-gradient(to left, var(--c-primary-900), var(--c-primary-600));
}

.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;
}

/* ==========================================================================
   Markdown header controls
   ========================================================================== */

.render-markdown-header a {
    display: none;
}

.render-markdown-header:hover a {
    display: inline;
}

/* ==========================================================================
   Insertion zone
   ========================================================================== */

.tgx-insertion-zone {
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-around !important;
    align-items: center !important;

    height: 100% !important;
    width: 100% !important;

    border-radius: var(--r-sm);
    text-decoration: none !important;
    padding: 1.5rem !important;

    opacity: 0.85 !important;
    background-color: rgba(255, 255, 255, 0.75) !important;

    transition: opacity var(--tr-mid),
    border var(--tr-mid),
    transform var(--tr-mid),
    box-shadow var(--tr-mid) !important;
}

.tgx-insertion-zone:hover {
    opacity: 1 !important;
}

.tgx-insertion-zone span {
    color: transparent;
    background-clip: text;
    background-image: var(--grad-text);

    font-size: 1.6rem;
    font-weight: 700;
}

.tgx-insertion-zone div {
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 0;

    font-size: 4rem;
    color: #fff;

    width: 3.5rem;
    height: 3.5rem;
    border-radius: 50%;
    font-weight: 300;

    background: linear-gradient(to right, var(--c-primary-900), var(--c-primary-600));
    margin-bottom: 1rem;
}

/* ==========================================================================
   Quill overrides
   ========================================================================== */

.ql-container {
    font-size: unset !important;
}

.ql-editor {
    padding: 0 !important;
}

.ql-toolbar {
    width: 100%;
}

/* Сброс inline стилей редактора */
.ql-container .ql-editor [style*="font-size"],
.ql-container .ql-editor [style*="font-family"],
.ql-container .ql-editor [style*="color"],
.ql-container .ql-editor [style*="background-color"] {
    all: unset !important;
    font-size: inherit !important;
    font-family: inherit !important;
    color: inherit !important;
    background-color: transparent !important;
}

/* ==========================================================================
   Tree
   ========================================================================== */

.tree {
    font-size: 0.95rem;
}

.tree ul {
    list-style: none;
    margin: 0;
    padding-left: 1rem;
}

.tree li {
    margin: 0.4rem 0;
    position: relative;
    text-wrap: nowrap;
}

.tree li::before {
    content: "";
    position: absolute;
    left: -1rem;
    top: 0.7rem;
    width: 0.8rem;
    height: 1px;
}

.tree li > .action {
    opacity: 0;
    transition: opacity var(--tr-mid);
}

.tree li:hover > .action {
    opacity: 1;
}

.tree button {
    background: none;
    border: none;
    padding: 0;

    font-weight: 500;
    cursor: pointer;

    display: flex;
    align-items: center;
    gap: 0.4rem;

    text-wrap: nowrap;
}

.tree a {
    text-wrap: nowrap;
}

.tree button:hover,
.tree .add-page:hover {
    text-decoration: underline;
}

.tree .icon-toggle {
    transition: transform var(--tr-fast);
}

.tree button[aria-expanded="true"] .icon-toggle {
    transform: rotate(90deg);
}

.tree .add-page {
    cursor: pointer;
}

/* ==========================================================================
   Bookmark login corner
   ========================================================================== */

.tgx-bookmark-login {
    position: fixed;
    inset: 0 auto auto 0;
    width: 2rem;
    height: 2rem;

    display: block;
    z-index: var(--z-top);
    cursor: pointer;
}

.tgx-bookmark-login::before {
    content: "";
    position: absolute;
    inset: 0;

    background: linear-gradient(315deg, var(--c-primary-600) 0%, var(--c-primary-900) 100%);
    clip-path: polygon(0 0, 100% 0, 0 100%);

    transform: scale(1);
    transform-origin: top left;
    opacity: 0.05;

    transition: transform 0.25s ease, opacity 0.25s ease;
}

.tgx-bookmark-login:hover::before {
    transform: scale(2);
    opacity: 1;
}

/* ==========================================================================
   Pre text container
   ========================================================================== */

.tgx-pre-text-container {
    text-wrap: wrap;
    text-align: justify;
    overflow: auto;
    white-space: pre-wrap;
}

/* ==========================================================================
   File actions (delete / download)
   ========================================================================== */

.tgx-delete-file,
.tgx-download-file {
    position: absolute;
    top: -0.3rem;

    padding: 0.1rem;
    display: flex;
    align-items: center;
    justify-content: center;

    color: #fff;
    cursor: pointer;
    z-index: var(--z-modal);

    border-radius: 50%;
    line-height: 1;

    background: linear-gradient(90deg, var(--c-primary-600) 0%, var(--c-primary-900) 100%);
}

.tgx-delete-file {
    right: -0.3rem;
}

.tgx-download-file {
    left: -0.3rem;
}

.tgx-delete-file i,
.tgx-download-file i {
    font-size: 1.2rem;
}

/* ==========================================================================
   Forms
   ========================================================================== */

.tgx-form {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 1.5rem;
}

.tgx-form-label {
    display: flex;
    align-items: center;
}

.tgx-form-label label {
    font-size: 18px;
}

.tgx-form-value input,
.tgx-form-value select,
.tgx-form-value textarea {
    box-shadow: var(--shadow-2);
    border-radius: var(--r-md) !important;
    padding: 0.5rem 1rem !important;
}

/* Label with image upload */
label:has(img) {
    cursor: pointer;
    position: relative;

    display: flex;
    align-items: center;
    justify-content: center;

    background: #fff;
    width: 6rem;
    height: 6rem;

    border-radius: var(--r-md);
    box-shadow: 0 5px 5px rgba(0, 0, 0, 0.25);
}

label img {
    position: absolute;
    object-fit: contain;
    width: 4rem;
    height: 4rem;
}

label .bg {
    width: 4rem;
    height: 4rem;
    background-image: radial-gradient(circle, #3174b847 1px, rgba(0, 0, 0, 0) 1px);
    background-size: 0.4rem 0.4rem;
}

/* Hover overlay + icon */
label:has(> img):hover::before {
    content: "";
    position: absolute;
    inset: 0;

    background-color: rgba(0, 0, 0, 0.4);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);

    z-index: 1;
    border-radius: var(--r-md);
    transition: background-color var(--tr-mid), box-shadow var(--tr-mid);
}

label:has(> img):hover::after {
    content: "\F219";
    font-family: "bootstrap-icons", serif;

    position: absolute;
    left: 50%;
    top: 50%;

    opacity: 0.6;
    font-size: 3rem;

    transform: translate(-50%, -50%);
    color: #fff;
    z-index: 2;
}

/* ==========================================================================
   Blur container
   ========================================================================== */

.tgx-box-container-blur {
    border: 3px solid rgba(255, 255, 255, 0.5);
    background-color: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(10px);

    padding: 2.5rem;
    color: #fff;

    border-radius: var(--r-xl);
    box-shadow: var(--shadow-2);
}

/* ==========================================================================
   Buttons (primary/light)
   ========================================================================== */

.tgx-btn-primary,
.tgx-btn-light {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    opacity: 0.95;
    cursor: pointer;
    line-height: 0;

    border: none;
    text-decoration: none;

    border-radius: var(--r-xl);
    text-transform: uppercase;
    font-weight: 700;
}

.tgx-btn-primary {
    background: var(--grad-primary);
    box-shadow: var(--shadow-3);
    color: #fff !important;
    padding: 1.5rem 2rem;
}

.tgx-btn-primary:not(:disabled):hover {
    opacity: 1;
    background: var(--grad-primary-rev);
}

.tgx-btn-primary:disabled {
    opacity: .75;
}

.tgx-btn-light {
    background: #fff;
    box-shadow: var(--shadow-2);
    color: var(--c-primary-500) !important;
    padding: 1.31rem 1.5rem;
}

.tgx-btn-light:hover {
    opacity: 1;
}

.tgx-btn-primary *,
.tgx-btn-light * {
    line-height: 0;
}

/* Bootstrap backdrop tweak */
.modal-backdrop.show {
    opacity: 0.75 !important;
}

/* ==========================================================================
   Text shadow + white color utility
   ========================================================================== */

.tgx-text-shadow,
.tgx-text-shadow * {
    text-shadow: 0 5px 10px rgba(0, 0, 0, 0.25);
}

.tgx-color-white,
.tgx-color-white * {
    color: #fff !important;
}

/* ==========================================================================
   Loader
   ========================================================================== */

body.tgx-loader {
    height: 100%;
}

.tgx-loader {
    --loader-size: 64px;
    --loader-scale-duration: 0.3s;

    position: relative;
    overflow: hidden;
    pointer-events: none;
    cursor: wait;

    height: auto;
    width: 100%;
}

.tgx-loader > * {
    opacity: 0.4;
    filter: blur(10px);
}

.tgx-loader::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;

    width: 100%;
    height: 100%;
    max-width: var(--loader-size);
    max-height: var(--loader-size);

    background-image: url(/public/assets/images/gif/loader.svg);
    background-position: center;
    background-size: contain;
    background-repeat: no-repeat;

    transform: translate(-50%, -50%) scale(0);
    opacity: 1;

    animation: scaleUp var(--loader-scale-duration) ease-in-out forwards;
}

@keyframes scaleUp {
    from {
        transform: translate(-50%, -50%) scale(0);
    }
    to {
        transform: translate(-50%, -50%) scale(1);
    }
}

.tgx-bubble {
    position: fixed;
    z-index: 9999;
    background: #fff;
    border-radius: 2rem;
    padding: 1rem 2rem;
    /* box-shadow: inset 0 4px 4px rgba(0, 0, 0, 0.25); */
    /* filter: drop-shadow(0px 15px 15px rgba(0, 0, 0, 0.25)); */
    filter: drop-shadow(0 -2px 8px rgba(0, 0, 0, .06)) /* немного сверху */ drop-shadow(0 10px 18px rgba(0, 0, 0, .16)) drop-shadow(0 0 1px rgba(0, 0, 0, .10)); /* лёгкая обводка */

    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translate(var(--enter-x, 0px), var(--enter-y, 10px)) scale(.98);
    transition: opacity .15s ease, transform .15s ease, visibility 0s linear .15s;
    isolation: isolate;

    --arrow-size: clamp(12px, 2.2vw, 18px);
    --arrow-x: 80px;
    --arrow-y: 60px;
}

.tgx-bubble[data-state="measuring"] {
    transition: none;
    transform: none;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.tgx-bubble[data-state="open"] {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translate(0, 0) scale(1);
    transition: opacity .15s ease, transform .15s ease, visibility 0s;
}

.tgx-bubble__title {
    font-size: clamp(18px, 3.6vw, 28px);
    font-weight: 700;
    color: var(--c-primary-900);
    margin: 0 0 10px 0;
    line-height: 1.1;
    text-align: center;
}

.tgx-bubble__text {
    font-size: clamp(14px, 3vw, 20px);
    opacity: 75%;
    margin: 0;
    text-align: center;
    white-space: pre-wrap;
}

.tgx-bubble__close {
    display: none;
    position: absolute;
    top: 10px;
    right: 16px;
    width: 40px;
    height: 40px;
    border-radius: 999px;
    border: 0;
    background: transparent;
    font-size: 22px;
    cursor: pointer;
    color: #9aa3ad;
}

.tgx-bubble__close:hover {
    color: #5f6b77;
}

.tgx-bubble::after {
    content: "";
    position: absolute;
    width: var(--arrow-size);
    height: var(--arrow-size);
    background: inherit;
    transform: rotate(45deg);
    z-index: -1;
    box-shadow: none;
}

.tgx-bubble[data-side="top"] {
    transform-origin: center bottom;
    --enter-y: 10px;
    --enter-x: 0px;
}

.tgx-bubble[data-side="top"]::after {
    left: calc(var(--arrow-x) - (var(--arrow-size) / 2));
    top: calc(100% - (var(--arrow-size) / 2));
}

.tgx-bubble[data-side="bottom"] {
    transform-origin: center top;
    --enter-y: -10px;
    --enter-x: 0px;
}

.tgx-bubble[data-side="bottom"]::after {
    left: calc(var(--arrow-x) - (var(--arrow-size) / 2));
    top: calc(-1 * (var(--arrow-size) / 2));
}

.tgx-bubble[data-side="left"] {
    transform-origin: right center;
    --enter-x: 10px;
    --enter-y: 0px;
}

.tgx-bubble[data-side="left"]::after {
    top: calc(var(--arrow-y) - (var(--arrow-size) / 2));
    left: calc(100% - (var(--arrow-size) / 2));
}

.tgx-bubble[data-side="right"] {
    transform-origin: left center;
    --enter-x: -10px;
    --enter-y: 0px;
}

.tgx-bubble[data-side="right"]::after {
    top: calc(var(--arrow-y) - (var(--arrow-size) / 2));
    left: calc(-1 * (var(--arrow-size) / 2));
}

@media (prefers-reduced-motion: reduce) {
    .tgx-bubble {
        transition: none !important;
    }
}