/**
 * @package     OUI Search Module
 * @subpackage  mod_oui_search
 *
 * @copyright   (C) 2025 Pros.bzh. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

.mod-oui-search {
    position: relative;
    width: 100%;
}

.oui-search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.mod-oui-search .oui-search-input {
    width: 100%;
    padding-right: 2.5rem;
}

.oui-search-loading {
    position: absolute;
    right: 0.75rem;
    display: inline-flex;
    width: 1rem;
    height: 1rem;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    opacity: 0.6;
    animation: oui-search-spin 0.7s linear infinite;
}

.oui-search-loading[hidden] {
    display: none;
}

@keyframes oui-search-spin {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .oui-search-loading {
        animation-duration: 2s;
    }
}

/* Results panel ---------------------------------------------------------- */

.oui-search-results {
    /* JS switches this to position:fixed and sets the coordinates, so the
       panel escapes any ancestor with overflow:hidden/clip. These values are
       the fallback used before the first placement. */
    position: absolute;
    z-index: 1050;
    top: calc(100% + 0.25rem);
    left: 0;
    right: 0;
    max-height: min(60vh, 28rem);
    overflow-y: auto;
    background: #fff;
    color: #1d2b1f;
    border-radius: 0.5rem;
    box-shadow: 0 0.75rem 2rem rgba(0, 0, 0, 0.18);
    text-align: left;
}

.oui-search-results[hidden] {
    display: none;
}

.oui-search-group {
    padding: 0.5rem 0.875rem 0.25rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #6c7a6e;
    background: #f4f6f4;
}

.oui-search-result-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.875rem;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid #eceeec;
}

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

.oui-search-result-item:hover,
.oui-search-result-item.is-active {
    background: #eef4ef;
    color: inherit;
    text-decoration: none;
}

.oui-search-result-item:focus-visible {
    outline: 2px solid #58815f;
    outline-offset: -2px;
}

.oui-search-result-image {
    flex: 0 0 auto;
    width: 2.75rem;
    height: 2.75rem;
    overflow: hidden;
    border-radius: 0.375rem;
    background: #f0f2f0;
}

.oui-search-result-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.oui-search-result-text {
    flex: 1 1 auto;
    min-width: 0;
}

.oui-search-result-title {
    display: block;
    font-weight: 600;
    line-height: 1.3;
}

.oui-search-result-subtitle {
    display: block;
    margin-top: 0.1rem;
    font-size: 0.8rem;
    line-height: 1.35;
    color: #627064;
    /* Long INSEE/venue strings must not stretch the panel */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.oui-search-result-badge {
    flex: 0 0 auto;
    padding: 0.15rem 0.45rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: #40573f;
    background: #e4ece5;
    border-radius: 0.25rem;
    white-space: nowrap;
}

.oui-search-result-item mark {
    padding: 0;
    background: #fdf2ac;
    color: inherit;
}

.oui-search-no-results {
    padding: 0.9rem 0.875rem;
    color: #627064;
    text-align: center;
}

/* Screen-reader-only live region ----------------------------------------- */

.oui-search-status {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Hero search on the homepage ------------------------------------------- */

.accueil-recherche-module {
    margin: 1.25rem 0;
    max-width: 32rem;
}

.accueil-recherche-module .oui-search-input {
    width: 100%;
    padding: 0.9rem 2.75rem 0.9rem 1.25rem;
    font-size: 1rem;
    color: #14261a;
    background: #fff;
    border: 2px solid transparent;
    border-radius: 2rem;
    box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.18);
}

.accueil-recherche-module .oui-search-input:focus {
    border-color: #2f8f8a;
    outline: none;
}

.accueil-recherche-module .oui-search-loading {
    right: 1.1rem;
    color: #14261a;
}

/* Mobile header bar ------------------------------------------------------ */

.app-barre-recherche .oui-search-input {
    width: 100%;
    padding: 0.6rem 2.5rem 0.6rem 0.9rem;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 1.5rem;
}
