/*
 * The course catalog (`[turgee_courses]`) - a plain card grid.
 *
 * WHY THIS FILE IS HERE AND NOT IN TURGOR LMS
 *
 * CourseCatalog moved into Pro with the storefront split, and has enqueued
 * `assets/course-catalog.css` from THIS plugin ever since - but the file
 * itself stayed behind in Turgor Exam Engine's own assets/, where nothing loads it.
 * Every catalog page requested a stylesheet that 404'd and rendered as an
 * unstyled bulleted list. Tests\Unit\AssetsExistTest now fails if any
 * Assets::url() reference points at a file that is not in assets/.
 *
 * ITS OWN STYLESHEET, NOT course-page.css: this shortcode goes on ANY page,
 * so it is enqueued at render time rather than keyed on post type.
 *
 * INHERITS RATHER THAN DECLARES: the defaults set no font family, no font
 * size and no body colour - only currentColor at reduced opacity - so this
 * reads correctly inside whatever theme it lands in.
 *
 * THEMEABLE THROUGH CUSTOM PROPERTIES, not by overriding selectors: a site
 * sets the --tg-catalog-* variables below (on .tg-catalog, or per card with
 * :nth-child() or the --product / --course modifiers) to restyle cards -
 * a coloured gradient, white text, a solid button - with no knowledge of
 * this file's internals.
 *
 * ONE LINK PER CARD, PLUS "ADD TO CART": the title's link is stretched over
 * the whole card with ::after, so the card stays clickable anywhere while a
 * screen reader hears one link, named after the course. `.tg-catalog__cta`
 * is a label, not a link. The one real second link, `.tg-catalog__add-to-cart`
 * (Products linked to WooCommerce only), sits above that overlay.
 */

/*
 * DEFAULTS UNDER :where(), which has no specificity - so a theme's own
 * `.tg-catalog { --tg-catalog-card-bg: ... }` always wins, whichever loads
 * last. This stylesheet is enqueued while the shortcode renders, so it
 * usually prints AFTER a theme's or page's own CSS; with a plain
 * `.tg-catalog` selector here, these defaults silently beat the theme's
 * values of equal specificity.
 */
:where(.tg-catalog) {
    --tg-catalog-columns-min: 220px;
    --tg-catalog-gap: 1.5rem;
    --tg-catalog-card-bg: transparent;
    --tg-catalog-card-color: inherit;
    --tg-catalog-card-border: 1px solid color-mix(in srgb, currentColor 12%, transparent);
    --tg-catalog-card-radius: var(--tg-radius, 6px);
    --tg-catalog-card-shadow: none;
    --tg-catalog-card-padding: 0.9rem;
    --tg-catalog-muted-opacity: 0.75;
    --tg-catalog-cta-bg: transparent;
    --tg-catalog-cta-color: inherit;
    --tg-catalog-cta-border: 1px solid var(--tg-brand, currentColor);
    --tg-catalog-cart-bg: var(--tg-brand, currentColor);
    --tg-catalog-cart-color: var(--tg-brand-contrast, Canvas);
}

/*
 * ul.tg-catalog, not .tg-catalog: themes indent lists in post content with
 * `.entry-content ul { padding-left: ... }`, which a single class loses to,
 * pushing the whole grid off to one side.
 */
ul.tg-catalog {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--tg-catalog-columns-min), 1fr));
    gap: var(--tg-catalog-gap);
    margin: 1.5rem 0;
    padding: 0;
    list-style: none;
}

ul.tg-catalog > .tg-catalog__card {
    margin: 0;
}

.tg-catalog__card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: var(--tg-catalog-card-padding);
    background: var(--tg-catalog-card-bg);
    color: var(--tg-catalog-card-color);
    border: var(--tg-catalog-card-border);
    border-radius: var(--tg-catalog-card-radius);
    box-shadow: var(--tg-catalog-card-shadow);
    overflow: hidden;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.tg-catalog__card:hover {
    box-shadow: var(--tg-catalog-card-shadow), 0 4px 14px color-mix(in srgb, currentColor 14%, transparent);
}

.tg-catalog__card:focus-within {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

.tg-catalog__thumb {
    display: block;
    width: calc(100% + 2 * var(--tg-catalog-card-padding));
    max-width: none;
    height: auto;
    margin: calc(-1 * var(--tg-catalog-card-padding)) calc(-1 * var(--tg-catalog-card-padding)) 0.4rem;
    aspect-ratio: 16 / 9;
    object-fit: cover;
}

.tg-catalog__title {
    margin: 0;
    font-size: 1.05em;
    line-height: 1.3;
    color: inherit;
}

.tg-catalog__link {
    text-decoration: none;
    color: inherit;
}

.tg-catalog__link::after {
    content: "";
    position: absolute;
    inset: 0;
}

.tg-catalog__link:focus-visible {
    outline: none; /* the card's :focus-within ring shows focus instead */
}

.tg-catalog__excerpt {
    margin: 0;
    opacity: var(--tg-catalog-muted-opacity);
    font-size: 0.9em;
}

.tg-catalog__price {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin: 0.2rem 0;
}

.tg-catalog__price-original {
    text-decoration: line-through;
    opacity: 0.6;
    font-size: 0.9em;
}

.tg-catalog__price-offer {
    font-weight: 700;
    font-size: 1.2em;
}

.tg-catalog__actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: auto;
    padding-top: 0.4rem;
}

.tg-catalog__cta,
.tg-catalog__add-to-cart {
    display: block;
    padding: 0.55rem 0.9rem;
    text-align: center;
    border-radius: 8px;
    font-weight: 600;
    text-decoration: none;
}

.tg-catalog__cta {
    background: var(--tg-catalog-cta-bg);
    color: var(--tg-catalog-cta-color);
    border: var(--tg-catalog-cta-border);
}

.tg-catalog__card:hover .tg-catalog__cta {
    background: color-mix(in srgb, currentColor 10%, var(--tg-catalog-cta-bg));
}

/* Above the title link's ::after overlay, so it gets its own clicks. */
.tg-catalog__add-to-cart {
    position: relative;
    z-index: 1;
    background: var(--tg-catalog-cart-bg);
    color: var(--tg-catalog-cart-color);
    border: 1px solid transparent;
}

.tg-catalog__add-to-cart:hover,
.tg-catalog__add-to-cart:focus-visible {
    filter: brightness(0.95);
}

.tg-catalog__empty {
    opacity: 0.75;
}

@supports not (color: color-mix(in srgb, currentColor 12%, transparent)) {
    :where(.tg-catalog) {
        --tg-catalog-card-border: 1px solid rgba(128, 128, 128, 0.2);
    }
}
