/*
 * Search page (custom UI)
 *
 * The search page replaces Pagefind's default UI widget with a custom
 * layout built directly on Pagefind's JS API. The CSS here only styles
 * our own DOM elements — we never load Pagefind's CSS file.
 *
 * Layout responsibility lives in layout.css (the .search-page grid that
 * places the filter sidebar in column 2). This file owns the typography
 * and visual register of the input, results, and filter controls.
 *
 * On wide screens (>=1000px), the layout grid is:
 *   col 1: header, input, status, results
 *   col 2: filters sidebar (always visible)
 * On narrow screens, everything stacks in document order with the
 * filters appearing after the results.
 */

/* On wide screens, the search page has its own grid (not the empty-sidebar
   grid in layout.css). Header, input, status, and results live in the
   reading column on the left; the filter panel sits in the right column
   and spans all rows so it stays at the top regardless of how many
   results render below. */
@media (min-width: 1000px) {
    .search-page {
        display: grid;
        grid-template-columns: minmax(0, var(--reading-width)) 220px;
        column-gap: var(--space-xxl);
    }

    .search-page > *:not(.search-filters) {
        grid-column: 1;
    }

    .search-page > .search-filters {
        grid-column: 2;
        grid-row: 1 / span 999;
        align-self: start;
    }
}

/* Page header — title and hint paragraph */
.search-page-header {
    margin-bottom: var(--space-md);
}

.search-page-title {
    font-family: var(--font-serif);
    font-size: 2.8rem;
    font-weight: 600;
    line-height: 1.1;
    letter-spacing: -0.015em;
    color: var(--color-primary-dark);
    margin-bottom: var(--space-sm);
}

.search-page-hint {
    font-family: var(--font-sans);
    font-size: 0.95rem;
    color: var(--color-ink-muted);
    max-width: 48ch;
}

/* Search input form */
.search-form {
    margin-bottom: var(--space-md);
}

.search-form-label {
    /* Visually hidden but accessible to screen readers */
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.search-input {
    width: 100%;
    font-family: var(--font-sans);
    font-size: 1.05rem;
    padding: 0.7rem 0.9rem;
    background: var(--color-bg);
    color: var(--color-ink);
    border: 1px solid var(--color-border);
    border-radius: 2px;
    outline: none;
    transition: border-color 0.15s ease;
}

.search-input:focus {
    border-color: var(--color-primary);
}

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

/* Status line above results */
.search-status {
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--color-ink-muted);
    margin-bottom: var(--space-md);
    min-height: 1.2em;
}

/* Results list */
.search-results {
    list-style: none;
    margin: 0;
    padding: 0;
}

.search-result {
    padding: var(--space-sm) 0;
    border-bottom: 1px solid var(--color-border);
}

.search-result:last-child {
    border-bottom: none;
}

.search-result-title {
    font-family: var(--font-serif);
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: 0.35rem;
}

.search-result-title a {
    color: var(--color-primary-dark);
    text-decoration: none;
}

.search-result-title a:hover {
    color: var(--color-primary);
    text-decoration: underline;
}

/* Thin horizontal rule between the title and the meta/excerpt block.
   Light enough to feel like punctuation rather than a hard separator. */
.search-result-divider {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 0 0 0.35rem 0;
}

/* Topic and date row. Sans-serif so it's clearly metadata against the
   serif title and excerpt. */
.search-result-meta {
    font-family: var(--font-sans);
    font-size: 0.78rem;
    color: var(--color-ink-muted);
    letter-spacing: 0.01em;
    margin-bottom: 0.3rem;
}

.search-result-excerpt {
    font-family: var(--font-serif);
    font-size: 0.98rem;
    color: var(--color-ink-muted);
    line-height: 1.55;
}

.search-result-excerpt mark {
    background: transparent;
    color: var(--color-primary);
    font-weight: 600;
}

/* Filter sidebar */
.search-filters {
    /* On narrow screens, slot above the results with some breathing room.
       On wide screens, layout.css places this in grid column 2. */
    margin-bottom: var(--space-lg);
}

.search-filters-heading {
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--color-ink-muted);
    padding-bottom: var(--space-xs);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-md);
}

.search-filters-loading {
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--color-ink-muted);
}

/* Each filter group is a <details> element so the user can collapse it.
   Initial open state is set by AXIS_OPEN_BY_DEFAULT in search.js. */
.search-filter-group {
    margin-bottom: var(--space-md);
}

/* The <summary> is the clickable header. Suppress the default disclosure
   triangle and substitute our own caret on the right so the row reads as
   a header rather than a list-item. */
.search-filter-heading {
    font-family: var(--font-sans);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-ink);
    margin-bottom: var(--space-xs);
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
}

.search-filter-heading::-webkit-details-marker {
    display: none;
}

.search-filter-heading::after {
    content: "+";
    font-size: 0.95rem;
    font-weight: 400;
    line-height: 1;
    color: var(--color-ink-muted);
    margin-left: 0.5rem;
}

.search-filter-group[open] > .search-filter-heading::after {
    content: "\2212"; /* minus sign */
}

.search-filter-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.search-filter-item {
    margin: 0.15rem 0;
}

.search-filter-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--color-ink);
    cursor: pointer;
    line-height: 1.4;
}

/* Hide the native checkbox visually but keep it accessible to assistive
   tech and keyboard focus. A custom box is drawn alongside via the
   adjacent .search-filter-box element. */
.search-filter-checkbox {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.search-filter-box {
    flex-shrink: 0;
    width: 13px;
    height: 13px;
    border: 1px solid var(--color-border);
    border-radius: 2px;
    background: var(--color-bg);
    position: relative;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.search-filter-label:hover .search-filter-box {
    border-color: var(--color-primary);
}

.search-filter-checkbox:checked + .search-filter-box {
    background: var(--color-primary);
    border-color: var(--color-primary);
}

.search-filter-checkbox:checked + .search-filter-box::after {
    content: "";
    position: absolute;
    left: 3px;
    top: 0px;
    width: 4px;
    height: 8px;
    border: solid var(--color-bg);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.search-filter-checkbox:focus-visible + .search-filter-box {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

.search-filter-value {
    flex-grow: 1;
    word-break: break-word;
}

.search-filter-count {
    flex-shrink: 0;
    font-size: 0.75rem;
    color: var(--color-ink-muted);
    font-variant-numeric: tabular-nums;
}

/* Narrow-screen adjustments */
@media (max-width: 720px) {
    .search-page-title {
        font-size: 2.1rem;
    }

    .search-input {
        font-size: 1rem;
    }
}
