/**
 * SearchWidget styles — unified search component
 * See docs/architecture/SEARCH_ENGINE_STRATEGY.md.
 * All classes are sw- prefixed; colours use the app's CSS custom properties
 * (styles.css/layout.css) so dark mode keeps working.
 */

.sw-root {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
}

.sw-input-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
}

.sw-input-icon {
    position: absolute;
    left: 0.95rem;
    color: var(--text-light, var(--text-light));
    pointer-events: none;
    font-size: 0.9rem;
}

.sw-input {
    width: 100%;
    min-width: 0;
    padding: 0.72rem 4.6rem 0.72rem 2.7rem;
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: 999px;
    background: var(--card, var(--card));
    color: var(--text, var(--text));
    font-size: 0.9rem;
    font-family: inherit;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
}

.sw-input:focus {
    outline: none;
    border-color: var(--primary, var(--primary));
    box-shadow: 0 0 0 3px rgba(91, 75, 245,  0.12);
}

.sw-input::-webkit-search-cancel-button {
    display: none;
}

.sw-scope-btn {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
    padding: 0.55rem 0.8rem;
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: 999px;
    background: var(--card, var(--card));
    color: var(--text-light, var(--text-light));
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    max-width: 150px;
}

.sw-scope-btn span {
    overflow: hidden;
    text-overflow: ellipsis;
}

.sw-scope-btn.sw-scope-module {
    color: var(--primary, var(--primary));
    border-color: rgba(91, 75, 245,  0.35);
}

.sw-scope-btn i {
    font-size: 0.65rem;
}

.sw-clear-btn,
.sw-filter-btn {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-light, var(--text-light));
    cursor: pointer;
    font-size: 0.8rem;
}

.sw-clear-btn {
    right: 2.6rem;
}

.sw-filter-btn {
    right: 0.75rem;
}

.sw-clear-btn:hover,
.sw-filter-btn:hover,
.sw-filter-btn.active {
    color: var(--primary, var(--primary));
    background: rgba(91, 75, 245,  0.08);
}

.sw-filter-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 15px;
    height: 15px;
    padding: 0 3px;
    border-radius: 999px;
    background: var(--primary, var(--ds-brand-solid));
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    line-height: 15px;
    text-align: center;
}

/* When the filter button is absent the clear button slides right */
.sw-input-row:not(:has(.sw-filter-btn)) .sw-clear-btn {
    right: 0.75rem;
}

/* ------------------------------------------ */
/* Scope menu (desktop dropdown)              */
/* ------------------------------------------ */

.sw-scope-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 10002;
    min-width: 200px;
    background: var(--card, var(--card));
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: 10px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.14);
    overflow: hidden;
}

.sw-scope-menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    padding: 0.65rem 0.9rem;
    border: none;
    background: transparent;
    color: var(--text, var(--text));
    font-size: 0.85rem;
    cursor: pointer;
    text-align: left;
}

.sw-scope-menu-item:hover {
    background: rgba(91, 75, 245,  0.05);
}

.sw-scope-menu-item.active {
    color: var(--primary, var(--primary));
    font-weight: 600;
}

/* Segmented control (mobile overlay) */
.sw-scope-segmented {
    display: flex;
    gap: 0.25rem;
    margin-top: 0.6rem;
    padding: 0.25rem;
    background: rgba(148, 163, 184, 0.12);
    border-radius: 10px;
}

.sw-segment {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-light, var(--text-light));
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
}

.sw-segment.active {
    background: var(--card, var(--card));
    color: var(--primary, var(--primary));
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.1);
}

/* ------------------------------------------ */
/* Chips                                      */
/* ------------------------------------------ */

.sw-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.5rem;
}

.sw-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.4rem 0.2rem 0.65rem;
    border-radius: 999px;
    background: rgba(91, 75, 245,  0.08);
    color: var(--primary, var(--primary));
    font-size: 0.72rem;
    font-weight: 600;
}

.sw-chip button {
    display: flex;
    align-items: center;
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-size: 0.65rem;
    padding: 0.15rem;
    border-radius: 50%;
}

/* ------------------------------------------ */
/* Dropdown / results                         */
/* ------------------------------------------ */

.sw-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    z-index: 10001;
    min-width: 340px;
    max-height: 480px;
    overflow-y: auto;
    background: var(--card, var(--card));
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.15), 0 8px 16px rgba(15, 23, 42, 0.1);
    animation: sw-dropdown-in 0.18s ease-out;
}

@keyframes sw-dropdown-in {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.sw-state {
    padding: 1.75rem;
    text-align: center;
    color: var(--text-light, var(--text-light));
    font-size: 0.88rem;
}

.sw-state i {
    display: block;
    font-size: 1.4rem;
    margin-bottom: 0.6rem;
    color: var(--primary, var(--primary));
}

.sw-state-compact {
    padding: 0.6rem;
    font-size: 0.78rem;
}

.sw-state-compact i {
    display: inline;
    font-size: inherit;
    margin: 0;
}

.sw-group-header {
    position: sticky;
    top: 0;
    padding: 0.7rem 1rem 0.45rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-light, var(--text-light));
    background: var(--card, var(--card));
    border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.sw-group-header i {
    margin-right: 0.45rem;
    color: var(--primary, var(--primary));
}

.sw-group-count {
    margin-left: 0.35rem;
    padding: 0.05rem 0.45rem;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.16);
    font-size: 0.68rem;
}

.sw-result-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid rgba(148, 163, 184, 0.08);
    transition: background 0.12s ease;
}

.sw-result-item:last-of-type {
    border-bottom: none;
}

.sw-result-item:hover,
.sw-result-item.highlighted {
    background: rgba(91, 75, 245,  0.05);
}

.sw-result-icon {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.82rem;
    background: rgba(91, 75, 245,  0.09);
    color: var(--primary, var(--primary));
}

.sw-mod-donations,
.sw-mod-pledges,
.sw-mod-sponsorships,
.sw-mod-goat-sadaqah {
    background: rgba(16, 185, 129, 0.1);
    color: var(--ds-success-text);
}

.sw-mod-invoices,
.sw-mod-items,
.sw-mod-finance,
.sw-mod-legacies {
    background: rgba(245, 158, 11, 0.1);
    color: var(--ds-warning-text);
}

.sw-mod-messaging,
.sw-mod-people,
.sw-mod-partners {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
}

.sw-mod-policies,
.sw-mod-risks,
.sw-mod-committees {
    background: rgba(139, 92, 246, 0.1);
    color: var(--ds-violet-text);
}

.sw-result-content {
    flex: 1;
    min-width: 0;
}

.sw-result-title {
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text, var(--text));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sw-result-meta {
    font-size: 0.74rem;
    color: var(--text-light, var(--text-light));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sw-status-badge {
    flex-shrink: 0;
    padding: 0.14rem 0.5rem;
    border-radius: 4px;
    background: rgba(148, 163, 184, 0.14);
    color: var(--text-light, var(--text-light));
    font-size: 0.68rem;
    text-transform: capitalize;
}

.sw-recent-item .sw-result-icon {
    background: rgba(148, 163, 184, 0.12);
    color: var(--text-light, var(--text-light));
}

.sw-recent-remove {
    border: none;
    background: transparent;
    color: var(--text-light, var(--text-light));
    cursor: pointer;
    padding: 0.3rem;
    border-radius: 50%;
    font-size: 0.75rem;
}

.sw-recent-remove:hover {
    color: var(--ds-danger-text);
}

.sw-footer {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    border-top: 1px solid rgba(148, 163, 184, 0.12);
    background: var(--surface-2);
    color: var(--primary, var(--primary));
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
}

.sw-footer:hover {
    background: rgba(91, 75, 245,  0.06);
}

.sw-footer i {
    margin-left: 0.3rem;
    font-size: 0.72rem;
}

/* ------------------------------------------ */
/* Filter panel                               */
/* ------------------------------------------ */

.sw-filter-panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    z-index: 10002;
    min-width: 320px;
    max-height: 440px;
    overflow-y: auto;
    padding: 1rem;
    background: var(--card, var(--card));
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.15);
    animation: sw-dropdown-in 0.18s ease-out;
}

.sw-filter-title {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-light, var(--text-light));
    margin-bottom: 0.75rem;
}

.sw-filter-title i {
    margin-right: 0.4rem;
    color: var(--primary, var(--primary));
}

.sw-filter-field {
    margin-bottom: 0.8rem;
}

.sw-filter-field > label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text, var(--text));
    margin-bottom: 0.3rem;
}

.sw-filter-control {
    display: flex;
    gap: 0.5rem;
}

.sw-filter-control input[type="text"],
.sw-filter-control input[type="date"],
.sw-filter-control input[type="number"],
.sw-filter-control select {
    flex: 1;
    min-width: 0;
    padding: 0.5rem 0.7rem;
    border: 1px solid rgba(148, 163, 184, 0.3);
    border-radius: 8px;
    background: var(--card, var(--card));
    color: var(--text, var(--text));
    font-size: 0.84rem;
    font-family: inherit;
}

.sw-filter-control input:focus,
.sw-filter-control select:focus {
    outline: none;
    border-color: var(--primary, var(--primary));
}

.sw-multiselect {
    flex-direction: column;
    max-height: 150px;
    overflow-y: auto;
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 8px;
    padding: 0.4rem;
    width: 100%;
}

.sw-multiselect-item {
    display: flex;
    align-items: center;
    padding: 0.3rem 0.4rem;
    font-size: 0.82rem;
    color: var(--text, var(--text));
    cursor: pointer;
    border-radius: 6px;
    text-transform: capitalize;
}

.sw-multiselect-item:hover {
    background: rgba(91, 75, 245,  0.05);
}

.sw-boolean {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.84rem;
    color: var(--text, var(--text));
    cursor: pointer;
}

.sw-filter-actions {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(148, 163, 184, 0.14);
}

.sw-filter-clear {
    padding: 0.5rem 0.9rem;
    border: 1px solid rgba(148, 163, 184, 0.3);
    border-radius: 8px;
    background: transparent;
    color: var(--text-light, var(--text-light));
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
}

.sw-filter-apply {
    padding: 0.5rem 1.2rem;
    border: none;
    border-radius: 8px;
    background: var(--primary, var(--ds-brand-solid));
    color: #fff;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
}

.sw-filter-apply:hover {
    filter: brightness(1.08);
}

/* ------------------------------------------ */
/* Mobile overlay                             */
/* ------------------------------------------ */

.sw-overlay {
    position: fixed;
    inset: 0;
    z-index: 10050;
    background: var(--bg, var(--surface-2));
    display: flex;
    flex-direction: column;
    animation: sw-overlay-in 0.2s ease-out;
}

@keyframes sw-overlay-in {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.sw-overlay-mount {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 0.75rem 1rem;
    padding-top: max(0.75rem, env(safe-area-inset-top));
}

.sw-mobile {
    flex: 1;
    min-height: 0;
}

.sw-back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text, var(--text));
    font-size: 1rem;
    cursor: pointer;
}

.sw-mobile .sw-input {
    padding-right: 4.6rem;
}

.sw-mobile .sw-dropdown {
    position: static;
    flex: 1;
    min-height: 0;
    margin-top: 0.75rem;
    max-height: none;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
    animation: none;
    overflow-y: auto;
}

.sw-mobile .sw-group-header {
    background: transparent;
}

.sw-mobile .sw-result-item {
    background: var(--card, var(--card));
    border: 1px solid rgba(148, 163, 184, 0.14);
    border-radius: 10px;
    margin-bottom: 0.5rem;
}

.sw-mobile .sw-footer {
    border: 1px solid rgba(148, 163, 184, 0.14);
    border-radius: 10px;
    background: var(--card, var(--card));
    margin-top: 0.25rem;
}

/* Filter panel as bottom sheet on mobile */
.sw-mobile .sw-filter-panel {
    position: fixed;
    inset: auto 0 0;
    max-height: 70vh;
    border-radius: 16px 16px 0 0;
    border: none;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
    box-shadow: 0 -12px 32px rgba(15, 23, 42, 0.2);
    animation: sw-sheet-in 0.22s ease-out;
}

@keyframes sw-sheet-in {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

body.sw-overlay-open {
    overflow: hidden;
}

/* ------------------------------------------ */
/* Small screens: top-bar input stays hidden  */
/* (the mobile overlay replaces it)           */
/* ------------------------------------------ */

@media (max-width: 768px) {
    #searchBox {
        display: none !important;
    }
}

/* Module-level search widget mounts are now driven by the unified top-bar
   widget to avoid a duplicated search bar on desktop. */
[data-search-widget].sw-module-mount {
    display: none !important;
}

/* ------------------------------------------ */
/* Full results page (modules/search.html)    */
/* ------------------------------------------ */

.sw-page {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.sw-page-mount {
    max-width: 720px;
}

.sw-page-results {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sw-page-summary {
    font-size: 0.85rem;
    color: var(--text-light, var(--text-light));
}

.sw-page-item {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 0.9rem 1rem;
    background: var(--card, var(--card));
    border: 1px solid rgba(148, 163, 184, 0.16);
    border-radius: 10px;
    cursor: pointer;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.sw-page-item:hover {
    border-color: rgba(91, 75, 245,  0.4);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

.sw-page-load-more {
    align-self: center;
    padding: 0.6rem 1.4rem;
    border: 1px solid rgba(148, 163, 184, 0.3);
    border-radius: 999px;
    background: var(--card, var(--card));
    color: var(--primary, var(--primary));
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

.sw-page-load-more:hover {
    background: rgba(91, 75, 245,  0.06);
}
