@import "shared/mixins-and-vars";

/* This is the CSS to style the custom HTML5 checkbox */
.enable-checkbox {
    @width-checkbox: 16;
    width: fit-content;
    margin: 0 auto;

    .form-control {
        font-family: system-ui, sans-serif;
        font-size: (16 / @px);
        font-weight: bold;
        line-height: 1.1;
        display: grid;
        grid-template-columns: 1em auto;
        gap: 0.5em;
    }

    .form-control + .form-control {
        margin-top: 1em;
    }

    .form-control--disabled {
        color: var(--form-control-disabled);
        cursor: not-allowed;
    }

    input[type="checkbox"] {
        .vendor(appearance, none);
        /* For iOS < 15 */
        background-color: var(--form-background);
        /* Not removed via appearance */
        margin: 0;

        font: inherit;
        color: currentColor;
        width: 1.15em;
        height: 1.15em;
        border: 0.15em solid currentColor;
        border-radius: 0.15em;
        transform: translateY(-0.075em);

        display: grid;
        place-content: center;

        .enable-focus(
      {
        outline: ~"max(2px, 0.15em)" solid @focus-color;
        outline-offset: ~"max(2px, 0.15em)";
      },
      {
        outline: none;
        outline-offset: 0;
      }
    );

        &::before {
            content: "";
            width: 0.65em;
            height: 0.65em;
            clip-path: polygon(
                14% 44%,
                0 65%,
                50% 100%,
                100% 16%,
                80% 0%,
                43% 62%
            );
            transform: scale(0);
            transform-origin: bottom left;
            transition: 120ms transform ease-in-out;
            box-shadow: inset 1em 1em var(--form-control-color);
            /* Windows High Contrast Mode */
            background-color: CanvasText;

            .enable__is-dark-mode & {
                filter: invert(100%);
            }
        }

        &:indeterminate::before {
            clip-path: polygon(0% 40%, 100% 40%, 100% 60%, 0% 60%);
            transform: scale(1);
        }

        &:checked::before {
            transform: scale(1);
        }

        &:disabled {
            --form-control-color: var(--form-control-disabled);

            color: var(--form-control-disabled);
            cursor: not-allowed;
        }
    }
}

#html-checkbox-multi-label {
    border-bottom: solid 3px black;
    text-align: center;
}

#html-checkbox__error {
    display: none;

    &.visible {
        display: block;
        margin: 10px auto;
    }
}

#group-example,
#indeterminate-example {
    legend {
        width: 100%;
        text-align: center;
        border-bottom: 3px solid black;
    }

    .checkbox-container {
        display: block;
        width: fit-content;
        margin: 0 auto;
        position: relative;

        input {
            position: absolute;
            left: 0;
        }

        label {
            width: 190px;
            margin-bottom: 10px;
            padding-left: (30 / @px);
            grid-template-columns: initial;
        }
    }

    .error {
        display: block;
        width: fit-content;
        margin: 0 auto 1em auto;
    }

    button {
        margin: 10px auto;
        text-align: center;
        display: block;
    }
}

#aria-indeterminate-example {
    label {
        display: inline;
    }

    .checkbox-container {
        min-width: 190px;
        list-style-type: none;
    }
}
