/* ---------- Page title ---------- */

.lib-page-title {
    font-family: var(--third-family);
    font-weight: 600;
    font-size: 20px;
    line-height: 1.25;
    color: var(--text-dark-color);
    margin: 0;
}

/* ---------- Collections row ---------- */

.lib-collections {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    min-width: 0;
}

.lib-collections__header {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.lib-collections__title {
    font-family: var(--font-family);
    font-weight: 600;
    font-size: 18px;
    line-height: 28px;
    color: var(--text-dark-color);
    margin: 0;
}

.lib-collections__all {
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 14px;
    color: var(--blue-color);
    text-decoration: none;
    white-space: nowrap;
}

    .lib-collections__all:hover {
        text-decoration: underline;
    }

/* Horizontal shelf of square collection cards. */
.lib-collections__shelf {
    align-items: flex-start;
    padding-bottom: 8px;
}

/* Full grid of square collection cards (all-collections page). */
.lib-collections-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
    gap: 16px 12px;
    width: 100%;
}

    .lib-collections-grid .collection-card-square {
        width: 100%;
    }

/* ---------- Sticky tests section bar ---------- */
/* A solid plate that spans the full content width (the negative margins cancel the page padding of
   .mt-root--list) and pins to the top of the scroll container, so it reads as page chrome for the
   tests list rather than as a card floating on the page background. It carries no heading — the
   search box and the result count already describe what it controls. */

.lib-tests-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: grid;
    grid-template-areas:
        "search filter"
        "count  count";
    grid-template-columns: 1fr auto;
    align-items: center;
    row-gap: 8px;
    column-gap: 12px;
    box-sizing: border-box;
    margin: 0 -16px;
    padding: 12px 16px;
    background: #FFFFFF;
    border-bottom: 1px solid var(--gray-300);
}

.lib-tests-bar__count {
    grid-area: count;
    justify-self: start;
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 13px;
    line-height: 18px;
    color: var(--gray-600);
    white-space: nowrap;
}

.lib-tests-bar__search {
    grid-area: search;
    min-width: 0;
}

/* ---------- 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-page-title {
        font-size: 24px;
    }

    .lib-tests-bar {
        grid-template-areas: "search filter count";
        grid-template-columns: 303px auto 1fr;
        margin: 0 -8px;
        padding: 12px 8px;
        row-gap: 0;
        column-gap: 16px;
    }

    .lib-tests-bar__count {
        justify-self: end;
    }

    .lib-tests-bar__search {
        width: 303px;
        max-width: 303px;
    }

    .lib-collections-grid {
        grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
        gap: 20px 16px;
    }

    .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-tests-bar {
        margin: 0 -22px;
        padding: 12px 22px;
    }

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

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {

    .lib-filter-btn,
    .lib-filters,
    .lib-filters-backdrop,
    .lib-filters__apply,
    .lib-filter-tab,
    .lib-range__field input {
        transition: none;
    }
}
