/* Floating Filter Bar - Reusable Component
   House style (2026-07): mono pill chips, teal/mint tokens — see
   reference_jmaths_house_style. */

.floating-filter-bar {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 50px;
    padding: 0.75rem 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--line);
    position: sticky;
    top: 80px;
    z-index: 500;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.filter-bar-filters {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
    flex: 1;
}

.filter-bar-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Filter Pills/Buttons */
.filter-pill {
    padding: 0.4rem 0.9rem;
    border: none;
    border-radius: 20px;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--jm-font-mono);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
}

.filter-pill:hover {
    background: var(--mint);
    color: var(--teal-deep);
}

.filter-pill.active {
    background: var(--teal);
    color: white;
    box-shadow: var(--shadow);
}

/* Filter Selects */
.filter-select {
    padding: 0.4rem 0.9rem;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--paper);
    font-family: var(--jm-font-mono);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 120px;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%230E2A28' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 12px;
    padding-right: 2rem;
}

.filter-select:focus {
    outline: none;
    border-color: var(--teal);
    box-shadow: 0 0 0 3px var(--mint);
}

/* Search Input */
.filter-search {
    padding: 0.4rem 1rem;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--paper);
    font-size: 0.85rem;
    min-width: 180px;
    transition: all 0.2s ease;
}

.filter-search:focus {
    outline: none;
    border-color: var(--teal);
    box-shadow: 0 0 0 3px var(--mint);
}

/* Action Buttons */
.filter-action-btn {
    padding: 0.4rem 0.9rem;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--paper);
    color: var(--muted);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--jm-font-mono);
    font-size: 0.8rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filter-action-btn:hover {
    background: var(--mint);
    border-color: var(--teal);
    color: var(--teal-deep);
}

.filter-action-btn.primary {
    background: var(--teal);
    border-color: transparent;
    color: white;
}

.filter-action-btn.primary:hover {
    box-shadow: var(--shadow);
    background: var(--teal-deep);
}

/* Results Count Badge */
.filter-results-badge {
    background: var(--mint);
    color: var(--teal-deep);
    font-family: var(--jm-font-mono);
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Responsive */
@media (max-width: 992px) {
    .floating-filter-bar {
        top: 60px;
        padding: 0.5rem 1rem;
        border-radius: 30px;
    }

    .filter-bar-filters {
        order: 2;
        width: 100%;
        justify-content: flex-start;
    }

    .filter-bar-actions {
        order: 1;
    }
}

@media (max-width: 768px) {
    .floating-filter-bar {
        border-radius: 20px;
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 0.75rem;
    }

    .filter-bar-filters {
        width: 100%;
        justify-content: center;
    }

    .filter-search {
        width: 100%;
        min-width: unset;
    }

    .filter-bar-actions {
        width: auto;
        justify-content: flex-end;
    }
}

/* Inline pill row inside the floating bar (unit-page topic navigator).
   Horizontal scroll on narrow viewports so the pill train never wraps
   awkwardly under the syllabus selector. */
.floating-filter-bar .filter-bar-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
    flex: 1;
    min-width: 0;
}
.floating-filter-bar .filter-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 3px 10px;
    background: var(--mint);
    border: 1px solid var(--line);
    border-radius: 8px;
    font-family: var(--jm-font-mono);
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--teal-ink);
    text-decoration: none;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.floating-filter-bar .filter-pill:hover {
    background: var(--mint2);
    border-color: var(--teal);
    color: var(--teal-deep);
    text-decoration: none;
}
.floating-filter-bar .filter-pill.active {
    background: var(--teal);
    border-color: var(--teal);
    color: white;
}
.floating-filter-bar .filter-pill-num {
    font-weight: 700;
    font-size: 0.78rem;
}
.floating-filter-bar .filter-pill-name {
    overflow: hidden;
    text-overflow: ellipsis;
}
.floating-filter-bar .filter-pill.locked {
    opacity: 0.5;
    cursor: not-allowed;
}
.floating-filter-bar .filter-pill-overview {
    background: var(--paper);
    border-color: var(--line);
    color: var(--muted);
    font-weight: 700;
}

/* View toggle (Course / By topic) — pill segmented control inside the
   floating bar. Active option fills teal; inactive stays muted. */
.floating-filter-bar .view-toggle {
    display: inline-flex;
    background: var(--mint);
    border-radius: 999px;
    padding: 2px;
    gap: 2px;
}
.floating-filter-bar .view-toggle-btn {
    padding: 4px 12px;
    font-family: var(--jm-font-mono);
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--muted);
    text-decoration: none;
    border-radius: 999px;
    transition: background 0.12s ease, color 0.12s ease;
    white-space: nowrap;
}
.floating-filter-bar .view-toggle-btn:hover {
    color: var(--teal-deep);
    text-decoration: none;
}
.floating-filter-bar .view-toggle-btn.active {
    background: var(--paper);
    color: var(--teal-deep);
    box-shadow: 0 1px 2px rgba(14, 42, 40, 0.12);
}

.filter-bar-trigger {
    white-space: nowrap;
}

.topic-filters-sheet {
    --bs-offcanvas-width: min(90vw, 340px);
}

@media (max-width: 991.98px) {
    /* backdrop-filter on .floating-filter-bar creates a CSS containing
       block for its position:fixed offcanvas descendant, trapping the
       sheet inside the pill's own box instead of the viewport. The pill
       background is already 95% opaque, so dropping the blur here (where
       the sheet must escape to fixed positioning) is visually a no-op. */
    .floating-filter-bar {
        backdrop-filter: none;
    }

    /* .floating-filter-bar is position:sticky with z-index:500, which
       establishes a stacking context — the nested offcanvas's own
       z-index:1045 only wins fights *inside* that context, so the whole
       subtree still renders beneath the site header (.jm-top-chrome,
       sticky z-index:1020) and the offcanvas backdrop (z-index:1040).
       Bump the ancestor above both, but only while the sheet is open, so
       normal scroll stacking (bar under the header) is unaffected. */
    .floating-filter-bar:has(.topic-filters-sheet.show),
    .floating-filter-bar:has(.topic-filters-sheet.showing) {
        z-index: 1046;
    }

    .topic-filters-sheet .offcanvas-body {
        display: block;
    }
}
