/* ── Site search (ported from the SiteArch CMS, themed to Comptrio) ──
   Two surfaces share this file:
     1. The topbar search form + autosuggest dropdown (every public page;
        markup in partials/searchform.php, behavior in search-suggest.js).
     2. The dedicated /search SERP page (template/pages/search.php).
   All colors come from the theme tokens defined in article.css / home.css
   so both dark and light themes work without extra rules here. */

/* ── Topbar search form ── */
.search-form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: relative;
}

.search-form input {
    width: 200px;
    padding: 0.35rem 0.75rem;
    font-family: var(--font);
    font-size: 0.85rem;
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    outline: none;
}

.search-form input::placeholder { color: var(--color-text-dim); }

.search-form input:focus {
    border-color: var(--color-primary);
    background: var(--color-surface-alt);
}

.search-form button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid var(--color-border);
    background: transparent;
    color: var(--color-text-dim);
    cursor: pointer;
    flex-shrink: 0;
}

.search-form button:hover {
    background: var(--color-primary-dim);
    color: var(--color-primary-text);
    border-color: var(--color-primary-text);
}

.search-form button svg { width: 15px; height: 15px; }

/* Topbar is tight on phones; the /search page itself keeps its own bar. */
@media (max-width: 640px) {
    .topbar .search-form {
        display: none;
    }
}

/* ── Autosuggest dropdown (attached to any input[type=search]) ── */
.search-suggestions {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
    margin: 4px 0 0;
    padding: 0;
    list-style: none;
    z-index: 1000;
    max-height: 300px;
    overflow-y: auto;
    text-align: left;
}

.search-suggestions li {
    padding: 8px 16px;
    font-size: 0.85rem;
    color: var(--color-text);
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.search-suggestions li:hover,
.search-suggestions li.selected {
    background-color: var(--color-primary-dim);
    color: var(--color-primary-text);
}

/* In the topbar the input is narrow — give the dropdown room, anchored
   to the right edge so it never overflows the viewport. */
.topbar .search-suggestions {
    width: 300px;
    left: auto;
    right: 0;
}

/* ── SERP page ── */
.search-container {
    width: 100%;
    max-width: 800px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.search-page-form {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    position: relative;
}

.search-page-input {
    flex: 1;
    padding: 0.75rem 1rem;
    font-family: var(--font);
    font-size: 1rem;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    outline: none;
}

.search-page-input::placeholder { color: var(--color-text-dim); }

.search-page-input:focus {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-sm);
}

.search-page-button {
    padding: 0.75rem 1.5rem;
    font-family: var(--font);
    background: var(--color-primary);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 500;
}

.search-page-button:hover { opacity: 0.85; }

/* The SERP form is full-width, so let its dropdown span it too. */
.search-page-form .search-suggestions {
    width: 100%;
}

.search-meta {
    color: var(--color-text-dim);
    font-size: 13px;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border);
}

.search-result {
    display: block;
    padding: 1.25rem;
    margin-bottom: 1rem;
    border-radius: var(--radius);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    text-decoration: none;
    color: inherit;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.search-result:hover {
    background: var(--color-surface-alt);
    border-color: var(--color-primary);
    transform: translateY(-2px);
    text-decoration: none;
}

.search-result h2 {
    text-decoration: none;
    color: var(--color-primary-text);
    margin: 0 0 0.25rem 0;
    font-size: 18px;
    line-height: 1.2;
}

.search-result:hover h2 {
    text-decoration: underline;
}

.search-result-path {
    font-family: 'IBM Plex Mono', 'IBM Plex Mono Fallback', monospace;
    color: var(--color-success);
    font-size: 13px;
    line-height: 16px;
    margin-bottom: 0.25rem;
}

.search-result-excerpt {
    color: var(--color-text-dim);
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
}

.search-result-excerpt::after {
    content: "...";
    color: var(--color-text-muted);
}

.pagination {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border);
}

.page-link,
.page-current {
    min-width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    text-decoration: none;
}

.page-link {
    color: var(--color-primary-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
}

.page-link:hover {
    background: var(--color-primary-dim);
    border-color: var(--color-primary-text);
    text-decoration: none;
}

.page-current {
    background: var(--color-primary);
    color: #fff;
    font-weight: 500;
}
