/* ============================================================
   Listing card header band — opt-in chrome for the site's card
   grids: learn categories and sections, protocol categories and
   protocols, checklist categories and checklists, quizzes, and
   the calculator tools.

   A card opts in by taking the .lib-card class and opening with
   <div class="lib-card-head"> wrapping its title heading. The band
   is solid navy with the brand-red line across its bottom edge,
   matching the .lib-group-heading
   bands above the grids so a card reads as a smaller sibling of
   its header.

   The title sits on a frosted strip spanning the full width of the
   band — translucent white over the navy, blurred, with a hairline
   rim and a top highlight. Same frosted-glass vocabulary as the
   card surfaces themselves. The strip reads identically in light
   and dark because the band behind it is dark in both themes.

   The band is full-bleed — it pulls out to the card's padding
   edges — so its negative margin has to track the card padding at
   every breakpoint. Every listing card on the site runs 2rem
   padding dropping to 1.5rem at the mobile breakpoint, so one pair
   of variables covers them all; the exceptions are handled at the
   bottom.

   The heading is matched by element, not by the module's own title
   class (.category-title / .quiz-title / .protocol-title / …), so
   a new card type only needs the two class hooks. Those module
   rules are all single-class, so this file out-ranks them wherever
   it loads — but link it last anyway, since the status-pill rules
   below tie with the top-right placements in the learn CSS.

   Colours, radii and frames come from the tokens in styles.css
   (--brand-navy, --brand-red, which follows the admin site colour,
   --r-lg, --frame-w, --surface-tray ...); the fallbacks are the old
   literals. Only links and cards not tagged .is-static react to
   hover and focus (styles.css, "Listing cards"); a static card's
   band stays at rest too. The shared, class-named version of this
   band is .fl-band / .fl-band--title in styles.css.
   ============================================================ */

.lib-card {
    /* Minimum band height, the gap below it, and the card's own
       padding, kept in variables so the pull-out, the card
       variants, and the mobile breakpoint stay in sync from one
       place. The band grows past the minimum when a long title
       wraps to a second line. */
    --lib-band-h: 3.75rem;
    --lib-band-gap: 1.25rem;
    --lib-card-pad: var(--pad-card, 2rem);
    /* Derived so the common case sets one value, while a card with
       asymmetric padding (the tools picker) can pull the two apart. */
    --lib-card-pad-x: var(--lib-card-pad);
    --lib-card-pad-y: var(--lib-card-pad);
}

.lib-card-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: var(--lib-band-h);
    padding: 0.75rem;
    /* Pull out to the card's padding edges so the band is full-bleed. */
    margin: calc(var(--lib-card-pad-y) * -1) calc(var(--lib-card-pad-x) * -1) var(--lib-band-gap);
    /* Brand-red line closing the band off, same as the group headings. */
    border-bottom: 3px solid var(--brand-red, #c0392b);
    /* The card's radius minus its frame, so the corners sit exactly
       inside the frame (16px - 3px). */
    border-radius: calc(var(--r-lg, 16px) - var(--frame-w, 3px)) calc(var(--r-lg, 16px) - var(--frame-w, 3px)) 0 0;
    /* Solid navy field. */
    background: var(--brand-navy, #0c1929);
    transition: border-color 0.3s ease;
}

/* The frosted title strip. */
.lib-card-head > h2,
.lib-card-head > h3 {
    flex: 1 1 auto;
    margin: 0;
    max-width: 100%;
    padding: 0.5rem 1rem;
    border-radius: var(--r-sm, 8px);
    background: rgba(255, 255, 255, 0.13);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border: 1px solid rgba(255, 255, 255, 0.22);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
    color: #fff;
    font-size: var(--fs-band-title, 1.15rem);
    font-weight: 700;
    line-height: 1.25;
    text-align: center;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    transition: background 0.3s ease, border-color 0.3s ease;
}

/* Hover: the strip lifts a stop and the red line brightens, riding
   along with the card lift and the "Enter Here" arrow. Links and
   cards not tagged .is-static only, like the lift. */
.lib-card:where(a, :not(.is-static)):hover .lib-card-head,
.lib-card:where(a, :not(.is-static)):focus-visible .lib-card-head,
.lib-card:where(a, :not(.is-static)):focus-within .lib-card-head {
    border-bottom-color: var(--brand-red-hover, #c9574b);
}

.lib-card:where(a, :not(.is-static)):hover .lib-card-head > h2,
.lib-card:where(a, :not(.is-static)):hover .lib-card-head > h3,
.lib-card:where(a, :not(.is-static)):focus-visible .lib-card-head > h2,
.lib-card:where(a, :not(.is-static)):focus-visible .lib-card-head > h3,
.lib-card:where(a, :not(.is-static)):focus-within .lib-card-head > h2,
.lib-card:where(a, :not(.is-static)):focus-within .lib-card-head > h3 {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.32);
}

/* Resource cards run tighter than the rest, and hold that padding at
   every width rather than stepping down on mobile. */
.res-card.lib-card {
    --lib-card-pad: 1.5rem;
}

/* The tools picker's destination cards are taller than they are wide
   in their padding, and hold it at every width. */
.learn-picker-card.lib-card {
    --lib-card-pad-x: 2rem;
    --lib-card-pad-y: 2.5rem;
}

@media (max-width: 768px) {
    /* Cards drop to 1.5rem padding at this breakpoint — the band's
       pull-out follows it through --pad-card, which steps to 1.5rem
       here. */
    .lib-card {
        --lib-band-h: 3.4rem;
    }

    .lib-card-head {
        padding: 0.6rem;
    }

    .lib-card-head > h2,
    .lib-card-head > h3 {
        font-size: 1.05rem;
        padding: 0.45rem 0.85rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .lib-card-head,
    .lib-card-head > h2,
    .lib-card-head > h3 {
        transition: none;
    }
}

/* ============================================================
   Category / section group panel — /learn/library/ and
   /learn/{category}/ on their "All" tab, where cards are broken
   into groups.

   The whole group is one card: the navy band runs across its top
   as a collapse toggle, and the grid of cards lives inside it, so
   a group reads as a container rather than a loose heading over a
   detached grid. Same surface as the listing cards it holds
   (near-black frame, frosted gradient, blue-cast shadow) but with
   no hover lift — it's a container, not a target.

   Collapsing animates in both directions via a 1fr -> 0fr grid row,
   which folds to the content's own height without anyone having to
   measure it. That needs a clipping wrapper, and Bootstrap's rows
   carry negative margins that an overflow-clipped element would cut
   into — so the padding sits one level deeper, on .lib-group-grid,
   clear of the clip. Where the fr transition isn't supported the
   fold simply snaps; nothing breaks.
   ============================================================ */

.lib-group {
    margin: 1.9rem 0 1.25rem;
    border-radius: var(--r-lg, 16px);
    border: var(--frame-w, 3px) solid var(--frame-listing, #0c1929);
    /* --surface-tray: deliberately a few stops deeper than the
       near-white cards it holds (light), lighter than the near-black
       cards (dark), so the panel reads as a tray behind them rather
       than one continuous surface with the cards dissolved into it. */
    background: var(--surface-tray, linear-gradient(160deg, #dbe5f2 0%, #d0dcec 55%, #c6d5e9 100%));
    box-shadow: var(--elev-listing, 0 4px 14px rgba(58, 111, 168, 0.1), 0 1px 3px rgba(40, 50, 75, 0.05));
    /* Clips the band's square top corners to the panel's radius. */
    overflow: hidden;
}

.lib-group:first-of-type {
    margin-top: 0.25rem;
}

/* The band, now a full-width collapse toggle. */
.lib-group-heading {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    margin: 0;
    padding: 0.85rem 1.1rem;
    border: 0;
    border-bottom: 3px solid var(--brand-red, #c0392b);
    background: var(--brand-navy, #0c1929);
    color: #fff;
    font-size: var(--fs-band-label, 0.95rem);
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.3s ease, filter 0.2s ease;
}

.lib-group-heading:hover {
    filter: brightness(1.25);
    border-bottom-color: var(--brand-red-hover, #c9574b);
}

.lib-group-heading:focus-visible {
    outline: 2px solid var(--focus-color-chrome, #d9b380);
    outline-offset: -5px;
}

.lib-group-heading .ti-folder {
    flex: 0 0 auto;
    color: var(--brand-gold, #d9b380);
    font-size: 1.1rem;
}

.lib-group-title {
    flex: 1 1 auto;
    min-width: 0;
}

/* Card count doubles as the affordance's payload: what's inside
   stays readable when the group is shut. */
.lib-group-count {
    flex: 0 0 auto;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.22);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    font-variant-numeric: tabular-nums;
}

.lib-group-chevron {
    flex: 0 0 auto;
    color: var(--brand-gold, #d9b380);
    font-size: 1.15rem;
    transition: transform 0.3s ease;
}

.lib-group.is-collapsed .lib-group-chevron {
    transform: rotate(-90deg);
}

/* A shut group is just its band — drop the red line so the panel
   reads as one closed bar rather than a bar with a loose edge. */
.lib-group.is-collapsed .lib-group-heading {
    border-bottom-width: 0;
}

.lib-group-body {
    display: grid;
    grid-template-rows: 1fr;
    transition: grid-template-rows 0.34s cubic-bezier(0.4, 0, 0.2, 1);
}

.lib-group.is-collapsed .lib-group-body {
    grid-template-rows: 0fr;
}

.lib-group-body-inner {
    min-height: 0;
    overflow: hidden;
}

/* Held back until the fold has finished, so a shut group drops out of
   the tab order and the accessibility tree without cutting the
   animation short on the way down. */
.lib-group.is-collapsed .lib-group-body-inner {
    visibility: hidden;
    transition: visibility 0s linear 0.34s;
}

.lib-group-grid {
    padding: 1.4rem 1.25rem;
    opacity: 1;
    transition: opacity 0.26s ease 0.06s;
}

.lib-group.is-collapsed .lib-group-grid {
    opacity: 0;
    transition: opacity 0.18s ease;
}

@media (max-width: 768px) {
    .lib-group-grid {
        padding: 1.1rem 0.85rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .lib-group-heading,
    .lib-group-chevron {
        transition: none;
    }

    .lib-group-body,
    .lib-group-grid {
        transition: none;
    }
}

/* ------------------------------------------------------------
   Collapse-all control. Lives in the "All" panel's header, the
   only panel that renders groups. Styled after .learn-back-btn so
   it reads as the same class of control, minus that button's
   leftward hover nudge — nothing here is going back.
   ------------------------------------------------------------ */

.lib-panel-header-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.lib-panel-header-text {
    min-width: 0;
}

.lib-toggle-all {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.95rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--primary-soft) 8%, var(--card-bg));
    border: 1.5px solid color-mix(in srgb, var(--primary-soft) 25%, var(--border-soft));
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1.4;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.lib-toggle-all:hover {
    background: color-mix(in srgb, var(--primary-soft) 16%, var(--card-bg));
    border-color: var(--primary-soft);
    color: var(--text-primary);
}

.lib-toggle-all:focus-visible {
    outline: 2px solid var(--primary-soft);
    outline-offset: 2px;
}

.lib-toggle-all i {
    font-size: 1rem;
}

@media (prefers-reduced-motion: reduce) {
    .lib-toggle-all {
        transition: none;
    }
}
