/*
 * Luccy CMS — neutral base styles of public dynamic forms (luccy-form__*, Luccy.Site.Core).
 * Plain CSS (no SCSS pipeline in Site.Core). Low specificity (:where) so a site restyles it with its own CSS or
 * replaces the wrapper partials (~/Views/Shared/DynamicForms/{SiteKey}/_X.cshtml). Theme through the custom
 * properties below. Half / third / two-thirds fields sit side by side in a 6-column grid and stack on narrow forms.
 */
:where(.luccy-form) {
    --lf-gap: 1rem;
    --lf-radius: 6px;
    --lf-border: #c4c9d0;
    --lf-border-focus: #2f6fdb;
    --lf-text-muted: #5b6470;
    --lf-error: #c62828;
    --lf-error-bg: #fdecec;
    --lf-success: #1e7a3c;
    --lf-success-bg: #e8f5ec;
    --lf-input-bg: #fff;

    container-type: inline-size;
    display: grid;
    gap: var(--lf-gap);
    position: relative;
}

:where(.luccy-form__group) {
    border: 0;
    margin: 0;
    padding: 0;
    min-width: 0;
}

:where(.luccy-form__legend) {
    font-weight: 600;
    font-size: 1.125em;
    margin-bottom: .5rem;
    padding: 0;
}

:where(.luccy-form__description, .luccy-form__group-description) {
    margin: 0 0 .75rem;
    color: var(--lf-text-muted);
}

:where(.luccy-form__grid) {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: var(--lf-gap);
}

:where(.luccy-form__field) {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    gap: .35rem;
    min-width: 0;
}

:where(.luccy-form__field--half) {
    grid-column: span 3;
}

:where(.luccy-form__field--third) {
    grid-column: span 2;
}

:where(.luccy-form__field--two-thirds) {
    grid-column: span 4;
}

@container (max-width: 560px) {
    :where(.luccy-form__field--half, .luccy-form__field--third, .luccy-form__field--two-thirds) {
        grid-column: 1 / -1;
    }
}

@supports not (container-type: inline-size) {
    @media (max-width: 600px) {
        :where(.luccy-form__field--half, .luccy-form__field--third, .luccy-form__field--two-thirds) {
            grid-column: 1 / -1;
        }
    }
}

:where(.luccy-form__label) {
    font-weight: 500;
    padding: 0;
}

:where(.luccy-form__required) {
    color: var(--lf-error);
}

:where(.luccy-form__input) {
    box-sizing: border-box;
    width: 100%;
    padding: .6rem .75rem;
    border: 1px solid var(--lf-border);
    border-radius: var(--lf-radius);
    background: var(--lf-input-bg);
    color: inherit;
    font: inherit;
}

:where(.luccy-form__textarea) {
    resize: vertical;
}

:where(.luccy-form__input:focus-visible, .luccy-form__check-input:focus-visible, .luccy-form__choice-input:focus-visible) {
    outline: 2px solid var(--lf-border-focus);
    outline-offset: 1px;
}

:where(.luccy-form__input-group) {
    display: flex;
    align-items: center;
    gap: .5rem;
}

:where(.luccy-form__unit) {
    color: var(--lf-text-muted);
    white-space: nowrap;
}

:where(.luccy-form__file) {
    padding: .45rem;
}

:where(.luccy-form__help, .luccy-form__file-limit) {
    margin: 0;
    font-size: .875em;
    color: var(--lf-text-muted);
}

/* checkbox / consent */
:where(.luccy-form__check) {
    display: flex;
    align-items: flex-start;
    gap: .5rem;
    cursor: pointer;
}

:where(.luccy-form__check-input, .luccy-form__choice-input) {
    margin: .2em 0 0;
    flex: none;
}

:where(.luccy-form__consent-link) {
    color: inherit;
    text-decoration: underline;
}

/* radio: list (default) or buttons */
:where(.luccy-form__choices) {
    border: 0;
    margin: 0;
    padding: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: .4rem;
}

:where(.luccy-form__choices > .luccy-form__label) {
    margin-bottom: .2rem;
}

:where(.luccy-form__choice) {
    display: flex;
    align-items: flex-start;
    gap: .5rem;
    cursor: pointer;
}

:where(.luccy-form__choices--buttons) {
    flex-direction: row;
    flex-wrap: wrap;
}

:where(.luccy-form__choices--buttons > .luccy-form__label) {
    flex-basis: 100%;
}

:where(.luccy-form__choices--buttons .luccy-form__choice) {
    position: relative;
    padding: .5rem .9rem;
    border: 1px solid var(--lf-border);
    border-radius: var(--lf-radius);
}

:where(.luccy-form__choices--buttons .luccy-form__choice-input) {
    position: absolute;
    opacity: 0;
    inset: 0;
    margin: 0;
    cursor: pointer;
}

:where(.luccy-form__choices--buttons .luccy-form__choice:has(:checked)) {
    border-color: var(--lf-border-focus);
    box-shadow: inset 0 0 0 1px var(--lf-border-focus);
}

:where(.luccy-form__choices--buttons .luccy-form__choice:has(:focus-visible)) {
    outline: 2px solid var(--lf-border-focus);
    outline-offset: 1px;
}

/* errors: the server / JS state (--invalid) and the browser state after the visitor touched the field */
:where(.luccy-form__error) {
    color: var(--lf-error);
    font-size: .875em;
}

:where(.luccy-form__error:empty) {
    display: none;
}

:where(.luccy-form__field--invalid) :where(.luccy-form__input),
:where(.luccy-form__input:user-invalid) {
    border-color: var(--lf-error);
}

/* status message */
:where(.luccy-form__status) {
    padding: .75rem 1rem;
    border-radius: var(--lf-radius);
}

:where(.luccy-form__status[hidden]) {
    display: none;
}

:where(.luccy-form__status--success) {
    color: var(--lf-success);
    background: var(--lf-success-bg);
}

:where(.luccy-form__status--error) {
    color: var(--lf-error);
    background: var(--lf-error-bg);
}

:where(.luccy-form__captcha:empty) {
    display: none;
}

/* submit + busy state */
:where(.luccy-form__actions) {
    display: flex;
    justify-content: flex-start;
}

:where(.luccy-form__submit) {
    padding: .7rem 1.5rem;
    border: 0;
    border-radius: var(--lf-radius);
    background: var(--lf-border-focus);
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

:where(.luccy-form__submit:disabled) {
    opacity: .6;
    cursor: progress;
}

:where(.luccy-form--busy) {
    cursor: progress;
}

:where(.luccy-form--busy .luccy-form__submit)::after {
    content: "";
    display: inline-block;
    width: .9em;
    height: .9em;
    margin-left: .5em;
    vertical-align: -.1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: luccy-form-spin .8s linear infinite;
}

@keyframes luccy-form-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    :where(.luccy-form--busy .luccy-form__submit)::after {
        animation: none;
    }
}
