/* ==================================================
   FILTER BAR (search, result count, sort)
   ==================================================
   Shared by /vibe-coding/ and /articles/. One toolbar on one rule instead
   of boxes inside a box: the magnifier and the placeholder say what it is
   (the labels stay for screen readers), the count and "Sort" sit at the
   right end. The rules follow the category tabs above: the same light
   hairline at rest, and the same 2px ink line as the selected tab while
   the bar is in use (it draws in from the left). Phones: the search takes
   the full width on its own line, the count and sort share the row under
   it.
   Markup:
     .filter-bar[role=search]
       .filter-bar__search > .filter-bar__sr label, input.filter-bar__input,
                             button.filter-bar__clear
       .filter-bar__count
       .filter-bar__sort > .filter-bar__label, select.filter-bar__select
                           (native, or upgraded by js/editorial-dropdown.js)
       button.filter-bar__reset (optional)
   ================================================== */
.filter-bar {
    --fb-ink: var(--ink, #0a0a0a);
    --fb-muted: rgba(10, 10, 10, 0.6);
    /* the category tabs' rule and their selected underline */
    --fb-rule: rgba(0, 0, 0, 0.12);
    --fb-active: #111111;
    --fb-ease: cubic-bezier(0.16, 1, 0.3, 1);
    --fb-height: 56px;
    position: relative;
    display: flex;
    align-items: center;
    gap: 0 20px;
    min-height: var(--fb-height);
    margin: 0;
    padding: 0;
    border: 0;
    border-bottom: 1px solid var(--fb-rule);
    background: transparent;
    color: var(--fb-ink);
    font-family: var(--font-ui, "Rido Neue Haas Text", "Helvetica Neue", Helvetica, Arial, sans-serif);
}

/* In use: the selected tab's 2px ink line draws in over the hairline. */
.filter-bar::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 2px;
    background: var(--fb-active);
    transform: scaleX(0);
    transform-origin: 0 50%;
    transition: transform 250ms var(--fb-ease);
    pointer-events: none;
}

.filter-bar:focus-within::after {
    transform: scaleX(1);
}

.filter-bar__sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- search ---------- */
.filter-bar__search {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    padding: 0;
}

/* the magnifier (Lucide "search"), drawn in ink */
.filter-bar__search::before {
    content: "";
    flex: 0 0 18px;
    width: 18px;
    height: 18px;
    background: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7.5'/%3E%3Cpath d='m20.5 20.5-4.2-4.2'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7.5'/%3E%3Cpath d='m20.5 20.5-4.2-4.2'/%3E%3C/svg%3E") center / contain no-repeat;
}

.filter-bar .filter-bar__input {
    -webkit-appearance: none;
    appearance: none;
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    height: var(--fb-height);
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    color: var(--fb-ink);
    font-family: inherit;
    /* 16px or more, so phones never zoom the page on focus */
    font-size: 17px;
    font-weight: 500;
    line-height: 1.2;
    letter-spacing: -0.01em;
    outline: none;
}

.filter-bar .filter-bar__input::placeholder {
    color: rgba(10, 10, 10, 0.5);
    opacity: 1;
}

/* the bar has its own Clear */
.filter-bar .filter-bar__input::-webkit-search-cancel-button,
.filter-bar .filter-bar__input::-webkit-search-decoration {
    -webkit-appearance: none;
    appearance: none;
}

/* ---------- text buttons: Clear, Reset ---------- */
.filter-bar__clear,
.filter-bar__reset {
    -webkit-appearance: none;
    appearance: none;
    flex: 0 0 auto;
    margin: 0;
    padding: 8px 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--fb-muted);
    font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    text-decoration: underline;
    text-decoration-color: transparent;
    text-underline-offset: 4px;
    cursor: pointer;
    transition:
        color 200ms var(--fb-ease),
        text-decoration-color 200ms var(--fb-ease);
}

.filter-bar__reset {
    color: var(--fb-ink);
}

.filter-bar__clear:hover,
.filter-bar__clear:focus-visible,
.filter-bar__reset:hover,
.filter-bar__reset:focus-visible {
    color: var(--fb-ink);
    text-decoration-color: currentColor;
    outline: none;
}

.filter-bar__clear[hidden],
.filter-bar__reset[hidden] {
    display: none;
}

/* ---------- count ---------- */
.filter-bar__count {
    flex: 0 0 auto;
    margin: 0;
    color: var(--fb-muted);
    font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* ---------- sort ---------- */
.filter-bar__sort {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
    min-width: 0;
    margin: 0;
}

/* a hairline between the count and the sort */
.filter-bar__sort::before {
    content: "";
    width: 1px;
    height: 20px;
    margin-right: 10px;
    background: var(--fb-rule);
}

.filter-bar__label {
    color: var(--fb-muted);
    font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    white-space: nowrap;
}

/* native select (articles): the value and a chevron, no box */
.filter-bar .filter-bar__select:not(.editorial-dropdown__native) {
    -webkit-appearance: none;
    appearance: none;
    width: auto;
    field-sizing: content;
    max-width: 240px;
    height: var(--fb-height);
    margin: 0;
    padding: 0 26px 0 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230a0a0a' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") right center / 14px 14px no-repeat;
    color: var(--fb-ink);
    font-family: inherit;
    font-size: 15px;
    font-weight: 500;
    line-height: 1.2;
    text-overflow: ellipsis;
    cursor: pointer;
}

.filter-bar .filter-bar__select:not(.editorial-dropdown__native):focus {
    outline: none;
}

.filter-bar .filter-bar__select:not(.editorial-dropdown__native):focus-visible {
    outline: 2px solid var(--fb-ink);
    outline-offset: 3px;
}

/* editorial dropdown (catalogue): same look, its own menu */
.filter-bar .editorial-dropdown {
    width: auto;
}

.filter-bar .editorial-dropdown__trigger,
.filter-bar .editorial-dropdown__trigger:hover,
.filter-bar .editorial-dropdown.is-open .editorial-dropdown__trigger,
.filter-bar .editorial-dropdown__trigger:focus-visible {
    border: 0;
    background: transparent;
}

.filter-bar .editorial-dropdown__trigger {
    width: auto;
    min-height: var(--fb-height);
    gap: 12px;
    padding: 0;
    color: var(--fb-ink);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
}

.filter-bar .editorial-dropdown__trigger:focus-visible {
    outline: 2px solid var(--fb-ink);
    outline-offset: 3px;
}

.filter-bar .editorial-dropdown__chevron {
    width: 14px;
    height: 14px;
    border: 0;
    background: currentColor;
    transform: none;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
}

.filter-bar .editorial-dropdown.is-open .editorial-dropdown__chevron {
    transform: rotate(180deg);
}

.filter-bar .editorial-dropdown__menu {
    top: calc(100% + 2px);
    left: auto;
    right: 0;
    min-width: 220px;
    border-color: var(--fb-ink);
}

/* ---------- phones: search on its own line, count + sort under it ---------- */
@media (max-width: 639px) {
    .filter-bar {
        flex-wrap: wrap;
        border-bottom: 0;
    }

    .filter-bar::after {
        content: none;
    }

    .filter-bar__search {
        flex: 1 1 100%;
        border-bottom: 1px solid var(--fb-rule);
        box-shadow: inset 0 -1px 0 transparent;
        transition:
            border-color 250ms var(--fb-ease),
            box-shadow 250ms var(--fb-ease);
    }

    .filter-bar__search:focus-within {
        border-bottom-color: var(--fb-active);
        box-shadow: inset 0 -1px 0 var(--fb-active);
    }

    .filter-bar .filter-bar__input {
        height: 52px;
    }

    /* row two: the count (and Reset, while filters are on) on the left,
       the sort on the right; very narrow screens wrap the sort below */
    .filter-bar {
        gap: 0 14px;
    }

    .filter-bar__count {
        order: 1;
        letter-spacing: 0.08em;
    }

    .filter-bar__reset {
        order: 2;
    }

    .filter-bar__sort {
        order: 3;
        margin-left: auto;
    }

    .filter-bar__sort::before {
        content: none;
    }

    .filter-bar .filter-bar__select:not(.editorial-dropdown__native),
    .filter-bar .editorial-dropdown__trigger {
        height: 48px;
        min-height: 48px;
    }

}

@media (prefers-reduced-motion: reduce) {
    .filter-bar::after,
    .filter-bar__search {
        transition: none !important;
    }
}

html[data-motion="reduced"] .filter-bar::after,
html[data-motion="reduced"] .filter-bar__search {
    transition: none !important;
}
