#pf2e-hud-sidebar {
    --min-width: 14em;
    --min-height: 4em;
    --max-heigth: var(var(--min-height));

    --nb-columns: 1;
    --max-column-width: 17em;

    --item-gap: 0.2em;
    --item-spacing: 0.3em;
    --item-image-height: 2.6em;
    --item-image-border-color: rgb(118 118 118);
    --item-name-padding: 0.2em;
    --item-name-background: rgba(255, 255, 255, 0.09);
    --item-chat-icon-size: 1.6em;

    --temporary-color: #ff8f00;

    --hud-input-color: #433a45;
    --hud-input-checked-color: #cdc9c3;

    --hud-font-size: var(--font-size-14);

    --statistic-background-hover: #ffffff0f;

    --variant-font-size: var(--font-size-12);
    --variant-background: #ffffff17;
    --variant-background-hover: transparent;
    --variant-background-selected: #b1b0ac;
    --variant-box-shadow-color: #4d4840;
    --variant-box-shadow: inset 0 0 0 1px var(--variant-box-shadow-color);
    --variant-box-shadow-selected: inset 0 0 3px 0px black;
    --variant-color: var(--color);
    --variant-color-hover: var(--color-highlight);
    --variant-color-selected: var(--color-reversed);
    --variant-gap: 2px;

    --input-checkbox-width: 1.7em;

    --action-image-height: 1.8em;

    position: absolute;
    padding: var(--sidebar-external-padding);
    // max-height: 100vh;
    max-width: 100vw;
    pointer-events: none;

    input[type="checkbox"] {
        height: 1.3em;
        width: var(--input-checkbox-width);
        margin: 0;

        &::after {
            font-size: 1.7em;
        }

        &:not(:checked) {
            display: flex;
            justify-content: center;

            &::before {
                color: var(--hud-input-color);
            }
        }

        &:checked {
            &::after {
                color: var(--color);
            }
        }
    }

    select {
        --input-background-color: var(--hud-input-color);

        height: 1.5em;
        border: none;
        border-radius: 2px;
        color: var(--color);
        padding-inline: 0;

        &:focus {
            --input-focus-outline-color: var(--color-cool-3);
        }
    }

    img.drag-img {
        width: 0;
        height: 0;
        border: 0;
        margin: 0;
        padding: 0;
        position: absolute;
    }

    *:has(> .name) {
        overflow: hidden;

        .name {
            overflow: hidden;
            text-overflow: ellipsis;
        }
    }

    .inner,
    [data-panel="filter"],
    [data-panel="sidebars"] {
        border: var(--outer-border);
        box-shadow: var(--outer-box-shadow);
        background: var(--outer-background);
        border-radius: var(--outer-border-radius);
    }

    .inner {
        overflow: auto;
        padding: var(--outer-padding);
        min-width: var(--min-width);
        min-height: var(--min-height);
        max-width: calc(100vw - var(--sidebar-external-padding) * 2);
        max-height: calc(var(--max-height) - var(--sidebar-external-padding) * 2);

        &:has(.filtered) {
            [data-filter-value]:not(.filtered) {
                filter: grayscale(1) opacity(0.2);
            }
        }
    }

    [data-panel="filter"] {
        position: absolute;
        bottom: -5px; // do not change that, it is hardcoded
        left: 50%;
        transform: translate(-50%, calc(100% - var(--sidebar-external-padding)));
        width: calc(100% - var(--sidebar-external-padding) * 2);
        padding: 10px;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;

        input {
            border: 1px solid #5d5d5d;
        }

        &.visible {
            opacity: 1;
            visibility: visible;
        }
    }

    [data-panel="sidebars"] {
        z-index: -1;
        position: absolute;

        top: 50%;
        left: 1px;
        transform: translateY(-50%);
        height: auto;
        width: 50px;
        display: grid;
        gap: 0.45em;
        grid-template-rows: repeat(5, 1fr);
        padding: 5px 2px;

        &.top {
            top: 1px;
            left: 50%;
            transform: translateX(-50%);
            height: 50px;
            width: auto;
            grid-template-columns: repeat(5, 1fr);
            grid-template-rows: none;
            justify-items: center;
            padding: 3px 5px;
        }
    }

    .item-list {
        white-space: nowrap;
        column-gap: var(--outer-padding);
        columns: var(--nb-columns);

        > * {
            break-inside: avoid;
        }
    }

    .option-toggles {
        display: flex;
        flex-direction: column;
        margin: 0;
        padding: 0;

        li {
            margin: 0;
            flex: 1;

            label {
                --row-gap: 0.1em;

                display: flex;
                flex-wrap: wrap;
                row-gap: 0.2em;
                column-gap: var(--row-gap);
                flex: 1;
                overflow: hidden;

                span {
                    margin-top: 1px;
                    max-width: calc(
                        var(--max-column-width) - var(--input-checkbox-width) - var(--row-gap)
                    );
                    overflow: hidden;
                    text-overflow: ellipsis;
                }

                &:has(input.hidden) {
                    span {
                        max-width: var(--max-column-width);
                    }
                }
            }

            select {
                padding-inline: 4px;
                flex: 1 1 var(--max-column-width);

                &:disabled {
                    display: none;
                }
            }
        }
    }

    header {
        .controls {
            position: absolute;
            inset: 0 0.2em 0 auto;
            display: flex;
            align-items: center;
            gap: 0.3em;

            &.left {
                inset: 0 auto 0 0.2em;
            }
        }

        .item {
            min-width: auto;

            &:not(:first-child) {
                margin-top: 0;
            }
        }

        &:not(:first-child) {
            margin-top: 0.6em;
        }
    }

    .item {
        display: flex;
        min-width: var(--min-width);
        max-width: var(--max-column-width);

        .details {
            flex: 1;
            display: grid;
            grid-template-rows: 1fr 1fr;
            gap: 0.1em;

            .extras {
                display: flex;
                justify-content: space-between;
                gap: 1em;
                font-size: 0.9em;

                > * {
                    display: flex;
                    align-items: center;
                }
            }
        }

        .name {
            background-color: var(--item-name-background);
            padding-inline: var(--item-name-padding);
        }

        .image {
            position: relative;
            height: var(--item-image-height);
            aspect-ratio: 1 / 1;
            border: 1px solid var(--item-image-border-color);
            border-radius: var(--outer-border-radius);
            margin-right: var(--item-gap);
            cursor: pointer;

            img {
                width: revert;
                height: revert;
                position: revert;
                border-radius: var(--outer-border-radius);
                border: none;
            }

            i {
                position: absolute;

                &.chat {
                    font-size: var(--item-chat-icon-size);
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    inset: 0;
                    width: unset;
                }

                &.flagged,
                &.temporary {
                    color: var(--temporary-color);
                    text-shadow: 0.05em 0 black, 0 0.05em black, -0.05em 0 black, 0 -0.05em black,
                        -0.05em -0.05em black, -0.05em 0.05em black, 0.05em -0.05em black,
                        0.05em 0.05em black;
                }

                &.flagged {
                    bottom: 0;
                    right: -0.5em;
                }

                &.temporary {
                    bottom: 0;
                    left: -0.5em;
                }
            }

            &:not(:hover) {
                i.chat {
                    display: none;
                }
            }

            &:hover {
                img,
                i.temporary {
                    opacity: 0;
                }
            }
        }

        &.action,
        &.feat,
        &.statistic,
        &.option-toggle {
            --item-name-background: transparent;
        }

        &.action,
        &.feat,
        &.statistic {
            --item-chat-icon-size: 1em;

            align-items: center;

            .image {
                height: var(--action-image-height);
            }

            .name {
                flex: 1;
            }

            .controls {
                display: flex;
                align-items: center;
                gap: 0.2em;
            }
        }

        &.statistic {
            .name {
                .action-glyph {
                    font-size: 0.9em;
                }
            }

            .controls {
                display: none;
                align-items: center;
                gap: 0.3em;
            }

            &:not(.proficient) {
                .image {
                    filter: grayscale(1) contrast(0.7);
                }

                .name {
                    color: var(--color-disabled);
                }
            }
        }

        &:not(:first-child) {
            margin-top: var(--item-spacing);
        }
    }

    .statistic-wrapper {
        margin-top: var(--item-spacing);

        .variants {
            margin-top: 0.2em;
            padding-left: 0.1em;
        }

        &:hover {
            .item.statistic {
                .controls {
                    display: flex;
                }
            }
        }
    }

    .item .variants,
    .item + .variants {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: var(--variant-gap);
        color: var(--variant-color);
        min-width: var(--min-width);
        max-width: var(--max-column-width);

        .variant {
            font-size: var(--variant-font-size);
            text-rendering: optimizeLegibility;
            text-transform: uppercase;
            background: var(--variant-background);
            border-radius: 2px;
            box-shadow: var(--variant-box-shadow);
            display: flex;
            border: none;
            flex: 0;
            gap: 0.2em;
            white-space: nowrap;
            height: 1.584em;
            padding: 1px 3px 0;
            align-items: center;

            &[data-action] {
                cursor: pointer;

                &:hover {
                    background: var(--variant-background-hover);
                    color: var(--variant-color-hover);
                }
            }

            &.selected {
                cursor: revert;
                background: var(--variant-background-selected);
                color: var(--variant-color-selected);
                box-shadow: var(--variant-box-shadow-selected);
            }
        }
    }

    .item .variants {
        margin-top: 2px;
    }

    &:not(.pf2e-hud-fadeout) {
        .inner,
        [data-panel="filter"],
        [data-panel="sidebars"] {
            pointer-events: all;
        }

        [data-panel="filter"] {
            &.visible {
                pointer-events: all;
            }
        }
    }
}

#pf2e-hud-sidebar[data-hud="token"] {
    --sidebar-external-padding: 1.8em;
}

@import "./actions";
@import "./extras";
@import "./feats";
@import "./items";
@import "./skills";
@import "./spells";
