/*
 * ful 9 compatibility.
 *
 * ful 9 ships every rule in the ful.* cascade layers and no longer derives its theme from bootstrap:
 * the unlayered bootstrap reboot (label, legend, ...) now wins over it. ful 6 shipped these rules
 * unlayered, right after bootstrap and before the page styles, which are written against them:
 * this file restores them, loaded where ful 6 css was.
 */

:root {
    --ful-color: var(--bs-body-color, #212529);
    --ful-bg: var(--bs-body-bg, #fff);
    --ful-border-width: var(--bs-border-width, 1px);
    --ful-border-radius: var(--bs-border-radius, 0.375rem);
    --ful-border-color: var(--bs-border-color, #dee2e6);
    --ful-disabled-bg: var(--bs-secondary-bg, #e9ecef);
    --ful-selected-bg: var(--bs-tertiary-bg, #f8f9fa);
    --ful-active-color: #fff;
    --ful-active-bg: #007376;
    --ful-accent-ink: var(--ful-active-bg);
    --ful-focus-border-color: #86b7fe;
    --ful-focus-box-shadow: 0 0 0 .25rem rgba(13, 110, 253, .25);
    --ful-invalid-color: var(--bs-form-invalid-color, #dc3545);
    --ful-invalid-border-color: var(--bs-form-invalid-border-color, #dc3545);
    --ful-invalid-box-shadow: 0 0 0 .25rem rgba(var(--bs-danger-rgb), .25);
    --ful-error-color: var(--bs-danger-text-emphasis, #58151c);
    --ful-error-bg: var(--bs-danger-bg-subtle, #f8d7da);
    --ful-error-border-color: var(--bs-danger-border-subtle, #f1aeb5);
    --ful-warning-color: var(--bs-warning-text-emphasis, #664d03);
    --ful-warning-bg: var(--bs-warning-bg-subtle, #fff3cd);
    --ful-warning-border-color: var(--bs-warning-border-subtle, #ffe69c);
}

[hidden] {
    display: none !important;
}

ful-control-group.input-group {
    /* the bootstrap .input-group/.form-control chrome is the one painted */
    color: inherit;
    border: 0;
    border-radius: 0;
    background-color: transparent;
    box-shadow: none;
    & > :is(input, textarea) {
        min-height: auto;
    }
}

/* ful 9 makes every host of a ful-control-group a block, ful 6 left the custom ones alone */
ca-input-pattern {
    display: inline;
}

/* as ful 6 wrote them: the :is() carries the specificity of a class */
:is(.ful-input, ful-input) {
    display: block;
    &[required] > .form-label > label::before {
        content: "* ";
        display: inline;
        font-weight: 700;
    }
    & input:focus,
    & textarea:focus {
        border-color: var(--ful-focus-border-color);
        box-shadow: var(--ful-focus-box-shadow);
    }
    &:invalid input,
    &:invalid textarea {
        background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23dc3545'%3E%3Ccircle cx='6' cy='6' r='4.5'/%3E%3Cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3E%3Ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3E%3C/svg%3E");
        background-position: right calc(.375em + .1875rem) center;
        background-repeat: no-repeat;
        background-size: calc(.75em + .375rem) calc(.75em + .375rem);
        border-color: var(--ful-invalid-border-color);
        padding-right: calc(1.5em + .75rem);
    }
    &:invalid input:focus,
    &:invalid textarea:focus {
        border-color: var(--ful-invalid-border-color);
        box-shadow: var(--ful-invalid-box-shadow);
    }
}

ful-field-error {
    font-size: inherit;
}

ful-radio-group {
    display: block;
    &[required] > fieldset > legend::before {
        color: var(--ful-color);
        content: "* ";
        display: inline;
        font-weight: 700;
    }
    & > fieldset {
        & > legend {
            font-size: 16px;
            /* ful 6 legend carried bootstrap .form-label */
            margin: 0 0 .5rem 0;
        }
        & > ful-radio-list {
            display: grid;
            gap: 10px;
            grid-template-columns: 1fr;
            & label {
                align-items: center;
                background-color: var(--ful-radio-group-label-bg);
                border: 1px solid var(--ful-radio-group-label-border-color);
                border-radius: 4px;
                cursor: pointer;
                display: flex;
                height: 100%;
                padding: 8px 10px;
                & > div {
                    flex: 1;
                }
            }
            & label:has(input[type=radio]:checked) {
                background-color: var(--ful-radio-group-label-checked-bg);
                border-color: var(--ful-radio-group-label-checked-border-color);
            }
            & label:has(input[type=radio]:disabled) {
                background-color: var(--ful-radio-group-label-disabled-bg);
                border-color: var(--ful-radio-group-label-disabled-border-color);
            }
            /* ful 9 moves the keyboard focus ring from the radio to its label */
            & input[type=radio]:focus-visible {
                outline: revert;
            }
            & label:has(input[type=radio]:focus-visible) {
                box-shadow: none;
            }
            & input[type=radio] {
                accent-color: var(--ful-radio-group-label-checked-border-color);
                height: 16px;
                margin-left: 8px;
                margin-right: 12px;
                vertical-align: text-bottom;
                width: 16px;
            }
        }
    }
    &.horizontal > fieldset > ful-radio-list {
        gap: 16px;
        grid-template-columns: 1fr 1fr;
    }
    &:invalid > fieldset > ful-radio-list label {
        border-color: var(--ful-radio-group-active-bg);
    }
}

/* ful-select is the tom-select based OldSelect (webc.js): ful 6 select rules it was styled by */
ful-select {
    cursor: pointer;
    display: block;
    & input {
        background-color: transparent;
        border: 0;
        flex: 1 1 auto;
        line-height: 1.5;
        margin: 0;
        min-width: 1em;
        outline: 0;
        padding: .375rem 0 .375rem 7px;
        width: 1em;
    }
}

/* the page's margin on every form child would pull the backdrop card off the centre: :root outweighs motor.css */
:root ful-spinner.backdrop {
    margin: auto;
}

/* while submitting ful 9 holds off every submit button: ful 6 only disabled the ones with an explicit type */
ful-form button:not([type])[aria-disabled=true] {
    opacity: 1;
    cursor: pointer;
}
