/* Funding types without matching programs (design C3: 50% opacity) */
.no-filter-match {
    opacity: .5;
}

/* Internal programs are the filtered items themselves, items without match are hidden (no design yet) */
.list__item--internalprogram.no-filter-match {
    display: none;
}


/* Container of the panel: it takes the width of the filter bar on small widths (see below) */
#filter__wrapper {
    container: filter / inline-size;

    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;

    padding-bottom: var(--layout--gap--default);
}

#filter__toggle {
    position: relative;
    z-index: 2;
    font-weight: bold;
}

/* Open: the toggle is part of the panel, without border and hover fill of the button */
#filter__toggle[aria-expanded="true"] {
    border-color: transparent;
    background-color: transparent;
    color: inherit;
}

#filter__toggle[aria-expanded="true"] > .btn--icon--open {
    --btn--icon--image: var(--icon--close);
}


/* Selected categories: wrap onto several lines, the toggle keeps its place at the top right */
.filter__tags {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem 1rem;
    flex: 1 1 auto;
    min-width: 0;

    /* A list for screen readers (number of active filters), without list styles */
    list-style: none;
    margin: 0;
    padding: 0;
}

/* As wide as its tag, only labels longer than the whole line wrap (then the tag grows in height) */
.filter__tags > li {
    display: flex;
    flex: 0 1 auto;
    min-width: 0;
    max-width: 100%;
}

.filter__tag {
    flex: 0 1 auto;
    max-height: none;
    text-align: left;
}

.filter__flyout--wrapper {
    position: relative;
    flex: 0 0 auto;
    margin-left: auto;
}


/*
 * Panel (disclosure, a <div> with the hidden attribute, see Components/Disclosure.js), anchored to the top right corner of the toggle (the toggle sits in the
 * panel's padding corner) and unfolds from there to the left and downwards.
 *
 * Mobile first: as wide as the filter bar (the toggle is at its right end), so it never leaves the viewport,
 * the fieldsets one below the other. From 48rem filter bar width on 60vw at most, from 36rem panel width on
 * the fieldsets side by side (container "filter-panel").
 */
#filter__panel {
    --panel--padding : 1rem;
    --panel--width   : calc(100cqi + var(--panel--padding) + 2 * var(--panel--border));
    --panel--border  : 1px;
    --panel--radius  : 10px;
    --panel--duration: .3s;

    /*
     * Collapsed into the top right corner. Open, the clip lies 1px outside the border box: clipping exactly
     * on the outer edge cuts the bottom border at fractional pixel positions (panel height is not an integer).
     */
    --panel--clip--closed: inset(0 0 100% 100% round var(--panel--radius));
    --panel--clip--open  : inset(-1px round calc(var(--panel--radius) + 1px));

    position: absolute;
    inset: auto;
    top  : calc(0px - calc(var(--panel--padding) / 2) - var(--panel--border));
    right: calc(0px - calc(var(--panel--padding) / 2) - var(--panel--border));
    margin: 0;

    width: var(--panel--width);
    max-width: none;

    background: var(--color--primary);
    color: inherit;

    border: var(--panel--border) solid var(--color--secondary);
    border-radius: var(--panel--radius);
    padding: var(--panel--padding);

    z-index: 1;

    display: block;
    clip-path: var(--panel--clip--closed);
    transition:
        clip-path var(--panel--duration) ease-in-out,
        display   var(--panel--duration) allow-discrete;
}

/* Closed: display none after the transition, the author display above overrides the UA rule */
#filter__panel[hidden] {
    display: none;
}

#filter__panel:not([hidden]) {
    clip-path: var(--panel--clip--open);
}

@starting-style {
    #filter__panel:not([hidden]) {
        clip-path: var(--panel--clip--closed);
    }
}

@container filter (min-width: 48rem) {
    #filter__panel {
        --panel--padding: 2rem;
        --panel--width  : min(60vw, 100cqi + var(--panel--padding) + 2 * var(--panel--border));
    }
}

@media (prefers-reduced-motion: reduce) {
    #filter__panel {
        transition: none;
    }
}

/* Keeps the first row of options clear of the toggle */
.filter__content {
    container: filter-panel / inline-size;
    margin-top: 1rem
}

.filter__options {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

@container filter-panel (min-width: 36rem) {
    .filter__options {
        flex-direction: row;
    }
}

.filter__options fieldset {
    border: unset;
    flex: 1;
}
/* Legend like the title of the funding type cards (h3), the options like their text (small text) */
.filter__options fieldset legend {
    margin-bottom: var(--layout--gap--small);
    font-size: var(--font-size--h3);
    font-weight: var(--font-weight--bold);
    line-height: var(--line-height--sub-headline);
}

.filter__option--category--item {
    --filter--check-size: calc(var(--target) / 2);

    position: relative;
    padding-top: .5rem;
}

/* The native input is hidden visually, it stays focusable and is drawn by the label (see below) */
.filter__option--category--item input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.filter__option--category--item input ~ label {
    display: flex;
    gap: var(--space--xs);
    font-size: var(--font-size--text-small);
    line-height: var(--line-height--text-small);
    cursor: pointer;
}

/* Circle centered on the first line of the label (1lh), long labels wrap next to it */
.filter__option--category--item input ~ label::before {
    content: "";
    flex-shrink: 0;
    width: var(--filter--check-size);
    height: var(--filter--check-size);
    margin-top: calc((1lh - var(--filter--check-size)) / 2);
    border: var(--border-width--default) solid var(--color--secondary);
    border-radius: 100%;
}

.filter__option--category--item input:checked ~ label::before {
    background: var(--color--secondary);
}

.filter__option--category--item input:focus-visible ~ label::before {
    outline: var(--outline-width--default) solid var(--color--secondary);
    outline-offset: var(--outline-offset--default);
}

/* The filled circle is a background, keep it in forced colors mode */
@media (forced-colors: active) {
    .filter__option--category--item input:checked ~ label::before {
        forced-color-adjust: none;
        background: CanvasText;
    }
}

/* Results and actions wrap on small widths */
.filter__footer {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: space-between;
    align-items : center;
    border-top: 1px solid var(--color--secondary);

    padding-top: 2rem;
    margin-top: 2rem;
}

.filter__results {
    font-weight: bold;
}

.filter__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}