/* The search box in the top bar and its list of suggestions (NavMenu.razor, js/site-search.js). A global file and not a scoped one: the
   list is drawn by the script, and scoped styles only reach elements that Blazor has drawn. */

.site-search {
    position: relative;
    /* In the middle of the bar on a wide screen (see below); the nav-left rule `margin-right: auto` is cancelled there. */
    order: 2;
    flex: 0 1 26rem;
    min-width: 12rem;
}

/* The bar is three parts: the logo and the menus, the search, the account menu. The two outer parts get the same share of the room
   left over, so the search sits in the middle of the bar and not just between them. The logo is outside the menus (it stays in the
   bar on a phone, where the menus are in a box), so an invisible copy of it after the account menu makes the two sides equally wide. */
@media (min-width: 641px) {
    .top-nav .nav-left {
        order: 1;
        flex: 1 1 0;
        margin-right: 0;
    }

    .top-nav .nav-right {
        order: 3;
        flex: 1 1 0;
        justify-content: flex-end;
    }

    .top-nav:has(.site-search)::after {
        content: "Lrex";
        order: 4;
        visibility: hidden;
        margin-left: 0.75rem;
        font-family: var(--lrex-font-display);
        font-weight: 700;
        font-size: 1.2rem;
    }
}

.site-search-input {
    width: 100%;
    height: 2.35rem;
    padding: 0 2.2rem 0 2.2rem;
    color: var(--lrex-fg);
    background-color: rgba(255, 255, 255, 0.05);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238b98ad' stroke-width='1.6' stroke-linecap='round' viewBox='0 0 16 16'%3E%3Ccircle cx='6.8' cy='6.8' r='4.6'/%3E%3Cpath d='m10.4 10.4 3.8 3.8'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 0.7rem 50%;
    border: 1px solid var(--lrex-line);
    border-radius: 999px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.site-search-input::placeholder {
    color: var(--lrex-muted);
}

.site-search-input:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

.site-search-input:focus {
    background-color: rgba(255, 255, 255, 0.09);
    border-color: var(--lrex-accent);
    box-shadow: 0 0 0 0.15rem rgba(var(--lrex-accent-rgb), 0.25);
}

/* The browser's own clear button for type=search is not styled the same everywhere, so it is left out. */
.site-search-input::-webkit-search-cancel-button {
    -webkit-appearance: none;
}

/* ---------- The list ---------- */

.site-search-list {
    position: absolute;
    top: calc(100% + 0.4rem);
    right: 0;
    left: 0;
    z-index: 30;
    max-height: min(70vh, 32rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0.25rem 0 0.4rem;
    color: var(--lrex-fg);
    background: var(--lrex-surface);
    border: 1px solid var(--lrex-line);
    border-radius: 0.6rem;
    box-shadow: 0 0.8rem 2rem rgba(0, 0, 0, 0.45);
}

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

/* A little wider than the box on a wide screen, so the second line of a hit fits. */
@media (min-width: 641px) {
    .site-search-list {
        left: auto;
        width: max(100%, 24rem);
    }
}

/* Every kind has a heading and a line over it, so it is clear where one kind ends and the next begins. */
.ss-group + .ss-group {
    margin-top: 0.25rem;
    border-top: 1px solid var(--lrex-line);
}

.ss-heading {
    padding: 0.55rem 0.9rem 0.2rem;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--lrex-muted);
}

.ss-hit {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.35rem 0.9rem;
    color: var(--lrex-fg);
    text-decoration: none;
}

.ss-hit:hover, .ss-hit.active {
    background: rgba(var(--lrex-accent-rgb), 0.14);
}

.ss-icon {
    flex: none;
    width: 28px;
    height: 28px;
    object-fit: contain;
    border-radius: 4px;
}

.ss-icon.round {
    object-fit: cover;
    border-radius: 50%;
}

.ss-icon-empty {
    display: grid;
    place-items: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--lrex-muted);
    background: rgba(255, 255, 255, 0.07);
}

.ss-text {
    display: flex;
    min-width: 0;
    flex-direction: column;
    line-height: 1.2;
}

.ss-title {
    overflow: hidden;
    font-size: 0.92rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ss-title mark {
    padding: 0;
    color: var(--lrex-accent);
    background: none;
    font-weight: 700;
}

.ss-sub {
    overflow: hidden;
    font-size: 0.74rem;
    color: var(--lrex-muted);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ss-tip {
    margin: 0.3rem 0.9rem 0;
    padding-top: 0.45rem;
    border-top: 1px solid var(--lrex-line);
    font-size: 0.78rem;
    color: var(--lrex-muted);
}

.ss-all, .ss-clear {
    display: block;
    width: calc(100% - 1.8rem);
    margin: 0.45rem 0.9rem 0;
    padding: 0.4rem 0.6rem;
    color: var(--lrex-accent);
    background: none;
    border: 1px solid var(--lrex-line);
    border-radius: 0.4rem;
    font-size: 0.8rem;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

.ss-all:hover, .ss-clear:hover {
    background: rgba(var(--lrex-accent-rgb), 0.1);
}

/* ---------- Phone: the box is a row of its own under the logo, always shown, and the list takes the whole width ---------- */

@media (max-width: 640px) {
    /* .topbar in front: the phone rules of NavMenu.razor.css (flex-wrap: nowrap, a minimum height) have the same weight as a bare
       .top-nav here, so this needs one more class to be sure to win. */
    .topbar .top-nav {
        flex-wrap: wrap;
        align-content: flex-start;
        align-items: center;
        row-gap: 0.1rem;
        min-height: 0;
        padding-block: 0.35rem 0.6rem;
    }

    .topbar .site-search {
        order: 10;
        flex: 1 0 100%;
    }

    .site-search-input {
        height: 2.6rem;
        /* 16 px stops iOS from zooming the page when the field gets the focus. */
        font-size: 1rem;
    }

    .site-search-list {
        max-height: 60vh;
    }

    .ss-hit {
        padding-block: 0.5rem;
    }
}

/* ---------- The big search in the home page's hero ---------- */

.site-search-hero {
    width: 100%;
    min-width: 0;
    text-align: left;
}

.site-search-hero .site-search-input {
    height: 3.4rem;
    padding: 0 1.2rem 0 3rem;
    font-size: 1.05rem;
    background-position: 1.1rem 50%;
    background-size: 1.15rem;
    background-color: rgba(255, 255, 255, 0.06);
    box-shadow: 0 0.6rem 1.8rem rgba(0, 0, 0, 0.35);
}

.site-search-hero .site-search-input:focus {
    box-shadow: 0 0 0 0.2rem rgba(var(--lrex-accent-rgb), 0.25), 0 0.6rem 1.8rem rgba(0, 0, 0, 0.35);
}

/* The list is as wide as the box here, on a wide screen too. */
.site-search-hero .site-search-list {
    left: 0;
    width: auto;
}
