[notifications] {
    &::after {

        position: fixed;
        inset: auto;
        top: max(calc(anchor(top) - 8px), 8px);
        right: max(calc(anchor(right) - 8px), 8px);

        display: flex;
        align-items: center;
        justify-content: center;
        width: 16px;
        height: 16px;
        position-anchor: auto;
        font-size: var(--font-size-xs);
        color: var(--white);

        pointer-events: none;
        content: attr(notifications);
        background-color: var(--error);
        border-radius: var(--radius-circle);
    }
}
[notifications="0"]::after { content: none; }

[presence] {
    position: relative;

    &::after {

        position: absolute;
        inset: auto;
        right: -3px;
        bottom: -3px;
        width: 12px;
        height: 12px;

        pointer-events: none;
        content: "";
        border-radius: var(--radius-circle);
    }
}

[presence="online"] {
    &::after {
        background-color: var(--success);
    }
}

[presence="away"] {
    &::after {
        background-color: var(--warning);
    }
}

[presence="do_not_disturb"] {
    &::after {
        background-color: var(--error);
    }
}

[presence="offline"] {
    &::after {
        background-color: var(--dark);
    }
}

[popover][anchor] {
    position-anchor: auto;
}

[popover] {
    position: fixed;
    inset: auto;
    top: anchor(bottom);
    left: anchor(left);
    z-index: var(--z-index-popover);
    margin-block: calc(var(--space-xs) / 2 );
    position-try-fallbacks: --bottom-left, --bottom-right, --top-left, --top-right;

    container-type: anchored;

    background-color: var(--white);
    border: 2px solid var(--light);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);

    &:popover-open {
        display: flex;
        flex-direction: column;
    }

    &[data-position="bottom-left"]  { top: anchor(bottom);   right: auto; bottom: auto; left: anchor(left); }
    &[data-position="bottom-right"] { top: anchor(bottom); right: anchor(right); bottom: auto; left: auto; }
    &[data-position="bottom"]       { top: anchor(bottom); right: auto; bottom: auto; left: anchor(center); translate: -50% 0; }
    &[data-position="top-left"]     { top: auto;   right: auto; bottom: anchor(top);    left: anchor(left); }
    &[data-position="top-right"]    { top: auto; right: anchor(right); bottom: anchor(top);    left: auto; }
    &[data-position="top"]          { top: auto; right: auto; bottom: anchor(top);    left: anchor(center); translate: -50% 0; }


    &.tooltip {
        top: anchor(bottom);
        left: calc(anchor(center) - var(--space-xs) * 2);
        width: 300px;
        padding: var(--space-xs);
        position-try-fallbacks: --tooltip-bottom-left, --tooltip-bottom-right, --tooltip-top-left, --tooltip-top-right;

        overflow: visible;
        font-size: var(--font-size-xs);

        color: var(--white);
        background-color: var(--dark);
        border: none;
        &::before {
            position: absolute;
            bottom: 90%;
            left: var(--space-xs);
            font-size: var(--font-size-xl);
            color: var(--dark);
            content: '▲';
        }

        @container anchored(fallback: --tooltip-bottom-left) {
            &::before {
                bottom: 90%;
                left: var(--space-xs);
                content: '▲';
            }
        }

        @container anchored(fallback: --tooltip-bottom-right) {
            &::before {
                right: var(--space-xs);
                bottom: 90%;
                left: unset;
                content: '▲';
            }
        }

        @container anchored(fallback: --tooltip-top-left) {
            &::before {
                top: 90%;
                bottom: auto;
                left: var(--space-xs);
                content: '▼';
            }
        }

        @container anchored(fallback: --tooltip-top-right) {
            &::before {
                top: 90%;
                right: var(--space-xs);
                bottom: auto;
                left: unset;
                content: '▼';
            }
        }
    }
}

@position-try --tooltip-bottom-left {
    left: calc(anchor(center) - var(--space-xs) * 2);
}

@position-try --tooltip-bottom-right {
    right: calc(anchor(center) - var(--space-xs) * 2);
    left: unset;
}

@position-try --tooltip-top-left {
    top: unset;
    bottom: anchor(top);
    left: calc(anchor(center) - var(--space-xs) * 2);
}

@position-try --tooltip-top-right {
    top: unset;
    right: calc(anchor(center) - var(--space-xs) * 2);
    bottom: anchor(top);
    left: unset;
}

[interestfor] {
    interest-delay-start: var(--transition-fast);
}

.skeleton {
    position: relative;
    display: grid;
    max-inline-size: 100%;
    overflow: hidden;
    color: transparent !important;
    pointer-events: none;
    background: color-mix(in srgb, var(--background) 80%, var(--white)) !important;
    border: none;
    border-radius: var(--radius-sm);

    &::after {
        position: absolute;
        inset: 0;
        content: '';
        background: linear-gradient(90deg,
            transparent 0%,
            color-mix(in srgb, var(--white) 82%, transparent) 45%,
            transparent 100%);
        transform: translateX(-100%);
        animation: table-skeleton-shimmer 1.4s ease-in-out infinite;
    }

    > * {
        visibility: hidden;
        grid-area: 1 / 1;
    }
}

.loader {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 48px;
    &::after, &::before {
        position: absolute;
        top: 0;
        left: 0;
        box-sizing: border-box;
        width: 48px;
        height: 48px;
        content: '';
        background: var(--white);
        border-radius: 50%;
        animation: animloader 2s linear infinite;
    }
    &::after {
        animation-delay: 1s;
    }

}

.request-indicator {
    display: none;
    align-items: center;
    gap: calc(var(--space-xs) / 2);
    color: var(--secondary);
    font-size: var(--font-size-sm);

    &.htmx-request {
        display: inline-flex;
    }
}

.request-spinner {
    display: inline-block;
    flex: 0 0 auto;
    width: 1em;
    aspect-ratio: 1;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: request-spinner 700ms linear infinite;
}

.link {
    color: var(--secondary);
    cursor: pointer;

    &:hover { text-decoration: underline; }
    &[href=""] { color: inherit; }

    &.remove {
        color: var(--dark);
        text-decoration: line-through;
        &::after { fill: var(--dark); }
    }

    &.file {
        display: inline-flex;
        align-items: center;
        gap: calc(var(--space-xs) / 2);

        &::after {
            flex-shrink: 0;
            width: var(--font-size-md);
            fill: var(--secondary);
        }
        &[href^="https://"]::after {
            content: url(/static/images/icons/file_types/link.svg);
        }
        &:is([href$=".csv"], [data_filename$=".csv" i])::after,
        &:is([href$=".xlsx"], [data_filename$=".xlsx" i])::after {
            content: url(/static/images/icons/file_types/csv.svg);
        }
        &:is([href$=".pdf"], [data_filename$=".pdf" i])::after {
            content: url(/static/images/icons/file_types/pdf.svg);
        }
        &:is([href$=".doc"], [data_filename$=".doc" i])::after,
        &:is([href$=".docx"], [data_filename$=".docx" i])::after {
            content: url(/static/images/icons/file_types/doc.svg);
        }
        &:is([href$=".ppt"], [data_filename$=".ppt" i])::after,
        &:is([href$=".pptx"], [data_filename$=".pptx" i])::after {
            content: url(/static/images/icons/file_types/ppt.svg);
        }
        &:is([href$=".png"], [data_filename$=".png" i])::after,
        &:is([href$=".jpg"], [data_filename$=".jpg" i])::after,
        &:is([href$=".jpeg"], [data_filename$=".jpeg" i])::after {
            content: url(/static/images/icons/file_types/img.svg);
        }
    }

    &.file-dark {
        display: inline-flex;
        align-items: center;
        gap: calc(var(--space-xs) / 2);

        &::after {
            flex-shrink: 0;
            width: var(--font-size-md);
            fill: var(--dark);
        }
        &[href^="https://"]::after {
            content: url(/static/images/icons/file_types/link-dark.svg);
        }
        &:is([href$=".csv"], [data_filename$=".csv" i])::after,
        &:is([href$=".xlsx"], [data_filename$=".xlsx" i])::after {
            content: url(/static/images/icons/file_types/csv-dark.svg);
        }
        &:is([href$=".pdf"], [data_filename$=".pdf" i])::after {
            content: url(/static/images/icons/file_types/pdf-dark.svg);
        }
        &:is([href$=".doc"], [data_filename$=".doc" i])::after,
        &:is([href$=".docx"], [data_filename$=".docx" i])::after {
            content: url(/static/images/icons/file_types/doc-dark.svg);
        }
        &:is([href$=".ppt"], [data_filename$=".ppt" i])::after,
        &:is([href$=".pptx"], [data_filename$=".pptx" i])::after {
            content: url(/static/images/icons/file_types/ppt-dark.svg);
        }
        &:is([href$=".png"], [data_filename$=".png" i])::after,
        &:is([href$=".jpg"], [data_filename$=".jpg" i])::after,
        &:is([href$=".jpeg"], [data_filename$=".jpeg" i])::after {
            content: url(/static/images/icons/file_types/img-dark.svg);
        }
    }

    &.silent {
        color: inherit;
        text-decoration: none;
    }

    &.button {
        color: var(--white);
        text-decoration: none;
    }
}

.link-group {
    > :not(:first-child)::before {
        display: inline-block;
        width: var(--font-size-sm);
        height: var(--font-size-sm);
        content: "";
        background: center/contain no-repeat url(/static/images/icons/right-dark.svg);
    }
}

.icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    aspect-ratio: 1;

    font-size: calc(1.25 * var(--font-size-md));
    vertical-align: middle;
    object-fit: cover;
    fill: currentColor;
    &.xxl {     font-size: calc(1.5 * var(--font-size-xl)); }
    &.xl {      font-size: calc(1.25 * var(--font-size-xl)); }
    &.lg {      font-size: calc(1.25 * var(--font-size-lg)); }
    &.md {      font-size: calc(1.25 * var(--font-size-md)); }
    &.sm {      font-size: calc(1.25 * var(--font-size-sm)); }
    &.xs {      font-size: calc(1.25 * var(--font-size-xs)); }
    &.xxs {     font-size: calc(1.0 * var(--font-size-xs)); }

    &.info {
        color: var(--info);
        &:hover { transform: scale(1.2); transform-origin: center; }
    }
    &.success {
        color: var(--success);
        &:hover { transform: scale(1.2); transform-origin: center; }
    }
    &.warning {
        color: var(--warning);
        &:hover { transform: scale(1.2); transform-origin: center; }
    }
    &.error {
        color: var(--error);
        &:hover { transform: scale(1.2); transform-origin: center; }
    }

    i { display: block; }
}

.item {
    display: flex;
    gap: var(--space-xs);
    align-items: center;

    padding: var(--space-xs) var(--space-md);
    color: var(--black);
    cursor: pointer;
    > .icon { width: var(--space-md); }

    &:hover {
        background-color: color-mix(in srgb, var(--secondary) 10%, var(--white));
    }
    &.vertical {
        border-left: 3px solid transparent;
        &:hover { border-left: 3px solid var(--secondary); }
        &.selected { border-left: 3px solid var(--secondary); }
    }
    &.horizontal {
        padding-bottom: calc(var(--space-xs) / 2);
        color: var(--dark);
        border-bottom: 3px solid transparent;
        border-top-left-radius: var(--radius-sm);
        border-top-right-radius: var(--radius-sm);
        &.selected { border-bottom: 3px solid var(--secondary); }

        &.selected, &:checked {
            color: var(--secondary);
        }
    }
    &.new {
        &::after {
            flex: 0 0 auto;
            width: 9px;
            height: 9px;
            margin-left: auto;
            content: "";
            background-color: var(--secondary);
            border-radius: var(--radius-circle);
        }
    }
    &.selected, &:checked {
        color: var(--secondary);
    }

    &.icon-xl { .icon { font-size: calc(1.25 * var(--font-size-xl)); width: var(--space-xl); } }
    &.icon-lg { .icon { font-size: calc(1.25 * var(--font-size-lg)); width: var(--space-lg); } }
    &.icon-md { .icon { font-size: calc(1.25 * var(--font-size-md)); width: var(--space-md); } }
    &.icon-sm { .icon { font-size: calc(1.25 * var(--font-size-sm)); width: var(--space-sm); } }
    &.icon-xs { .icon { font-size: calc(1.25 * var(--font-size-xs)); width: var(--space-xs); } }
}

.badge {
    display: inline-flex;
    align-items: center;
    align-self: start;
    justify-content: center;
    min-width: 80px;
    padding: calc(0.5 * var(--space-xs)) var(--space-xs);
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-radius: var(--radius-pill);
}

.section-label {
    display: inline;
    padding-left: var(--space-xs);
    font-size: var(--font-size-xs);
    font-weight: 500;
}

.tab-header {
    z-index: 1;
    display: flex;
    padding-top: var(--space-xs);
    padding-right: var(--space-xs);
    padding-left: var(--space-xs);
    margin-bottom: var(--space-xs);

    background-color: var(--background);
    border-bottom: 3px solid var(--light);
    &.justify-start         { justify-content: flex-start; }
    &.justify-end           { justify-content: flex-end; }
    &.justify-center        { justify-content: center; }
    &.justify-space-between { justify-content: space-between; }
    &.justify-space-around  { justify-content: space-around; }
    &.justify-space-evenly  { justify-content: space-evenly; }

    & + [tab] .dashboard {
        top: calc(var(--space-xl) * 1.85);
        border-bottom: 3px solid var(--light);
    }

    &:has(+ [tab="dashboard"].overflow-y:not([hidden])) {
        margin-bottom: 0;
    }

    & + [tab="dashboard"].overflow-y {
        padding-top: 0;

        > .dashboard {
            top: 0;
        }
    }
}

.dropdown {
    > button {
        &:focus { box-shadow: inset 0 0 0 1px var(--secondary); }
    }
    > [popover] {
        inline-size: anchor-size(width);
        max-height: 300px;
        margin-block: calc(var(--space-xs) / 2 );
        box-shadow: var(--shadow-md);
    }
}

.details {
    > summary {
        display: flex;
        gap: var(--space-md);
        align-items: center;
        padding: var(--space-sm);
        overflow: hidden;
        white-space: nowrap;
        cursor: pointer;
        border-left: 3px solid transparent;

        > span {
            flex: 1;
            font-size: var(--font-size-md);
            font-weight: 600;
            color: var(--black);
        }
        > aside {
            color: var(--dark);
        }
        &::-webkit-details-marker { display: none; }
        &::after {
            display: inline-block;
            width: var(--font-size-xl);
            height: var(--font-size-xl);
            content: "";
            background: center/contain no-repeat url(/static/images/icons/right-dark.svg), var(--white);
            border-radius: var(--radius-circle);
            box-shadow: var(--shadow-sm);
        }
        &:hover { background-color: color-mix(in srgb, var(--secondary) 10%, var(--white)); }
    }
    > section {
        height: 0;
        padding: var(--space-sm);
        padding-top: calc(var(--space-xs) / 2);
        opacity: 0;
        transition: height var(--transition-medium) ease,
                    opacity var(--transition-xslow) ease;
    }

    &:open {
        > summary {
            border-left: 3px solid var(--secondary);
            >:first-child {
                color: var(--secondary);
            }
            &::after {
                display: inline-block;
                width: var(--font-size-xl);
                height: var(--font-size-xl);
                content: "";
                background: center/contain no-repeat url(/static/images/icons/down.svg), var(--secondary);
                border-radius: var(--radius-circle);
                box-shadow: var(--shadow-sm);
            }
        }
        > section {
            height: calc-size(auto, size);
            opacity: 1;
        }
    }

    &:focus { box-shadow: inset 0 0 0 1px var(--secondary); }
}

.alert {
    z-index: var(--z-index-alert);
    display: flex;
    gap: var(--space-sm);
    align-items: center;

    padding: var(--space-sm);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);

    opacity: 1;
    translate: 0 0;
    transition: calc(var(--transition-slow) + calc(var(--stack_position) * var(--transition-fast))) ease;
    transition-behavior: allow-discrete;

    &.status-message {
        color: var(--black);
        background-color: var(--white);
        border: 2px solid var(--black);
    }

    --stack_position: attr(stack_position type(<integer>));

    @starting-style {
        opacity: 0;
        translate: 50% 0;
    }

    &.is-dismissing {
        pointer-events: none;
        opacity: 0;
        translate: 50% 0;
    }
}

.alert-stack {
    position: fixed;
    right: var(--space-md);
    bottom: var(--space-md);
    z-index: var(--z-index-alert);

    display: flex;
    flex-direction: column-reverse;
    gap: var(--space-xs);
    align-content: flex-end;
    align-items: flex-end;
}

.dialog-alert-stack {
    right: var(--space-md);
    bottom: var(--space-md);
    z-index: var(--z-index-alert);
}

.avatar {

    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: calc(2 * var(--space-md));
    aspect-ratio: 1 / 1;
    padding: 0;
    font-size: calc(1.25 * var(--font-size-md));
    font-weight: normal;
    vertical-align: middle;
    color: var(--white);
    appearance: none;

    cursor: pointer;
    background-color: var(--primary);
    border: 2px solid transparent;

    border-radius: var(--radius-circle);

    &:hover { z-index: var(--z-index-avatar); }

    &.white          { color: var(--dark); background-color: var(--white); border: 2px solid var(--light); }
    &.primary        { background-color: var(--primary); }
    &.secondary      { background-color: var(--secondary); }
    &.light          { background-color: var(--light); }
    &.dark           { background-color: var(--dark); }
    &.notification   { background-color: var(--info); }
    &.success        { background-color: var(--success); }
    &.warning        { background-color: var(--warning); }
    &.error          { background-color: var(--error); }

    &.xl {
        height: calc(2 * var(--space-xl));
        font-size: calc(1.25 * var(--font-size-xl));
    }
    &.lg {
        height: calc(2 * var(--space-lg));
        font-size: calc(1.25 * var(--font-size-lg));
    }
    &.md {
        height: calc(2 * var(--space-md));
        font-size: calc(1.25 * var(--font-size-md));
    }
    &.sm {
        height: calc(2 * var(--space-sm));
        font-size: calc(1.25 * var(--font-size-sm));
    }
    &.xs {
        height: calc(2 * var(--space-xs));
        font-size: calc(1.25 * var(--font-size-xs));
    }
    &.hero {
        height: 80px;
        font-size: 50px;
    }
    &.preview {
        height: 150px;
        font-size: 90px;
    }

    > span {

        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        height: 100%;
    }

    > img {
        display: block;
        width: 100%;
        height: 100%;
        object-fit: cover;
        border-radius: inherit;
    }
    &:has(> img) { background-color: transparent; }

    &.edit {
        &:hover {
            &::after {
                position: absolute;
                width: 80px;
                height: 80px;
                content: "";
                background-color: var(--primary);
                background-image: url(/static/images/icons/edit.svg);
                background-repeat: no-repeat;
                background-position: center;
                background-size: 50%;
                border-radius: var(--radius-circle);
            }
        }
    }
}

[popover].profile-popover {
    max-width: 400px;
    pointer-events: none;
    box-shadow: var(--shadow-lg);

    opacity: 0;
    transform: translateY(var(--space-xs));

    transition:
        opacity var(--transition-medium) ease,
        transform var(--transition-medium) ease,
        overlay var(--transition-medium) ease allow-discrete,
        display var(--transition-medium) ease allow-discrete;

    &:popover-open {
        pointer-events: auto;
        opacity: 1;
        transform: translateY(0);
    }

    @starting-style {
        &:popover-open {
            opacity: 0;
            transform: translateY(var(--space-xs));
        }
    }

    >.loading {
        gap: var(--space-sm);
        min-width: fit-content;
        padding: var(--space-md);
    }
}

.avatar-group {
    display: flex;
    align-items: center;
    margin-left: calc(0.8 * var(--space-xs));

    > .avatar {
        margin-left: calc(-0.8 * var(--space-xs));
        border: 2px solid var(--white);
    }
}

.notification {
    align-items: start;
    min-width: 0;
    background-color: var(--white);
    border: 2px solid var(--info);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);

    &.max-width {
        max-width: 500px;
    }

    &.seen {
        border-color: var(--light);
        > header {
            button:first-child {
                i {
                    color: var(--light);
                }
            }
        }
    }
}

.tag {
    padding: calc(var(--space-xs) / 2) var(--space-xs);
    font-size: var(--font-size-xs);
    cursor: default;
    border-radius: var(--radius-xs);
    &:not([class*="status-"]) {
        color: var(--white);
        background: var(--primary);
    }
    &.removable {
        cursor: pointer;
        &::after {
            margin-left: var(--space-xs);
            font-size: var(--font-size-sm);
            content: "×";
        }
    }
    &.anchor {
        cursor: pointer;
    }
}

[popover].tag-popover {
    box-sizing: border-box;
    inline-size: anchor-size(width);
    max-inline-size: calc(100vw - var(--space-md));
    padding: var(--space-xs);
}

.tag-options {
    display: block;
    field-sizing: content;
    box-sizing: border-box;
    width: 100%;
    appearance: auto;
    background-color: var(--white);
    color: var(--black);
    max-height: min(16rem, 50vh);
    overflow-y: auto;
    border: none;
    border-radius: var(--radius-xs);

    &:focus-visible { outline: 2px solid var(--secondary); }
    > option {
        padding: var(--space-xs) var(--space-md);
        &:checked { background-color: var(--secondary); color: var(--white); }
    }
}

.progressbar {
    display: flex;
    gap: var(--space-xs);
    align-items: center;
    width: 100%;
    min-width: 0;

    .progressbar-track {
        flex: 1;
        width: 100%;
        min-width: 0;
        height: 0.5rem;
        overflow: hidden;
        background-color: color-mix(in srgb, var(--light) 70%, var(--white));
        border-radius: 999px;
    }

    .progressbar-fill {
        width: 100%;
        height: 100%;
        background: color-mix(in srgb, var(--success) calc(var(--progress-value) * 100%), var(--info));
        border-radius: inherit;
        transform: scaleX(var(--progress-value));
        transform-origin: left center;
        transition: transform 550ms cubic-bezier(0.22, 1, 0.36, 1);
        will-change: transform;
    }

    .progressbar-label {
        min-width: 3rem;
        font-size: var(--font-size-sm);
        color: var(--dark);
        text-align: right;
    }
}

.job {
    display: flex;
    flex-direction: column;
    min-width: 450px;
    padding: calc(0.5 * var(--space-xs)) var(--space-sm);
    background-color: var(--white);
    border: 2px solid var(--light);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);

    .result {
        background-color: color-mix(in srgb, var(--light) 70%, var(--white));
        border-radius: var(--radius-sm);

        pre {
            padding: var(--space-xs);
            margin: 0;
            font-family: 'Roboto Mono', ui-monospace, SFMono-Regular, Consolas, monospace;
            font-size: var(--font-size-sm);
            word-break: break-word;
            white-space: pre-wrap;
        }

        &.error {
            background-color: color-mix(in srgb, var(--error) 10%, var(--white));
            border-color: var(--error);
        }
    }

    > footer {
        display: flex;
        flex-direction: column;
        gap: var(--space-xs);
    }
}

[popover].actions {
    inset: auto;
    top: anchor(bottom);
    right: anchor(right);
    padding: 0;
    margin-block: calc(var(--space-xs) / 2);
    position-try-fallbacks: --bottom-right, --bottom-left, --top-left, --top-right;
    box-shadow: var(--shadow-md);

    &:popover-open {
        display: block;
    }

    nav > .item {
        flex: 1;
    }
}

@position-try --bottom-right {
    inset: auto;
    top: anchor(bottom);
    right: anchor(right);
}

@position-try --bottom-left {
    inset: auto;
    top: anchor(bottom);
    left: anchor(left);
}

@position-try --top-right {
    inset: auto;
    right: anchor(right);
    bottom: anchor(top);
}

@position-try --top-left {
    inset: auto;
    bottom: anchor(top);
    left: anchor(left);
}

@position-try --bottom {
    inset: auto;
    top: anchor(bottom);
}

@position-try --top {
    inset: auto;
    bottom: anchor(top);
}