/* Global search component */

#global-search-panel[hidden],
#global-search-results[hidden] {
    display: none !important;
}

.global-search-panel {
    position: relative;
    width: 100%;
    background: #ffffff;
    color: #333333;
    border-bottom: 1px solid #d3d3d3;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    box-sizing: border-box;
}

.global-search-panel *,
.global-search-panel *::before,
.global-search-panel *::after {
    box-sizing: border-box;
}

.global-search-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 20px;
}

.global-search-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.global-search-heading h2 {
    margin: 0;
    padding: 0;
    border: none;
    font-size: 22px;
    line-height: 1.4;
    color: var(--primary-bg-color, #005aad);
}

.global-search-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid #d3d3d3;
    background: #ffffff;
    color: #333333;
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
}

.global-search-close:hover {
    background: #f2f4f6;
}

.global-search-form {
    display: block;
    margin: 0;
    padding: 0;
}

.global-search-scope-wrapper {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
    max-width: 420px;
}

.global-search-scope-wrapper label,
.global-search-input-label {
    display: block;
    font-size: 16px;
    line-height: 1.5;
    font-weight: 500;
    color: #333333;
}

.global-search-scope {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    background: #ffffff;
    border: 1px solid var(--primary-bg-color, #005aad);
    border-radius: 0;
    color: #333333;
    font-family: inherit;
    font-size: 16px;
}

.global-search-input-label {
    margin-bottom: 8px;
}

.global-search-input-row {
    display: flex;
    align-items: stretch;
    gap: 0;
    width: 100%;
}

.global-search-input {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    min-height: 50px;
    padding: 10px 16px;
    border: 1px solid var(--primary-bg-color, #005aad);
    border-radius: 0;
    background: #ffffff;
    color: #333333;
    font-family: inherit;
    font-size: 18px;
    line-height: 1.5;
}

.global-search-submit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    min-height: 50px;
    padding: 12px 24px;
    border: 1px solid #ffd72f;
    border-radius: 0;
    background: #ffd72f;
    color: #333333;
    font-family: inherit;
    font-size: 18px;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}

.global-search-submit:hover {
    background: var(--primary-bg-color, #005aad);
    border-color: var(--primary-bg-color, #005aad);
    color: #ffffff;
}

.global-search-panel :focus-visible {
    outline: 3px solid #005aad;
    outline-offset: 3px;
}

#global-search-toggle:focus-visible {
    outline: 3px solid #ffd72f;
    outline-offset: 4px;
}

#search-box.global-search-focused:focus {
    outline: 3px solid #005aad;
    outline-offset: 3px;
}

.global-search-status {
    font-size: 14px;
    line-height: 1.5;
    color: #555555;
}

.global-search-status:not(:empty) {
    margin-top: 12px;
}

.global-search-results {
    width: 100%;
    max-height: 360px;
    margin-top: 12px;
    overflow-y: auto;
    border: 1px solid #d3d3d3;
    background: #ffffff;
}

.global-search-results ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.global-search-results li {
    margin: 0;
    padding: 0;
    border-bottom: 1px solid #eeeeee;
}

.global-search-results li:last-child {
    border-bottom: none;
}

.global-search-results li a {
    display: block;
    padding: 14px 16px;
    color: #333333;
    font-size: 16px;
    line-height: 1.5;
    text-decoration: none;
    overflow-wrap: anywhere;
}

.global-search-results li a:hover,
.global-search-results li a:focus-visible {
    background: #f2f4f6;
    color: var(--primary-bg-color, #005aad);
}

.global-search-results li a:focus-visible {
    outline-offset: -4px;
}

.global-search-results .highlight,
.global-search-results em,
.global-search-results strong {
    background: #ffffc3;
    font-style: normal;
}

/* Mobile layout */

@media screen and (max-width: 767px) {
    .global-search-container {
        padding: 16px;
    }

    .global-search-heading {
        margin-bottom: 16px;
    }

    .global-search-heading h2 {
        font-size: 20px;
    }

    .global-search-scope-wrapper {
        max-width: none;
    }

    .global-search-input-row {
        flex-direction: column;
        gap: 12px;
    }

    .global-search-input {
        font-size: 16px;
    }

    .global-search-submit {
        display: flex;
        width: 100%;
        font-size: 16px;
    }

    .global-search-results {
        max-height: 300px;
    }

    .global-search-results li a {
        padding: 12px;
        font-size: 14px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .global-search-panel *,
    #global-search-toggle,
    #global-search-toggle * {
        transition: none !important;
    }
}


/* Stage 2: Scoped search interfaces */

.global-search-scope {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    text-overflow: ellipsis;
}

#global-search-status[hidden],
.scoped-search-wrapper #search-status[hidden],
.scoped-search-wrapper #search-results[hidden] {
    display: none !important;
}

/* Inline search wrapper */

.scoped-search-wrapper {
    position: relative;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.scoped-search-wrapper *,
.scoped-search-wrapper *::before,
.scoped-search-wrapper *::after {
    box-sizing: border-box;
}

/* Search form layout */

.scoped-search-wrapper .scoped-search-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
    gap: 0;
    width: 100%;
    max-width: 100%;
    margin: 30px 0 0;
    padding: 0;
    text-align: left;
}

.scoped-search-wrapper .scoped-search-scope-row {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    min-width: 0;
    margin: 0 0 12px;
}

.scoped-search-wrapper .scoped-search-scope-row label {
    display: block;
    margin: 0;
    font-size: 16px;
    font-weight: 500;
    line-height: 1.5;
    color: #333333;
}

.scoped-search-wrapper .global-search-scope {
    display: block;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    min-height: 44px;
    margin: 0;
    font-size: 16px;
    background-color: #ffffff;
    color: #333333;
}

/* Preserve the existing input and button design */

.scoped-search-wrapper .scoped-search-form #search-box {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    height: 50px;
    min-height: 50px;
    margin: 0;
    border-right: 0;
    font-size: 18px;
}

.scoped-search-wrapper .scoped-search-form button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-height: 50px;
    height: 50px;
    margin: 0;
    padding: 10px 24px;
    font-size: 18px;
}

/* Accessible keyboard focus */

.scoped-search-wrapper :focus-visible {
    outline: 3px solid #005aad;
    outline-offset: 3px;
}

.scoped-search-wrapper .scoped-search-form #search-box:focus-visible {
    outline: 3px solid #005aad;
    outline-offset: 3px;
}

/* Search status */

.scoped-search-wrapper .scoped-search-status {
    margin-top: 10px;
    padding: 8px 12px;
    background: #ffffff;
    color: #555555;
    font-size: 14px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

/* Inline suggestion results */

.scoped-search-wrapper #search-results {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    width: 100%;
    max-width: 100%;
    max-height: 360px;
    margin: 8px 0 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    background: #ffffff;
    border: 1px solid #d3d3d3;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
    z-index: 10;
}

.scoped-search-wrapper #search-results ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.scoped-search-wrapper #search-results li {
    margin: 0;
    padding: 0;
    border-bottom: 1px solid #eeeeee;
}

.scoped-search-wrapper #search-results li:last-child {
    border-bottom: none;
}

.scoped-search-wrapper #search-results li a {
    display: block;
    min-height: 44px;
    padding: 12px 16px;
    color: #333333;
    font-size: 16px;
    line-height: 1.5;
    text-decoration: none;
    white-space: normal;
    overflow-wrap: anywhere;
}

.scoped-search-wrapper #search-results li a:hover,
.scoped-search-wrapper #search-results li a:focus-visible {
    background: #f2f4f6;
    color: var(--primary-bg-color, #005aad);
}

.scoped-search-wrapper #search-results li a:focus-visible {
    outline-offset: -4px;
}

/* Allow the homepage search section to grow */

.first-page:has(.scoped-search-wrapper) {
    height: auto;
    min-height: 470px;
    padding-bottom: 24px;
}

.first-page .scoped-search-wrapper {
    max-width: 100%;
}

.first-page .scoped-search-wrapper .scoped-search-scope-row label {
    align-self: flex-start;
    padding: 2px 6px;
    background: #ffffff;
}

/* Full search results */

.text-search:has(.scoped-search-wrapper) {
    min-width: 0;
}

.text-search .scoped-search-current {
    margin: 12px 0;
    font-size: 16px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.text-search .scoped-search-empty {
    margin-top: 20px;
    padding: 20px;
    border: 1px solid #d3d3d3;
    background: #f8f9fa;
    color: #333333;
    overflow-wrap: anywhere;
}

.text-search .scoped-search-empty h3 {
    margin-top: 0;
}

.text-search .scoped-search-empty a {
    color: var(--primary-bg-color, #005aad);
    text-decoration: underline;
}

.text-search .scoped-search-empty a:focus-visible {
    outline: 3px solid #005aad;
    outline-offset: 3px;
}

/* Mobile search layout */

@media screen and (max-width: 767px) {
    .first-page:has(.scoped-search-wrapper) {
        height: auto;
        min-height: 280px;
        padding-bottom: 20px;
    }

    .scoped-search-wrapper .scoped-search-form {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 12px;
        width: 100%;
        margin-top: 20px;
    }

    .scoped-search-wrapper .scoped-search-scope-row {
        grid-column: 1;
        margin-bottom: 0;
    }

    .scoped-search-wrapper .scoped-search-form #search-box {
        width: 100%;
        min-width: 0;
        max-width: 100%;
        padding-right: 12px;
        border-right: 1px solid var(--primary-bg-color, #005aad);
        font-size: 16px;
    }

    .scoped-search-wrapper .scoped-search-form button {
        display: flex;
        width: 100%;
        min-height: 44px;
        font-size: 16px;
    }

    .scoped-search-wrapper #search-results {
        max-height: 300px;
    }

    .scoped-search-wrapper #search-results li a {
        padding: 12px;
        font-size: 14px;
    }

    .text-search .scoped-search-empty {
        padding: 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .scoped-search-wrapper *,
    .scoped-search-wrapper *::before,
    .scoped-search-wrapper *::after {
        transition: none !important;
    }
}
