/* NSA custom search — replaces Ghost's sodo-search.
   Themed entirely with Meridian's own CSS variables, so it follows the active
   colour scheme, paper palette, and dark mode automatically. Structural rules
   are hand-written (not Tailwind) so nothing depends on the Vite build. */

.nsa-search-overlay {
    position: fixed;
    inset: 0;
    z-index: 2147483000;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: max(8vh, 2.5rem) 1rem 1rem;
    background: rgba(0, 0, 0, 0.45);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity .15s ease;
}
/* The hard show/hide is the [hidden] attribute (display:none). We deliberately
   do NOT use `visibility:hidden` here — an element inside a visibility:hidden
   ancestor can't take programmatic focus, which would break autofocus on open. */
.nsa-search-overlay[hidden] { display: none; }
.nsa-search-overlay.is-open { opacity: 1; }

.nsa-search-modal {
    width: min(640px, 100%);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    background: var(--color-paper);
    color: var(--color-ink);
    border: 1px solid var(--color-rule);
    box-shadow: 0 24px 60px -12px rgba(0, 0, 0, .45);
    transform: translateY(-8px);
    transition: transform .15s ease;
}
.nsa-search-overlay.is-open .nsa-search-modal { transform: translateY(0); }

.nsa-search-field {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .9rem 1rem;
    border-bottom: 1px solid var(--color-rule);
}
.nsa-search-field svg { flex: none; color: var(--color-ink-3); }

/* field icon: magnifier by default, spinner while a query is in flight */
.nsa-search-icon { flex: none; position: relative; width: 15px; height: 15px; }
.nsa-search-glass { display: block; }
.nsa-search-spin {
    display: none;
    box-sizing: border-box;
    width: 15px;
    height: 15px;
    border: 2px solid var(--color-rule);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: nsa-search-spin .6s linear infinite;
}
.nsa-search-overlay.is-searching .nsa-search-glass { display: none; }
.nsa-search-overlay.is-searching .nsa-search-spin { display: block; }
@keyframes nsa-search-spin { to { transform: rotate(360deg); } }
.nsa-search-input {
    flex: 1 1 auto;
    min-width: 0;
    border: 0;
    background: transparent;
    color: var(--color-ink);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.4;
    outline: none;
}
.nsa-search-input::placeholder { color: var(--color-ink-faint); }
.nsa-search-input::-webkit-search-cancel-button { -webkit-appearance: none; }
/* right-side controls: clear-text (only with text) + close */
.nsa-search-clear-input,
.nsa-search-close {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: transparent;
    cursor: pointer;
    padding: 0;
}
.nsa-search-close svg { display: block; }
/* clear: a small text button shown only when the box has text */
.nsa-search-clear-input {
    display: none;
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 600;
    color: var(--color-ink-mute);
    padding: .15rem .3rem;
    border-radius: 3px;
}
.nsa-search-overlay.has-text .nsa-search-clear-input { display: inline-flex; }
.nsa-search-clear-input:hover { color: var(--color-accent); }
/* close: replaces the old "Esc" label */
.nsa-search-close {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    color: var(--color-ink-faint);
}
.nsa-search-close:hover { color: var(--color-accent); }

.nsa-search-results { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.nsa-search-status {
    padding: 1.25rem 1rem;
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--color-ink-mute);
}

/* section label ("Authors" / "Articles") */
.nsa-search-section {
    padding: .7rem 1rem .35rem;
    font-family: var(--font-sans);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--color-ink-faint);
}

/* shared result row (posts + authors) */
.nsa-search-result {
    display: flex;
    gap: .75rem;
    padding: .8rem 1rem;
    border-bottom: 1px solid var(--color-rule);
    text-decoration: none;
    color: inherit;
}
.nsa-search-result:last-child { border-bottom: 0; }
.nsa-search-result:hover,
.nsa-search-result.is-active { background: var(--color-paper-2); }

.nsa-search-body { min-width: 0; flex: 1 1 auto; }

/* article rows */
.nsa-search-thumb {
    flex: none;
    width: 56px;
    height: 56px;
    object-fit: cover;
    background: var(--color-paper-3);
}
.nsa-search-title {
    display: block;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 15px;
    line-height: 1.3;
    color: var(--color-ink);
    margin: 0 0 .15rem;
}
.nsa-search-excerpt {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-family: var(--font-sans);
    font-size: 12.5px;
    line-height: 1.45;
    color: var(--color-ink-3);
    margin: 0 0 .25rem;
}
.nsa-search-meta {
    display: block;
    font-family: var(--font-sans);
    font-size: 11px;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--color-ink-mute);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* author rows */
.nsa-search-author { align-items: center; }
.nsa-search-avatar {
    flex: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--color-paper-3);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 15px;
    color: var(--color-ink-3);
}
.nsa-search-author-name {
    display: block;
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 14px;
    line-height: 1.3;
    color: var(--color-ink);
}

/* topic (tag) rows */
.nsa-search-tag { align-items: center; }
.nsa-search-tag-icon {
    flex: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-paper-3);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 18px;
    color: var(--color-ink-faint);
}
.nsa-search-tag-name {
    display: block;
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 14px;
    line-height: 1.3;
    color: var(--color-ink);
}

.nsa-search-title mark,
.nsa-search-excerpt mark,
.nsa-search-author-name mark,
.nsa-search-tag-name mark {
    background: transparent;
    color: var(--color-accent);
    font-weight: 700;
}

/* topic row + its "add filter" button share one divider */
.nsa-search-tagrow {
    display: flex;
    align-items: stretch;
    border-bottom: 1px solid var(--color-rule);
}
.nsa-search-tagrow:last-child { border-bottom: 0; }
.nsa-search-tagrow .nsa-search-result { flex: 1 1 auto; border-bottom: 0; }
.nsa-search-add {
    flex: none;
    align-self: center;
    margin: 0 1rem;
    font-family: var(--font-sans);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .03em;
    white-space: nowrap;
    color: var(--color-ink-mute);
    background: transparent;
    border: 1px solid var(--color-rule);
    border-radius: 999px;
    padding: .2rem .55rem;
    cursor: pointer;
    transition: color .12s ease, border-color .12s ease;
}
.nsa-search-add:hover { color: var(--color-accent); border-color: var(--color-accent); }

/* active filter chips */
.nsa-search-facets {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .4rem;
    padding: .6rem 1rem;
    border-bottom: 1px solid var(--color-rule);
}
.nsa-search-facets[hidden] { display: none; }
.nsa-search-facets-label {
    font-family: var(--font-sans);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--color-ink-faint);
    margin-right: .15rem;
}
.nsa-search-chip {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 600;
    color: var(--color-accent);
    background: var(--color-accent-tint);
    border-radius: 999px;
    padding: .2rem .25rem .2rem .6rem;
}
.nsa-search-chip-x {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: inherit;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}
.nsa-search-chip-x:hover { background: rgba(0, 0, 0, .08); }
.nsa-search-clear {
    font-family: var(--font-sans);
    font-size: 11px;
    color: var(--color-ink-mute);
    background: transparent;
    border: 0;
    cursor: pointer;
    text-decoration: underline;
    padding: .2rem .3rem;
}
.nsa-search-clear:hover { color: var(--color-accent); }

html.nsa-search-open, body.nsa-search-open { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
    .nsa-search-overlay, .nsa-search-modal { transition: none; }
    .nsa-search-spin { animation: none; }
}
