/*
 * trainitnow-child — Catalog filter bar
 *
 * Styles the `[tin_catalog_filters]` shortcode (see functions.php). Moved out
 * of woocommerce.css section [11] when the bar was redesigned: the old layout
 * was one flex row holding the search box and every dropdown, so each new
 * filterable attribute made the row longer, the boxes narrower and their
 * wrapping less predictable. This version stacks three fixed rows instead —
 * active-filter pills, the search row, and a collapsible even grid of
 * dropdowns — so the bar's height and rhythm no longer depend on how many
 * attributes a given site filters on.
 *
 * Panel visibility: `display: none` here, `display: grid` under `.is-expanded`
 * (toggled by js/catalog-filters.js), and forced open by an inline <noscript>
 * override in the shortcode. Collapsing is display-only — hidden <select>s
 * still submit their values, so a collapsed panel never silently drops a
 * filter.
 */

.tin-catalog-form {
    /* Shared control height — the search input, both buttons and every select
     * line up on it, and the dropdown chevron is positioned from it. */
    --tin-control-h: 44px;

    display: flex;
    flex-direction: column;
    gap: 14px;
    background: var(--tin-card);
    border: 1px solid var(--tin-border);
    border-radius: var(--tin-radius-lg);
    padding: 16px;
    box-shadow: var(--tin-shadow-card);
    margin-bottom: 24px;
}

/* ------------------------------------------------------------------
 * Active-filter pills
 * ------------------------------------------------------------------
 * Each pill is a plain link back to the same results minus that one
 * filter — no JS, no state to keep in sync with the dropdowns below.
 */
.tin-catalog-form__active {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.tin-filter-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    padding: 0 10px 0 12px;
    border: 1px solid var(--tin-border);
    border-radius: 999px;
    background: var(--tin-accent);
    color: var(--tin-accent-foreground);
    font-family: inherit;
    font-size: 13px;
    line-height: 1;
    text-decoration: none;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
/* Divi appends arrow glyphs via ::after on link-ish elements; make sure none
 * of that leaks into a pill. */
.tin-filter-pill::after {
    display: none !important;
}
.tin-filter-pill__key {
    font-weight: 500;
    opacity: 0.65;
}
.tin-filter-pill__key::after {
    content: ":";
}
.tin-filter-pill__value {
    font-weight: 600;
}
.tin-filter-pill__x {
    opacity: 0.5;
    transition: opacity 0.15s ease;
}
.tin-filter-pill:hover,
.tin-filter-pill:focus-visible {
    background: var(--tin-primary);
    border-color: var(--tin-primary);
    color: var(--tin-primary-foreground);
}
.tin-filter-pill:hover .tin-filter-pill__x,
.tin-filter-pill:focus-visible .tin-filter-pill__x {
    opacity: 1;
}
.tin-filter-pill:focus-visible {
    outline: none;
    box-shadow: var(--tin-focus-ring);
}

/* "Clear all" reads as a quiet escape hatch, not a fourth filter. */
.tin-filter-pill--clear {
    padding: 0 8px;
    background: transparent;
    border-color: transparent;
    color: var(--tin-muted-foreground);
    text-decoration: underline;
}
.tin-filter-pill--clear:hover,
.tin-filter-pill--clear:focus-visible {
    background: transparent;
    border-color: transparent;
    color: var(--tin-primary);
}

/* ------------------------------------------------------------------
 * Search row: input + Filters toggle + submit
 * ------------------------------------------------------------------ */
.tin-catalog-form__bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.tin-catalog-form__search {
    position: relative;
    display: flex;
    align-items: center;
    /* Absorbs all leftover width; min-width:0 lets it actually shrink inside
     * the flex row instead of forcing an early wrap. */
    flex: 1 1 260px;
    min-width: 0;
}
.tin-catalog-form .tin-search-icon {
    position: absolute;
    left: 14px;
    color: var(--tin-muted-foreground);
    pointer-events: none;
}
.tin-catalog-form input[type="search"] {
    width: 100%;
    height: var(--tin-control-h);
    padding: 0 14px 0 42px;
    border: 1px solid var(--tin-border);
    border-radius: var(--tin-radius-md);
    background: var(--tin-card);
    color: var(--tin-foreground);
    font-family: inherit;
    font-size: 15px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.tin-catalog-form input[type="search"]:focus {
    outline: none;
    border-color: var(--tin-primary);
    box-shadow: var(--tin-focus-ring);
}

.tin-catalog-form__toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    height: var(--tin-control-h);
    padding: 0 14px;
    border: 1px solid var(--tin-border);
    border-radius: var(--tin-radius-md);
    background: var(--tin-card);
    color: var(--tin-foreground);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}
.tin-catalog-form__toggle:hover {
    border-color: var(--tin-primary);
    color: var(--tin-primary);
}
.tin-catalog-form__toggle:focus-visible {
    outline: none;
    border-color: var(--tin-primary);
    box-shadow: var(--tin-focus-ring);
}

/* How many filters are on, while the panel is shut. The label itself stays
 * "Filters" in both states so the button never changes width. */
.tin-catalog-form__count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--tin-primary);
    color: var(--tin-primary-foreground);
    font-size: 12px;
    font-weight: 700;
}

.tin-catalog-form__chevron {
    transition: transform 0.2s ease;
}
.tin-catalog-form.is-expanded .tin-catalog-form__chevron {
    transform: rotate(180deg);
}

.tin-catalog-form__submit {
    flex: 0 0 auto;
    height: var(--tin-control-h);
    padding: 0 22px;
    border: 0;
    border-radius: var(--tin-radius-md);
    background: var(--tin-primary);
    color: var(--tin-primary-foreground);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.2s ease;
}
.tin-catalog-form__submit:hover {
    filter: brightness(0.92);
}
.tin-catalog-form__submit:focus-visible {
    outline: none;
    box-shadow: var(--tin-focus-ring);
}

/* ------------------------------------------------------------------
 * Dropdown panel
 * ------------------------------------------------------------------
 * auto-fit + minmax is the whole point of the redesign: however many
 * attributes a site filters on, the cells are equal width, aligned in
 * rows, and reflow to fewer columns instead of squeezing.
 */
.tin-catalog-form__panel {
    display: none;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px 14px;
    padding-top: 14px;
    border-top: 1px solid var(--tin-border);
}
.tin-catalog-form.is-expanded .tin-catalog-form__panel {
    display: grid;
    animation: tin-filters-reveal 0.18s ease;
}
@keyframes tin-filters-reveal {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
    .tin-catalog-form.is-expanded .tin-catalog-form__panel { animation: none; }
    .tin-catalog-form__chevron { transition: none; }
}

.tin-catalog-form__field {
    position: relative;
    min-width: 0;
}
.tin-catalog-form__label {
    display: block;
    margin-bottom: 6px;
    color: var(--tin-muted-foreground);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
}

.tin-catalog-form__select {
    width: 100%;
    height: var(--tin-control-h);
    padding: 0 34px 0 14px;
    border: 1px solid var(--tin-border);
    border-radius: var(--tin-radius-md);
    background-color: var(--tin-card);
    color: var(--tin-foreground);
    font-family: inherit;
    font-size: 15px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.tin-catalog-form__select:hover {
    border-color: var(--tin-primary);
}
.tin-catalog-form__select:focus {
    outline: none;
    border-color: var(--tin-primary);
    box-shadow: var(--tin-focus-ring);
}

/* Chevron drawn on the FIELD wrapper rather than as a background-image on the
 * select: a data-URI SVG can't read a CSS variable, so the old version had the
 * arrow colour hardcoded. Two borders on a rotated box follow the tokens. */
.tin-catalog-form__field::after {
    content: "";
    position: absolute;
    right: 16px;
    bottom: calc(var(--tin-control-h) / 2 - 5px);
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--tin-muted-foreground);
    border-bottom: 2px solid var(--tin-muted-foreground);
    transform: rotate(45deg);
    pointer-events: none;
}

/* ------------------------------------------------------------------
 * Narrow screens: search takes its own row, the two buttons split the
 * next one evenly, and the grid collapses toward a single column.
 * ------------------------------------------------------------------ */
@media (max-width: 640px) {
    .tin-catalog-form {
        padding: 14px;
    }
    .tin-catalog-form__search {
        flex: 1 1 100%;
    }
    .tin-catalog-form__toggle,
    .tin-catalog-form__submit {
        flex: 1 1 0;
        justify-content: center;
        padding: 0 12px;
    }
    .tin-catalog-form__panel {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }
}
