/* ==========================================================================
   Faceted Search for Ultimate Member — sidebar stylesheet
   Works alongside UM's native .um-members-wrapper and user card rendering.
   ========================================================================== */

/* ------------------------------------------------------------------
   Layout: CSS Grid so the sidebar spans the full height beside the
   member grid (header + cards + pagination).
   ------------------------------------------------------------------ */

.um:has(.um-fs-sidebar) {
    display: grid;
    grid-template-columns: 260px 1fr;
}

/* Sidebar left (default) — column 1, span all rows */
.um-fs-sidebar {
    grid-column: 1;
    grid-row: 1 / span 99;
    padding: 0 20px 0 0;
    box-sizing: border-box;
    align-self: start;
}

/* All other UM children flow into column 2 */
.um:has(.um-fs-sidebar) > *:not(.um-fs-sidebar) {
    grid-column: 2;
}

/* Sidebar right */
.um:has(.um-fs-sidebar.um-fs-layout-sidebar_right) {
    grid-template-columns: 1fr 260px;
}

.um-fs-sidebar.um-fs-layout-sidebar_right {
    grid-column: 2;
    grid-row: 1 / span 99;
    padding: 0 0 0 20px;
}

.um:has(.um-fs-sidebar.um-fs-layout-sidebar_right) > *:not(.um-fs-sidebar) {
    grid-column: 1;
}

/* Top bar */
.um:has(.um-fs-sidebar.um-fs-layout-topbar) {
    grid-template-columns: 1fr;
}

.um-fs-sidebar.um-fs-layout-topbar {
    grid-column: 1;
    grid-row: auto;
    padding: 0 0 16px 0;
}

.um-fs-sidebar.um-fs-layout-topbar .um-fs-facets-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.um-fs-sidebar.um-fs-layout-topbar .um-fs-block {
    flex: 1 1 200px;
    min-width: 0;
}

/* ------------------------------------------------------------------
   Facet blocks
   ------------------------------------------------------------------ */

.um-fs-block {
    margin-bottom: 12px;
    padding: 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fff;
}

.um-fs-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    margin-bottom: 0;
}

.um-fs-heading h4 {
    margin: 0;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #374151;
}

.um-fs-toggle {
    border: none;
    background: transparent;
    cursor: pointer;
    color: #9ca3af;
    font-size: 18px;
    line-height: 1;
    padding: 0;
    display: none;
    transition: transform 0.2s;
}

.um-fs-block.is-collapsed .um-fs-toggle {
    transform: rotate(-90deg);
}

.um-fs-content {
    margin-top: 10px;
}

.um-fs-block.is-collapsed .um-fs-content {
    display: none;
}

/* Options (checkbox/radio) */
.um-fs-options {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 240px;
    overflow-y: auto;
}

.um-fs-option {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.875rem;
    color: #374151;
    cursor: pointer;
    line-height: 1.4;
}

.um-fs-option input {
    accent-color: #4f46e5;
    flex-shrink: 0;
}

.um-fs-count {
    color: #9ca3af;
    font-size: 0.78em;
}

/* Dropdown */
.um-fs-input[data-facet-type="dropdown"] {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.875rem;
    color: #374151;
    background: #fff;
}

/* Tags */
.um-fs-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.um-fs-tag {
    border: 1px solid #d1d5db;
    background: #f9fafb;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.78rem;
    cursor: pointer;
    color: #374151;
    transition: all 0.15s;
    line-height: 1.5;
}

.um-fs-tag:hover {
    border-color: #6366f1;
    color: #4f46e5;
}

.um-fs-tag.is-active {
    background: #eef2ff;
    border-color: #6366f1;
    color: #4f46e5;
    font-weight: 600;
}

/* Range inputs */
.um-fs-range-wrap {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.um-fs-range-wrap label {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 0.78rem;
    color: #6b7280;
}

.um-fs-range-input {
    padding: 5px 8px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.875rem;
    width: 100%;
    box-sizing: border-box;
    color: #374151;
}

.um-fs-empty {
    font-size: 0.8rem;
    color: #9ca3af;
    margin: 0;
}

/* ------------------------------------------------------------------
   Active filter chips
   ------------------------------------------------------------------ */

.um-fs-active-chips {
    margin-top: 12px;
    padding: 8px;
    background: #fafafa;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    display: none; /* shown by JS when chips exist */
}

.um-fs-active-chips:not(:empty) {
    display: block;
}

.um-fs-chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 8px;
}

.um-fs-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 0.78rem;
    color: #3730a3;
}

.um-fs-chip-remove {
    background: none;
    border: none;
    cursor: pointer;
    color: #6366f1;
    font-size: 13px;
    padding: 0 1px;
    line-height: 1;
}

.um-fs-chip-remove:hover { color: #dc2626; }

.um-fs-clear-all {
    font-size: 0.78rem;
    color: #6b7280;
    background: none;
    border: 1px solid #d1d5db;
    border-radius: 5px;
    padding: 3px 8px;
    cursor: pointer;
    transition: all 0.15s;
    width: 100%;
}

.um-fs-clear-all:hover {
    background: #fee2e2;
    border-color: #fca5a5;
    color: #b91c1c;
}

/* ------------------------------------------------------------------
   Show more / Show less
   ------------------------------------------------------------------ */

.um-fs-show-more {
    background: none;
    border: none;
    padding: 4px 0 0;
    font-size: 0.78rem;
    color: #4f46e5;
    cursor: pointer;
    text-align: left;
}

.um-fs-show-more:hover {
    text-decoration: underline;
}

/* ------------------------------------------------------------------
   Results count header
   ------------------------------------------------------------------ */

.um-fs-results-header {
    font-size: 0.875rem;
    color: #6b7280;
    padding: 6px 0 12px;
    flex-basis: 100%;
    order: 0;
}

.um-fs-results-header strong {
    color: #111827;
    font-weight: 600;
}

/* ------------------------------------------------------------------
   Keyboard focus
   ------------------------------------------------------------------ */

.um-fs-option input:focus-visible,
.um-fs-tag:focus-visible,
.um-fs-toggle:focus-visible,
.um-fs-show-more:focus-visible,
.um-fs-chip-remove:focus-visible {
    outline: 2px solid #4f46e5;
    outline-offset: 2px;
    border-radius: 3px;
}

/* ------------------------------------------------------------------
   Mobile
   ------------------------------------------------------------------ */

@media (max-width: 767px) {
    .um:has(.um-fs-sidebar) {
        grid-template-columns: 1fr;
    }

    .um-fs-sidebar,
    .um-fs-sidebar.um-fs-layout-sidebar_right {
        grid-column: 1;
        grid-row: auto;
        padding: 0 0 16px 0;
    }

    .um:has(.um-fs-sidebar) > *:not(.um-fs-sidebar),
    .um:has(.um-fs-sidebar.um-fs-layout-sidebar_right) > *:not(.um-fs-sidebar) {
        grid-column: 1;
    }

    .um-fs-sidebar.um-fs-layout-topbar .um-fs-facets-panel {
        display: block;
    }

    .um-fs-toggle {
        display: inline-block;
    }

    .um-fs-block {
        margin-bottom: 8px;
    }
}

/* ------------------------------------------------------------------
   Loading / active feedback states
   ------------------------------------------------------------------ */

/*
 * Stale counts: when a filter just changed and the new counts are
 * in-flight, dim the count badges so users know they're updating.
 * The transition makes the dim feel smooth rather than jarring.
 */
.um-fs-counts-stale .um-fs-count {
    opacity: 0.35;
    transition: opacity 0.1s ease;
}

/* Restore counts with a gentle fade-in once the AJAX returns. */
.um-fs-facets-panel:not(.um-fs-counts-stale) .um-fs-count {
    opacity: 1;
    transition: opacity 0.2s ease;
}

/*
 * Active label highlight: applied immediately on checkbox/radio click
 * via _handleInputChange(), before the AJAX round-trip.
 * Gives instant visual confirmation that the click registered.
 */
.um-fs-option.is-active {
    color: #4f46e5;
    font-weight: 500;
}

.um-fs-option.is-active input[type="checkbox"],
.um-fs-option.is-active input[type="radio"] {
    accent-color: #4f46e5;
}

/*
 * Subtle pulse on the sidebar panel while counts are loading.
 * Keeps the animation lightweight (opacity only, GPU-accelerated).
 */
@keyframes umFsCountPulse {
    0%   { opacity: 0.35; }
    50%  { opacity: 0.55; }
    100% { opacity: 0.35; }
}

.um-fs-counts-stale .um-fs-count {
    animation: umFsCountPulse 1s ease-in-out infinite;
}

.um-fs-truncated-notice {
    margin: 8px 0 0;
    padding: 8px 10px;
    font-size: 12px;
    line-height: 1.4;
    color: #8a6d3b;
    background: #fff8e5;
    border: 1px solid #f0e0b2;
    border-radius: 6px;
}
