/* Search styles.
 *
 * Every colour, face and radius comes from the theme's --brand-* custom
 * properties, so a skin recolours all of this by publishing tokens and
 * nothing here has to know which product it is serving. The skin loads
 * after this file (asset order 200 against 100) and can override any rule.
 *
 * The box is one thing: a single bordered field holding the term, where to
 * look and the button, with no borders of their own inside it. That is the
 * whole idea. A scope control sitting beside the box would read as a
 * filter to apply afterwards, and a reader would type first, get the whole
 * site, and never come back to it.
 *
 * What this file decides about results is that a list of them is read, not
 * browsed: one column, generous line height, the title the biggest thing
 * on the row, and no card doing an impression of a shop window. Somebody
 * searching has already said what they want.
 */

/* ── The box, in both sizes ──────────────────────────────────────────── */

.search-box {
    position: relative;
}

.search-box__field {
    display: flex;
    align-items: stretch;
    background: var(--brand-bg);
    border: 1px solid var(--brand-border);
    border-radius: var(--brand-radius);
    transition: border-color .15s ease, box-shadow .15s ease;
}

/* The field carries the focus ring for whatever is inside it, because the
 * field is what a reader sees as the control. */
.search-box__field:focus-within {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-primary) 18%, transparent);
}

/* Named for a screen reader, hidden from a sighted one, which already has
 * the placeholder and the shape of the control. */
.search-box__hidden-label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.search-box__input {
    flex: 1 1 auto;
    min-width: 0;
    padding: .45rem .75rem;
    font: inherit;
    font-size: .9rem;
    color: var(--brand-text);
    background: none;
    border: 0;
    border-radius: inherit;
}

.search-box__input:focus {
    outline: none;
}

.search-box__input::placeholder {
    color: var(--brand-muted);
}

/* Chrome draws its own clear button inside a type=search and puts it in
 * the same corner as the scope control, where the two read as one broken
 * widget. Escape empties the box instead. */
.search-box__input::-webkit-search-cancel-button {
    display: none;
}

/* ── Where to look, inside the same field ────────────────────────────── */

.search-box__scope {
    position: relative;
    display: inline-flex;
    align-items: center;
    /* Gives up width before the input does: the reader is typing in the
       input, and a course name is allowed to end in an ellipsis. */
    flex: 0 1 auto;
    min-width: 0;
    max-width: 10rem;
    overflow: hidden;
    border-inline-start: 1px solid var(--brand-border);
}

.search-box__select {
    /* width, not max-width. A <select> does not shrink below the width of
       its longest option the way text does, so in a narrow header it grew
       past the element holding it and ran under the submit button: measured
       at 132px inside a 106px parent, 27px of it on top of the magnifier.
       Filling the parent instead makes the parent the one that decides. */
    width: 100%;
    min-width: 0;
    max-width: 10rem;
    padding: .35rem 1.6rem .35rem .65rem;
    font: inherit;
    font-size: .82rem;
    color: var(--brand-muted);
    background: none;
    border: 0;
    border-radius: calc(var(--brand-radius) * .6);
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    text-overflow: ellipsis;
}

/* The caret, drawn rather than loaded, so it takes its colour from the
 * theme like everything else here. */
.search-box__scope::after {
    content: "";
    position: absolute;
    inset-inline-end: .6rem;
    width: 0;
    height: 0;
    margin-block-start: .3rem;
    border: .28rem solid transparent;
    border-top-color: var(--brand-muted);
    pointer-events: none;
}

.search-box__submit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    padding-inline: .7rem;
    color: var(--brand-primary);
    background: none;
    border: 0;
    border-radius: inherit;
    cursor: pointer;
}

.search-box__submit:hover {
    color: var(--brand-heading);
}

.search-box__select:focus-visible,
.search-box__submit:focus-visible {
    outline: 2px solid var(--brand-primary);
    outline-offset: -2px;
    border-radius: calc(var(--brand-radius) * .6);
}

/* ── The header box ──────────────────────────────────────────────────── */

.search-box--nav {
    margin-inline-start: auto;
}

.search-box--nav .search-box__field {
    /* The widest control in the bar, deliberately. Searching is what a
       reader came to a wiki of fourteen years of material to do, and a box
       the size of a button reads as an afterthought. It still gives way
       before the brand and the menu do, and collapses to full width on a
       narrow screen. */
    width: clamp(18rem, 38vw, 34rem);
}

/* ── The panel under the header box ──────────────────────────────────── */

.search-box__panel {
    position: absolute;
    top: calc(100% + .5rem);
    inset-inline-end: 0;
    z-index: 60;
    width: min(30rem, calc(100vw - 2.5rem));
    max-height: min(70vh, 32rem);
    overflow-y: auto;
    padding: .75rem;
    background: var(--brand-bg);
    border: 1px solid var(--brand-border);
    border-radius: var(--brand-radius);
    box-shadow: 0 18px 40px color-mix(in srgb, var(--brand-heading) 16%, transparent);
}

.search-box__panel[hidden] {
    display: none;
}

.search-box__status {
    margin: 0 0 .25rem;
    padding-inline: .6rem;
    color: var(--brand-muted);
    font-size: .82rem;
}

.search-box__note:not(:empty) {
    margin: 0 0 .5rem;
    padding: .4rem .6rem;
    color: var(--brand-muted);
    font-size: .8rem;
    border-inline-start: 3px solid var(--brand-accent);
    background: color-mix(in srgb, var(--brand-accent) 8%, transparent);
    border-radius: calc(var(--brand-radius) * .6);
}

.search-box__note:empty {
    display: none;
}

.search-box__list[aria-busy="true"] {
    opacity: .55;
    transition: opacity .12s ease;
}

.search-box__group + .search-box__group {
    margin-block-start: .5rem;
}

.search-box__group-title {
    margin: 0 0 .15rem;
    padding: .3rem .6rem 0;
    color: var(--brand-muted);
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
}

.search-box__result {
    display: block;
    padding: .45rem .6rem;
    color: var(--brand-text);
    border-radius: calc(var(--brand-radius) * .6);
}

/* The pointer and the keyboard land on the same thing, so they look the
 * same. Without that, arrowing down through a list a mouse is also
 * hovering shows two selected rows and neither of them is wrong. */
.search-box__result:hover,
.search-box__result.is-active {
    background: color-mix(in srgb, var(--brand-primary) 10%, transparent);
    text-decoration: none;
}

.search-box__result-title {
    display: block;
    font-family: var(--brand-font-heading);
    font-size: .92rem;
    font-weight: 600;
    color: var(--brand-heading);
}

.search-box__result-snippet {
    /* Two lines of context, because a third turns a panel into a page.
     * The box display is what makes the clamp work, and it lays the
     * snippet out as a block the way display:block would. */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-block-start: .1rem;
    color: var(--brand-muted);
    font-size: .8rem;
    line-height: 1.45;
}

.search-box__all {
    display: block;
    margin-block-start: .5rem;
    padding: .5rem .6rem .2rem;
    color: var(--brand-primary);
    font-size: .85rem;
    font-weight: 600;
    border-block-start: 1px solid var(--brand-border);
}

.search-box__all[hidden] {
    display: none;
}

/* ── The search screen ───────────────────────────────────────────────── */

.search-box--page {
    margin-bottom: 1.5rem;
}

.search-box--page .search-box__field {
    background: var(--brand-surface);
}

.search-box--page .search-box__input {
    padding: .75rem 1rem;
    font-size: 1.05rem;
}

.search-box--page .search-box__select {
    max-width: 14rem;
    font-size: .95rem;
}

.search-box--page .search-box__submit {
    padding-inline: 1.1rem;
}

.search-box--page .search-box__icon {
    width: 20px;
    height: 20px;
}

.search-status {
    color: var(--brand-muted);
    font-size: .95rem;
    margin: 0 0 .35rem;
}

/* An honest note about a degraded answer, told apart from the results by
 * its accent edge rather than by a colour of its own. */
.search-note:not(:empty) {
    color: var(--brand-muted);
    font-size: .9rem;
    margin: 0 0 1.25rem;
    padding: .6rem .9rem;
    border-inline-start: 3px solid var(--brand-accent);
    background: color-mix(in srgb, var(--brand-accent) 8%, transparent);
    border-radius: var(--brand-radius);
}

.search-note:empty {
    display: none;
}

/* Dimmed while a request is in flight, so a reader can see the list is
 * about to change without it jumping around. */
.search-results[aria-busy="true"] {
    opacity: .55;
    transition: opacity .12s ease;
}

/* ── Groups and results ──────────────────────────────────────────────── */

.search-group {
    margin-bottom: 2rem;
}

.search-group__title {
    font-size: 1.1rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--brand-muted);
    margin: 0 0 .75rem;
    padding-bottom: .4rem;
    border-bottom: 1px solid var(--brand-border);
}

.search-group__list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: .25rem;
}

.search-result {
    padding: .75rem .9rem;
    border-radius: var(--brand-radius);
    border: 1px solid transparent;
    transition: border-color .15s ease, background-color .15s ease;
}

.search-result:hover,
.search-result:focus-within {
    background: var(--brand-surface);
    border-color: var(--brand-border);
}

.search-result__title {
    font-family: var(--brand-font-heading);
    font-size: 1.05rem;
    font-weight: 600;
}

.search-result__title:focus-visible {
    outline: 2px solid var(--brand-primary);
    outline-offset: 3px;
    border-radius: 4px;
}

.search-result__snippet {
    color: var(--brand-muted);
    font-size: .92rem;
    margin: .25rem 0 0;
}

/* ── Small screens ───────────────────────────────────────────────────── */

@media (max-width: 820px) {
    /* The header collapses into a stack, and a box that kept its own width
     * there would push the menu off the edge. */
    .search-box--nav {
        width: 100%;
        margin-inline-start: 0;
    }

    .search-box--nav .search-box__field {
        width: 100%;
    }

    .search-box__panel {
        inset-inline: 0;
        width: auto;
    }
}
