.lib-root .mt-list-header {
    grid-template-areas:
        "title title"
        "search filter";
    grid-template-columns: 1fr auto;
    row-gap: 12px;
    column-gap: 12px;
    align-items: center;
}

.lib-root .mt-list-title {
    grid-area: title;
}

.lib-root .mt-list-search {
    grid-area: search;
    width: auto;
    max-width: none;
}

/* ---------- Filter trigger button ---------- */

.lib-filter-btn {
    grid-area: filter;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 48px;
    padding: 0 14px;
    border-radius: 12px;
    border: 1px solid var(--gray-300);
    background: #FFFFFF;
    color: var(--text-dark-color);
    cursor: pointer;
    font-family: var(--font-family);
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    transition: background-color .15s ease, border-color .15s ease;
}

    .lib-filter-btn:hover {
        background: var(--gray-200);
    }

.lib-filter-btn--active {
    border-color: var(--blue-color);
    color: var(--blue-color);
}

.lib-filter-btn__label {
    display: none;
}

.lib-filter-btn__badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--blue-color);
    color: #FFFFFF;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
}

.lib-filters-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(22, 30, 57, .35);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease-in-out;
    z-index: 50;
}

.lib-filters-backdrop--open {
    opacity: 1;
    pointer-events: auto;
}

.lib-filters {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    background: #FFFFFF;
    box-shadow: -8px 0 24px rgba(22, 30, 57, .15);
    transform: translateX(100%);
    transition: transform .25s ease-in-out;
    z-index: 60;
    display: flex;
    flex-direction: column;
}

.lib-filters--open {
    transform: translateX(0);
}

.lib-filters__header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid var(--gray-200);
}

.lib-filters__close {
    width: 40px;
    height: 40px;
}

.lib-filters__title {
    font-family: var(--third-family);
    font-weight: 600;
    font-size: 20px;
    color: var(--text-dark-color);
    margin: 0;
}

.lib-filters__reset {
    background: none;
    border: none;
    padding: 8px 12px;
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 14px;
    color: var(--green-color);
    cursor: pointer;
    border-radius: 8px;
}

    .lib-filters__reset:hover:not(:disabled) {
        background: rgba(28, 205, 157, .1);
    }

    .lib-filters__reset:disabled {
        color: var(--gray-500);
        cursor: default;
    }

.lib-filters__body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.lib-filters__footer {
    padding: 16px;
    border-top: 1px solid var(--gray-200);
    background: #FFFFFF;
}

.lib-filters__apply {
    width: 100%;
    height: 48px;
    border-radius: 12px;
    border: none;
    background: var(--green-color);
    color: #FFFFFF;
    font-family: var(--font-family);
    font-weight: 600;
    font-size: 16px;
    cursor: pointer;
    transition: filter .15s ease;
}

    .lib-filters__apply:hover {
        filter: brightness(1.05);
    }

/* ---------- Individual filter sections ---------- */

.lib-filter-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.lib-filter-section__title {
    font-family: var(--font-family);
    font-weight: 600;
    font-size: 16px;
    color: var(--text-dark-color);
    margin: 0;
}

/* Range input pair (Questions, Time) */
.lib-range {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 8px;
}

.lib-range__field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1 1 0;
    min-width: 0;
}

.lib-range__label {
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 12px;
    color: var(--gray-500);
}

.lib-range__field input {
    box-sizing: border-box;
    width: 100%;
    height: 44px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid var(--gray-300);
    background: #FFFFFF;
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 14px;
    color: var(--text-dark-color);
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}

    .lib-range__field input:focus {
        border-color: var(--blue-color);
        box-shadow: 0 0 0 3px rgba(75, 159, 255, .15);
    }

.lib-range__dash {
    padding-bottom: 12px;
    color: var(--gray-500);
}

/* Tab-like segmented control used for Time limit & Sort */
.lib-filter-tabs {
    display: flex;
    flex-direction: row;
    gap: 8px;
}

.lib-filter-tabs--wrap {
    flex-wrap: wrap;
}

.lib-filter-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    padding: 0 14px;
    border-radius: 10px;
    border: none;
    background: var(--gray-200);
    color: var(--text-dark-color);
    cursor: pointer;
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 14px;
    transition: background-color .15s ease, color .15s ease;
}

    .lib-filter-tab:hover {
        background: var(--gray-300);
    }

.lib-filter-tab--active {
    background: var(--blue-color);
    color: #FFFFFF;
}

    .lib-filter-tab--active:hover {
        background: var(--blue-700);
    }

/* ============================================================
   Tablet / desktop overrides
   ============================================================ */
@media (min-width: 768px) {

    .lib-root .mt-list-header {
        grid-template-areas: "title search filter";
        grid-template-columns: 1fr 303px auto;
    }

    .lib-root .mt-list-search {
        width: 303px;
        max-width: 303px;
    }

    .lib-filter-btn__label {
        display: inline;
    }

    /* Anchor the drawer to the right, cap its width. */
    .lib-filters {
        width: 380px;
        max-width: 90vw;
        border-radius: 20px 0 0 20px;
    }
}

@media (min-width: 1024px) {

    .lib-filters {
        width: 420px;
    }
}
