/* ── Search input ─────────────────────────────────────────────────────────── */
.sop-document-search {
    position: relative;
    margin: 1rem 0;
}

.sop-search-label {
    display: block;
    font-weight: 600;
    font-size: 1.05rem;
    color: #3a3320;
    margin-bottom: 0.5rem;
    letter-spacing: 0.01em;
}

.sop-corpus-subhead {
    margin: 0 0 0.85rem;
    color: #6b5e3d;
    font-size: 0.95rem;
    line-height: 1.45;
    font-style: italic;
}

.sop-document-search-input {
    width: 100%;
    padding: 0.85rem 1rem 0.85rem 2.6rem;
    border: 1px solid #d6cfb8;
    border-radius: 4px;
    font-size: 1.05rem;
    line-height: 1.4;
    background-color: #fff;
    /* Magnifying-glass icon, inline SVG as data URI — no extra HTTP request */
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239e824b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'/><line x1='21' y1='21' x2='16.65' y2='16.65'/></svg>");
    background-repeat: no-repeat;
    background-position: 0.85rem center;
    background-size: 1.1rem 1.1rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.sop-document-search-input::-webkit-search-cancel-button {
    /* Native clear-button is fine, just slight breathing room */
    margin-left: 0.4rem;
}

.sop-document-search-input:focus {
    outline: none;
    border-color: #9e824b;
    box-shadow: 0 0 0 2px rgba(158, 130, 75, 0.22);
}

/* ── Live dropdown container ─────────────────────────────────────────────── */
.sop-document-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 0.25rem;
    background: #fff;
    border: 1px solid #d0c49a;
    border-radius: 4px;
    z-index: 9999;
    display: block;
    box-shadow: 0 4px 18px rgba(0,0,0,0.11);
}

/* Constrain height so the dropdown never covers the full viewport */
.sop-document-search-results:not(.sop-document-search-results-static) {
    max-height: 480px;
    overflow-y: auto;
}

/* ── Individual result — live dropdown ───────────────────────────────────── */
.sop-document-search-result {
    display: block;
    padding: 0.65rem 0.9rem;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid #f0ece0;
}

.sop-document-search-result:last-of-type {
    border-bottom: none;
}

.sop-document-search-result:hover,
.sop-document-search-result:focus,
.sop-document-search-result.sop-result-active {
    background: #fdf7ec;
    outline: none;
}

.sop-document-search-result:hover .sop-result-title,
.sop-document-search-result:focus .sop-result-title,
.sop-document-search-result.sop-result-active .sop-result-title {
    text-decoration: underline;
}

/* ── Result content ──────────────────────────────────────────────────────── */
.sop-result-title {
    font-size: 1rem;
    font-weight: 600;
    color: #7a5f1a;
    line-height: 1.3;
    margin-bottom: 0.15rem;
}

.sop-result-meta {
    font-size: 0.78rem;
    color: #999;
    margin-bottom: 0.2rem;
    letter-spacing: 0.01em;
}

.sop-result-synopsis {
    font-size: 0.875rem;
    color: #444;
    line-height: 1.45;
}

/* Clamp synopsis to 3 lines inside the live dropdown */
.sop-document-search-results:not(.sop-document-search-results-static) .sop-result-synopsis {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Body-text snippet — shown when the term is in the document body but not
   already visible in the synopsis */
.sop-result-snippet {
    font-size: 0.82rem;
    color: #666;
    font-style: italic;
    line-height: 1.4;
    margin-top: 0.3rem;
    padding-left: 0.6rem;
    border-left: 2px solid #d0c49a;
}

/* ── Footer: "Showing X of Y — See all →" ───────────────────────────────── */
.sop-results-footer {
    padding: 0.5rem 0.9rem;
    font-size: 0.82rem;
    color: #999;
    border-top: 1px solid #f0ece0;
    background: #fdfaf4;
    border-radius: 0 0 4px 4px;
}

.sop-results-footer-link {
    font-weight: 600;
    text-decoration: none;
    color: #7a5f1a;
}

.sop-results-footer-link:hover,
.sop-results-footer-link:focus {
    text-decoration: underline;
}

/* ── Highlight marks ─────────────────────────────────────────────────────── */
mark {
    background: #f2dfa0;
    color: inherit;
    padding: 0 0.1em;
    border-radius: 2px;
}

/* ── Static (server-side) results — full-page list ───────────────────────── */
.sop-document-search-results-static {
    position: static;
    box-shadow: none;
    border: none;
    margin-top: 1.25rem;
}

.sop-results-count {
    font-size: 0.85rem;
    color: #888;
    margin: 0 0 0.5rem;
}

.sop-results-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sop-result-item {
    padding: 1.5rem 0;
    border-bottom: 1px solid #ede9dc;
}

.sop-result-item:first-child {
    padding-top: 1rem;
}

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

.sop-result-link {
    display: block;
    text-decoration: none;
    color: inherit;
}

/* Title gets a stronger entry-point — slightly larger, gold underline only on hover */
.sop-results-list .sop-result-title {
    font-size: 1.15rem;
    line-height: 1.25;
    margin-bottom: 0.25rem;
}

.sop-result-link:hover .sop-result-title,
.sop-result-link:focus .sop-result-title {
    text-decoration: underline;
}

/* ── Pagination ──────────────────────────────────────────────────────────── */
.sop-pagination {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 1.25rem;
    flex-wrap: wrap;
}

.sop-page-link {
    display: inline-block;
    padding: 0.3rem 0.6rem;
    border: 1px solid #d0c49a;
    border-radius: 3px;
    font-size: 0.85rem;
    text-decoration: none;
    color: #7a5f1a;
    background: #fff;
    line-height: 1.4;
}

.sop-page-link:hover,
.sop-page-link:focus {
    background: #fdfaf4;
    border-color: #7a5f1a;
}

.sop-page-current {
    background: #7a5f1a;
    color: #fff;
    border-color: #7a5f1a;
    cursor: default;
}

.sop-page-prev,
.sop-page-next {
    font-weight: 600;
}

/* No-results message on the static search page */
.sop-no-results {
    color: #777;
    font-style: italic;
    margin-top: 0.5rem;
}

/* ── Input row: input and submit button side-by-side ─────────────────────── */
.sop-search-input-row {
    display: flex;
    align-items: stretch;
}

.sop-search-input-row .sop-document-search-input {
    flex: 1 1 0%;
    border-radius: 4px 0 0 4px;
    border-right: none;
    min-width: 0;
}

.sop-search-input-row .sop-search-submit {
    border: 1px solid #9e824b;
    background-color: #9e824b;
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    padding: 0 1.6rem;
    border-radius: 0 4px 4px 0;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.sop-search-input-row .sop-search-submit:hover,
.sop-search-input-row .sop-search-submit:focus {
    background-color: #7a6138;
    border-color: #7a6138;
    outline: none;
}

.sop-search-input-row .sop-search-submit:focus-visible {
    box-shadow: 0 0 0 2px rgba(158, 130, 75, 0.35);
}

/* Pull the input's gold focus ring underneath the button join, otherwise the
   right edge gets a visible gold corner that breaks the joined-component look. */
.sop-search-input-row .sop-document-search-input:focus {
    box-shadow: 0 0 0 2px rgba(158, 130, 75, 0.22);
    clip-path: inset(-3px 0 -3px -3px);
}

/* ── Header search widget — compact input + gold icon button ─────────────── */
.sop-header-search {
    max-width: none;
    margin: 0;
}

.sop-header-search-form {
    display: flex;
    align-items: stretch;
}

.sop-header-search-input {
    flex: 1 1 0%;
    border-radius: 4px 0 0 4px;
    border-right: none;
    min-width: 0;
}

.sop-header-search-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    min-width: 2.5rem;
    background: #7a5f1a;
    border: 1px solid #7a5f1a;
    border-radius: 0 4px 4px 0;
    cursor: pointer;
    color: #fff;
    padding: 0;
    transition: background 0.15s, border-color 0.15s;
}

.sop-header-search-btn:hover,
.sop-header-search-btn:focus {
    background: #614c14;
    border-color: #614c14;
}

.sop-header-search-btn svg {
    width: 1.1rem;
    height: 1.1rem;
    fill: currentColor;
}

/* ── Search filter pills ─────────────────────────────────────────────────── */
.sop-filters-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.85rem;
    align-items: center;
}

/* Each filter is now a single pill (label + select + optional clear-x).
   When JS enhances the filter into a custom dropdown, the pill becomes a
   relative-positioned anchor so the floating listbox can hang off it. */
.sop-filter-bar {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.7rem;
    background: #fff;
    border: 1px solid #d6cfb8;
    border-radius: 999px;
    transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
    white-space: nowrap;
    line-height: 1.2;
}

.sop-filter-bar:hover {
    border-color: #b59b5e;
}

.sop-filter-bar:focus-within {
    border-color: #9e824b;
    box-shadow: 0 0 0 2px rgba(158, 130, 75, 0.18);
}

/* Active pill — when its inner select carries .sop-filter-active */
.sop-filter-bar:has(.sop-filter-active) {
    background: rgba(158, 130, 75, 0.10);
    border-color: #9e824b;
}

.sop-filter-label {
    font-size: 0.78rem;
    color: #8c8060;
    font-weight: 500;
    letter-spacing: 0.01em;
    white-space: nowrap;
    margin: 0;
}

.sop-filter-bar:has(.sop-filter-active) .sop-filter-label {
    color: #6b5e3d;
}

.sop-filter-select {
    border: none;
    background: transparent;
    color: #3a3320;
    font-size: 0.88rem;
    font-family: inherit;
    padding: 0.05rem 1.1rem 0.05rem 0;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    /* Custom chevron — same gold as the input icon */
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239e824b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
    background-repeat: no-repeat;
    background-position: right 0 center;
    background-size: 0.7rem 0.7rem;
    max-width: 22rem;
    text-overflow: ellipsis;
    overflow: hidden;
    line-height: 1.4;
}

.sop-filter-select:focus {
    outline: none;
}

.sop-filter-select.sop-filter-active {
    color: #5a4a2c;
    font-weight: 500;
}

/* ── Custom JS-enhanced trigger button + listbox ─────────────────────────
   Active when sop-document-search.js runs and replaces the native <select>
   with the custom dropdown UI. The button visually replaces the label+select
   inside the pill; the listbox floats below the pill on click. */
.sop-filter-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0;
    border: none;
    background: transparent;
    color: inherit;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    cursor: pointer;
    /* Custom chevron — same as the native <select> styling */
    padding-right: 1.1rem;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239e824b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
    background-repeat: no-repeat;
    background-position: right 0 center;
    background-size: 0.7rem 0.7rem;
}

.sop-filter-trigger:focus {
    outline: none;
}

.sop-filter-trigger .sop-filter-label {
    /* Keep the label styling identical to the un-enhanced pill */
    margin: 0;
}

.sop-filter-trigger .sop-filter-value {
    color: #3a3320;
    font-size: 0.88rem;
    font-weight: 500;
    max-width: 16rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Listbox panel — floats below the pill */
.sop-filter-options {
    position: absolute;
    top: calc(100% + 0.4rem);
    left: 0;
    z-index: 50;
    min-width: 100%;
    max-width: 28rem;
    max-height: 18rem;
    overflow-y: auto;
    margin: 0;
    padding: 0.35rem 0;
    background: #fff;
    border: 1px solid #d6cfb8;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(60, 50, 25, 0.15), 0 2px 6px rgba(60, 50, 25, 0.08);
    list-style: none;
    line-height: 1.4;
}

.sop-filter-options[hidden] {
    display: none;
}

.sop-filter-option {
    padding: 0.5rem 1.1rem;
    font-size: 0.9rem;
    color: #3a3320;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.1s;
}

.sop-filter-option.is-active {
    background: rgba(158, 130, 75, 0.10);
}

.sop-filter-option.is-selected {
    color: #5a4a2c;
    font-weight: 600;
    background: rgba(158, 130, 75, 0.06);
}

.sop-filter-option.is-selected.is-active {
    background: rgba(158, 130, 75, 0.16);
}

.sop-filter-option.is-selected::before {
    content: "✓";
    margin-right: 0.4rem;
    color: #9e824b;
    font-weight: 700;
}

/* When JS-enhanced, the active pill state is driven by aria-expanded on the
   trigger, since :has() on the hidden select still resolves to active even
   when no value is selected (because of how we hide it). Use the trigger
   instead. */
.sop-filter-bar:has(.sop-filter-trigger[aria-expanded="true"]) {
    border-color: #9e824b;
    box-shadow: 0 0 0 2px rgba(158, 130, 75, 0.18);
}

/* Clear-x — small circular button at the right of the pill */
.sop-filter-clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.1rem;
    height: 1.1rem;
    border-radius: 50%;
    color: #9e824b;
    background: rgba(158, 130, 75, 0.18);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 700;
    line-height: 1;
    transition: background-color 0.15s, color 0.15s;
    margin-left: 0.1rem;
}

.sop-filter-clear:hover,
.sop-filter-clear:focus {
    background: #9e824b;
    color: #fff;
    text-decoration: none;
    outline: none;
}

/* ── Highlight bar inside document pages ─────────────────────────────────── */
.sop-highlight-bar {
    background: #fff8e8;
    border: 1px solid #e8d08a;
    border-radius: 3px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.sop-highlight-bar button {
    background: #e8d08a;
    border: 1px solid #d4b96a;
    border-radius: 3px;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    font-size: 0.82rem;
}

.sop-highlight-bar button:hover {
    background: #d4b96a;
}

/* ── Related Documents ───────────────────────────────────────────────────── */
.sop-related-heading {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.sop-related-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sop-related-item {
    border-bottom: 1px solid #ede9dc;
}

.sop-related-item:last-child {
    border-bottom: none;
}

.sop-related-link {
    display: block;
    padding: 0.75rem 0;
    text-decoration: none;
    color: inherit;
}

.sop-related-link:hover .sop-related-title,
.sop-related-link:focus .sop-related-title {
    text-decoration: underline;
}

.sop-related-title {
    font-weight: 600;
    color: #7a5f1a;
    line-height: 1.3;
}

.sop-related-meta {
    font-size: 0.78rem;
    color: #999;
    margin-top: 0.1rem;
}

.sop-related-synopsis {
    font-size: 0.85rem;
    color: #555;
    margin-top: 0.2rem;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ── v1.0.0: chips, did-you-mean, multi-filter bar ────────────────── */

.sop-result-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35em;
    margin-top: 0.7em;
    align-items: center;
}

.sop-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.1em 0.55em;
    font-size: 0.68rem;
    font-weight: 500;
    line-height: 1.45;
    border-radius: 2em;
    color: #6b5a35;
    background: rgba(158, 130, 75, 0.07);
    border: 1px solid rgba(158, 130, 75, 0.18);
}

/* Hidden-overflow chips: revealed when toggle is clicked */
.sop-chips-hidden {
    display: contents;
}
.sop-result-chips:not(.is-expanded) .sop-chips-hidden {
    display: none;
}

.sop-chips-toggle {
    display: inline-flex;
    align-items: center;
    padding: 0.1em 0.55em;
    font-size: 0.68rem;
    font-weight: 500;
    line-height: 1.45;
    border-radius: 2em;
    background: transparent;
    border: 1px dashed rgba(158, 130, 75, 0.35);
    color: #8a7244;
    cursor: pointer;
    font-family: inherit;
}

.sop-chips-toggle:hover,
.sop-chips-toggle:focus {
    background: rgba(158, 130, 75, 0.06);
    border-style: solid;
    outline: none;
}

.sop-result-chips.is-expanded .sop-chips-toggle {
    /* When expanded, the toggle reads "Show fewer" — keep it visible */
    background: rgba(158, 130, 75, 0.05);
}

.sop-chip-tag {
    color: #345e8a;
    background: rgba(52, 94, 138, 0.08);
    border-color: rgba(52, 94, 138, 0.22);
}

.sop-did-you-mean {
    margin-top: 0.6em;
    color: #555;
    font-size: 0.95rem;
}

.sop-did-you-mean a {
    color: #9E824B;
    font-weight: 600;
    text-decoration: none;
    border-bottom: 1px dotted rgba(158, 130, 75, 0.6);
}

.sop-did-you-mean a:hover {
    color: #7a6138;
    border-bottom-style: solid;
}

/* Filter bar — make multiple filters stack cleanly */
.sop-filter-bar + .sop-filter-bar {
    margin-top: 0.4em;
}

/* ── v1.1.0: suggested-concept chip variant ───────────────────────── */

.sop-chip-suggestion {
    color: #8a7244;
    background: rgba(158, 130, 75, 0.04);
    border: 1px dashed rgba(158, 130, 75, 0.45);
    font-style: italic;
}

.sop-chip-suggestion::before {
    content: "?";
    margin-right: 0.3em;
    font-style: normal;
    opacity: 0.6;
    font-weight: 700;
}
