:root {
    --bth-chk-size: 16px;
    --bth-chk-border: #bfbfc0;
    --bth-chk-border-hover: #8f8f91;
    --bth-chk-on: #3374db; /* azul Betha */
    --bth-chk-on-disabled: #a9c3ee;
    --bth-chk-focus: rgba(51, 116, 219, .25);
    --bth-chk-spring: cubic-bezier(.22, 1.2, .36, 1);
    --bth-chk-fill-time: .22s; /* tempo do preenchimento; o check começa logo depois */
    --bth-chk-mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E");
    --bth-chk-dash: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round'%3E%3Cpath d='M6 12h12'/%3E%3C/svg%3E");
}

input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *)) {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    position: relative;
    display: inline-block;
    flex-shrink: 0;
    width: var(--bth-chk-size);
    height: var(--bth-chk-size);
    vertical-align: -3px;
    background-color: #fff;
    background-image: none;
    border: 1.5px solid var(--bth-chk-border);
    border-radius: 4px;
    box-shadow: none;
    cursor: pointer;
    transition: border-color .15s ease, box-shadow .15s ease, transform .3s var(--bth-chk-spring);
}

    /* Preenchimento nasce como um ponto no centro e cresce até ocupar a caixa */
    input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *))::before {
        content: "";
        position: absolute;
        inset: 0;
        background: var(--bth-chk-on);
        border-radius: 50%;
        transform: scale(0);
        transition: transform .16s ease-in .06s, border-radius .16s ease .06s;
    }

    input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *))::after {
        content: "";
        position: absolute;
        inset: -1.5px;
        background: var(--bth-chk-mark) center / 100% 100% no-repeat;
        clip-path: inset(0 100% 0 0);
        transition: clip-path .08s ease-in;
    }

    input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *)):hover:not(:disabled):not(:checked):not(:indeterminate) {
        border-color: var(--bth-chk-border-hover);
    }

    input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *)):focus {
        outline: 0;
    }

    input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *)):focus-visible {
        box-shadow: 0 0 0 3px var(--bth-chk-focus);
    }

    input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *)):active:not(:disabled) {
        transform: scale(.86);
        transition-duration: .15s, .15s, .08s;
    }

    /* Marcado / indeterminado */
    input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *)):checked,
    input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *)):indeterminate {
        border-color: var(--bth-chk-on);
    }

        input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *)):checked::before,
        input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *)):indeterminate::before {
            transform: scale(1);
            border-radius: 1px;
            transition: transform var(--bth-chk-fill-time) var(--bth-chk-spring), border-radius var(--bth-chk-fill-time) ease;
        }

        /* O check só começa quando o preenchimento termina */
        input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *)):checked::after,
        input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *)):indeterminate::after {
            clip-path: inset(0 0 0 0);
            transition: clip-path .28s cubic-bezier(.65, 0, .35, 1) var(--bth-chk-fill-time);
        }

        /* Indeterminado (ex.: "selecionar todos" parcial do Tabulator) */
        input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *)):indeterminate::after {
            background-image: var(--bth-chk-dash);
        }

    /* Desabilitado */
    input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *)):disabled {
        background-color: #ededed;
        border-color: #d4d4d5;
        cursor: not-allowed;
    }

        input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *)):disabled:checked,
        input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *)):disabled:indeterminate {
            border-color: var(--bth-chk-on-disabled);
        }

        input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *)):disabled::before {
            background: var(--bth-chk-on-disabled);
        }

/* Erro de validação */
.bth-field-error input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *)):not(:checked) {
    border-color: #dd413c;
}

@media (prefers-reduced-motion: reduce) {
    input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *)),
    input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *))::before,
    input[type="checkbox"]:where(:not([data-bth-native]):not([role="switch"]):not(.form-switch *))::after {
        transition: none !important;
    }
}
