/* ==========================================================================
   Filter Components — Design System
   Two patterns: Inline Filter Bar (Pattern 1) and Sidebar Filters (Pattern 2)
   See docs/ideas/filter-patterns.md for usage guide.
   ========================================================================== */

/* ==========================================================================
   PATTERN 1 — Inline Filter Bar
   Use for lists with ≤3 filter controls (pills, search, dropdowns).
   Pages: Insights, Prompts, Templates, Relationships
   ========================================================================== */
.list-filters {
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1rem;
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* ⭐ Search and pills sit bare on the ground under the header. The white
   box above is a card that is not an item — and, at 16px, the only second
   radius on /entries/. Shipped as a modifier on the ported pages first
   (entries, then the other four); it becomes the default when Insights has
   been walked. 📐 docs/admin/design_system.md "Ports". */
.list-filters--bare {
    background: none;
    border: 0;
    border-radius: 0;
    padding: 0;
}

/* ── The fold ─────────────────────────────────────────────────────────────
   ⭐ **CLOSED UNTIL SHE WANTS IT** (2026-09-06). Five controls above every
   visit is most of a phone's first screen, ahead of the writing. The panel
   opens itself when a filter is on — see the template — so a collapsed fold
   can never hide the reason the list is short.
   ⚠️ The summary is a control: 44px, its own focus ring, and the marker
   replaced rather than left to the browser's default triangle. */
.list-filters--fold {
    gap: 0;
}

.list-filters__summary {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    min-height: 44px;
    padding: 0 var(--space-base) 0 0;
    cursor: pointer;
    list-style: none;
    font-size: var(--text-base-sm);
    color: var(--text-color);
    width: fit-content;
}

.list-filters__summary::-webkit-details-marker,
.list-filters__summary::marker {
    content: "";
    display: none;
}

/* The disclosure mark, drawn rather than iconned: one glyph that rotates, so
   there is no second icon to keep in step with the set. */
.list-filters__summary::before {
    content: "";
    width: 0;
    height: 0;
    border-left: 5px solid currentColor;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    transition: transform var(--duration-quick) var(--ease-out);
    flex: none;
}

.list-filters--fold[open] > .list-filters__summary::before {
    transform: rotate(90deg);
}

.list-filters__summary:focus-visible {
    outline: var(--border-width-md) solid var(--primary);
    outline-offset: 2px;
    border-radius: var(--border-radius-sm);
}

.list-filters--fold[open] > .list-filters__controls {
    margin-top: var(--space-md);
}

/* ── The fold, on the toolbar row ─────────────────────────────────────────
   ⭐ **`--inline` PUTS THE SUMMARY ON THE BAR AND THE PANEL OVER THE PAGE.**
   Closed, the fold cost a 44px band of its own above the list plus the gap
   under it — about 68px of the 304px `/entries/` opened on. As a member of
   `.list-toolbar` it costs nothing: it shares the row with the view switch.

   ⛔ **AND THE PANEL MUST NOT PUSH THE LIST DOWN.** A fold in a flex row that
   grows when opened either widens the row or reflows it; both make the bar
   jump under her finger. So the controls are lifted out of flow and hang
   under the summary, the same way the calendar's *Jump to* panel already
   does — see entry-calendar.css `.calendar__reach-panel`, which is where this
   shape is from.

   ⚠️ **THE `max-width` IS ARITHMETIC, NOT A ROUND NUMBER.** The panel is
   anchored to the summary's right edge, which sits at the page column's right
   edge; a panel wider than the column overflows to the LEFT, off screen, with
   no scrollbar to find it by. `100vw` minus the page's two gutters is exactly
   the column, so at any width the left edge lands inside the viewport.

   ⚠️ `margin-top` is reset because the base fold uses it for the gap between
   summary and controls, and here that gap lives in `top` — left in, it would
   double. */
/* ⚠️ **DOUBLE CLASS, ON PURPOSE.** `.list-filters` is restated at (0,2,0)
   because the Pattern-1 phone media query below re-declares `padding` and
   `margin-bottom` on the bare `.list-filters` selector — at equal specificity
   and LATER in the file, so a single-class modifier loses to it under 600px.
   A 16px bottom margin on a flex item in the toolbar row makes the bar taller
   on the one screen this whole change is about. */
.list-filters.list-filters--inline {
    position: relative;
    flex: none;
    margin: 0;
    padding: 0;
    background: none;
    border: 0;
    border-radius: 0;
    display: block;
}

.list-filters.list-filters--inline > .list-filters__summary {
    min-height: 44px;
    padding: 0 var(--space-md);
    background: var(--surface-raised);
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--radius-pill);
    font-size: var(--text-md);
    font-weight: 500;
    white-space: nowrap;
}

@media (hover: hover) {
    .list-filters.list-filters--inline > .list-filters__summary:hover {
        background: var(--surface-hover);
    }
}

.list-filters.list-filters--inline[open] > .list-filters__controls,
.list-filters.list-filters--inline > .list-filters__controls {
    position: absolute;
    top: calc(100% + var(--space-2xs));
    right: 0;
    z-index: 20;
    margin-top: 0;
    width: max-content;
    max-width: min(26rem, calc(100vw - 2 * var(--space-md)));
    padding: var(--space-md);
    background: var(--surface-raised);
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-md);
}

/* Inside a panel the search is a full row rather than a competitor for the
   width; the selects wrap under it. */
.list-filters.list-filters--inline > .list-filters__controls .list-filters__search {
    flex: 1 1 100%;
    min-width: 0;
}

/* ── Pills row ── */
/*
 * ⛔ **THIS WAS THE SETTINGS TAB STRIP BUG, ON FOUR MORE PAGES.** Until Design
 * 2.0 Batch 8 this row was `overflow-x: auto` with `scrollbar-width: none` and
 * a hidden WebKit scrollbar — the exact combination that hid two settings
 * destinations on a 1040px desktop in Batch 6, with nothing on screen to say
 * they were there.
 *
 * ⚠️ **AND IT IS SHARED**: Insights, Prompts, Templates and Relationships all
 * use it. The prompt library has seven subjects plus "Everything", so on a
 * narrow window the last two scrolled off silently — on a desktop, where there
 * is no swipe and no scrollbar to find them with.
 *
 * ⭐ Wrapping instead. Pills are short and there are never many; a second row
 * costs a few pixels, and every filter stays reachable. Horizontal scroll is a
 * fine touch pattern, but not one to keep when the same rule serves a mouse.
 */
.list-filters__pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.filter-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-pill);
    font-size: var(--text-sm);
    font-weight: 500;
    min-height: 44px;
    white-space: nowrap;
    text-decoration: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    background: var(--card-background);
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.filter-pill:hover {
    border-color: var(--accent);
    color: var(--accent-dark);
    background: var(--accent-light);
}

/* ⛔ White on `--accent` (#9CA998) was 2.46:1 — the active pill failed AA
   on every list page. The fill pair is what the primary button uses, and
   dark.css remaps both sides of it. */
.filter-pill--active {
    border-color: var(--accent-fill);
    color: var(--accent-on-fill);
    background: var(--accent-fill);
}

.filter-pill__count {
    font-size: 0.75rem;
    opacity: 0.7;
}

/* ── Controls row (search + dropdowns) ── */
.list-filters__controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

/* ── The search field and the button that submits it ──────────────────────
   ⛔ **THE BUTTON IS NOT DECORATION. WITHOUT IT THERE IS NO WAY TO SEARCH
   ON A PHONE.** A form with no submit button has no submitter for the
   keyboard's Go key to press, and iOS Safari will not submit one — so
   /entries/ and /relationships/ shipped a search field that answered Enter on
   a desktop and did nothing at all on a phone. Reported 2026-09-08.
   ⚠️ `hidden` or `display: none` does not bring it back: the button has to be
   RENDERED to be a submitter. If it ever has to disappear, use the `.sr-only`
   recipe (absolute, 1px, clipped), never `hidden`.
   ⭐ It is visible here because it repairs two more holes at the same time:
   a mouse-only reader had no way to submit the text field either, and neither
   did a keyboard-only reader. `prompt_library.html` has carried this button
   since before Design 2.0, and is the one search on the app nobody has
   complained about. */
.list-filters__search {
    flex: 1;
    min-width: 180px;
    display: flex;
    align-items: center;
    gap: var(--space-2xs);
}

.list-filters__search .filter-input {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
}

.list-filters__go {
    flex: none;
    white-space: nowrap;
}

/* ── Shared input / select ── */
.filter-input,
.filter-select {
    width: 100%;
    padding: 0.625rem 0.75rem;
    font-size: 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--background);
    color: var(--text-color);
    min-height: 44px;
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.filter-input:focus,
.filter-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.filter-input::placeholder {
    color: var(--text-secondary);
}

/* Select: auto-width in inline bar, full-width in sidebar */
.list-filters__controls .filter-select {
    width: auto;
    min-width: 140px;
}

/* ── Active filter indicator ── */
.list-filters__clear {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-decoration: none;
    white-space: nowrap;
}

.list-filters__clear:hover {
    color: var(--primary);
}

/* ── Search result info ── */
.list-filters__result-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.list-filters__result-info a {
    margin-left: 8px;
    color: var(--primary);
}

/* ── Pattern 1 responsive ── */
@media (max-width: 599px) {
    .list-filters {
        padding: 0.75rem;
        margin-bottom: 1rem;
    }

    .list-filters__controls {
        flex-wrap: wrap;
    }

    .list-filters__search {
        min-width: 0;
        flex: 1 1 100%;
    }

    .list-filters__controls .filter-select {
        flex: 1;
        min-width: 0;
        width: auto;
        font-size: 0.85rem;
        padding: 0.5rem 0.5rem;
    }

    .list-filters__clear {
        font-size: 0.8rem;
    }
}

/* ==========================================================================
   PATTERN 2 — Sidebar Filters
   Use for lists with 4+ filter controls or radio/checkbox groups.
   Pages: Entries
   ========================================================================== */

/* ── Layout ── */
.sidebar-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

/* ── Sidebar ── */
.filter-sidebar {
    background: var(--card-background);
    padding: 20px;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    height: fit-content;
}

.filter-sidebar h2 {
    font-size: 1rem;
    margin-bottom: 15px;
}

.filter-section {
    margin-bottom: 20px;
}

.filter-section:last-of-type {
    margin-bottom: 0;
}

.filter-section__label,
.filter-section h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.09em;
    margin-bottom: 10px;
}

/* ── Radio / checkbox groups ── */
.filter-radio-group,
.checkbox-group {
    display: flex;
    flex-direction: column;
    max-height: 200px;
    overflow-y: auto;
}

.filter-radio,
.checkbox-item {
    display: flex;
    align-items: center;
    padding: 6px 0;
    cursor: pointer;
    font-size: 0.9rem;
    min-height: 44px;
}

.filter-radio input,
.checkbox-item input {
    margin-right: 8px;
}

.filter-radio__count,
.checkbox-item .count {
    margin-left: auto;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

/* ── Sidebar actions ── */
.filter-actions {
    display: flex;
    gap: 8px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
    margin-top: 20px;
}

/* ── Mobile toggle ── */
.sidebar-toggle {
    display: none;
    margin-bottom: 1rem;
}

/* ── Sidebar responsive ── */
@media (min-width: 900px) {
    .sidebar-layout {
        grid-template-columns: 250px 1fr;
    }

    .filter-sidebar {
        position: sticky;
        top: 80px;
    }
}

@media (max-width: 899px) {
    .sidebar-toggle {
        display: flex;
    }

    .filter-sidebar {
        display: none;
    }

    .filter-sidebar.show {
        display: block;
    }
}