/* ==========================================================================
   Co-Order Hub — Header Search
   Loaded on every frontend page (search bar lives in the site header).
   ========================================================================== */

/* ── Wrapper ─────────────────────────────────────────────────────────────── */

.coh-header-search {
    position: relative;
    display: flex;
    align-items: center;
    flex-shrink: 1;
    min-width: 0;
}

/* ── Input field ─────────────────────────────────────────────────────────── */

.coh-header-search__field {
    position: relative;
    display: flex;
    align-items: center;
}

.coh-header-search__icon {
    position: absolute;
    left: 9px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: #646970;
    pointer-events: none;
    flex-shrink: 0;
}

.coh-header-search__input {
    display: block;
    width: 200px;
    padding: 6px 10px 6px 32px;
    font-size: 0.875rem;
    line-height: 1.4;
    color: #1d2327;
    background: #f6f7f7;
    border: 2px solid var(--color-accent);
    border-radius: 4px;
    outline: none;
    transition: width 200ms ease, border-color 160ms ease, box-shadow 160ms ease;
    /* Remove browser default search-input decorations */
    -webkit-appearance: none;
    appearance: none;
}

.coh-header-search__input::-webkit-search-cancel-button,
.coh-header-search__input::-webkit-search-decoration {
    -webkit-appearance: none;
}

.coh-header-search__input::placeholder {
    color: #646970;
}

.coh-header-search__input:focus {
    width: 240px;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-accent) 18%, transparent);
    background: #fff;
    outline: none;
}

/* Extra right padding when clear button is visible */
.coh-search-clear:not([hidden]) ~ .coh-header-search__input,
.coh-header-search__input:has(~ .coh-search-clear:not([hidden])) {
    padding-right: 28px;
}

/* ── Clear button ────────────────────────────────────────────────────────── */

.coh-search-clear[hidden] {
    display: none;
}

.coh-search-clear {
    position: absolute;
    right: 7px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3px;
    background: none;
    border: none;
    cursor: pointer;
    color: #646970;
    border-radius: 3px;
    transition: color 120ms ease, background 120ms ease;
    line-height: 0;
}

.coh-search-clear:hover {
    color: #1d2327;
    background: rgba(0, 0, 0, 0.06);
}

/* ── Results dropdown ────────────────────────────────────────────────────── */

.coh-search-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    min-width: 320px;
    max-height: 480px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #dcdcde;
    border-radius: 6px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
    z-index: 500;
    overscroll-behavior: contain;
}

/* Align dropdown to the right when input is near right edge */
.coh-header-search--align-right .coh-search-dropdown {
    left: auto;
    right: 0;
}

/* ── "Press Enter" hint ──────────────────────────────────────────────────── */

.coh-search-enter-hint {
    display: block;
    padding: 8px 14px;
    font-size: 0.8rem;
    color: #646970;
    background: #f6f7f7;
    border-bottom: 1px solid #e8e8e8;
    text-decoration: none;
    font-style: italic;
    transition: background 120ms ease, color 120ms ease;
}

.coh-search-enter-hint:hover {
    background: #f0f6fc;
    color: var(--color-accent);
    text-decoration: none;
}

/* ── Status message (searching / no results) ─────────────────────────────── */

.coh-search-status {
    padding: 12px 14px;
    font-size: 0.875rem;
    color: #646970;
    font-style: italic;
}

/* ── Purchase group ──────────────────────────────────────────────────────── */

.coh-search-group {
    border-bottom: 1px solid #f0f0f1;
}

.coh-search-group:last-child {
    border-bottom: none;
}

/* Purchase title link */
.coh-search-group__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 14px 6px;
    background: #f6f7f7;
}

.coh-search-group__title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #1d2327;
    text-decoration: none;
    letter-spacing: 0.01em;
    text-transform: uppercase;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.coh-search-group__title:hover {
    color: var(--color-accent);
    text-decoration: none;
}

.coh-search-group__view-link {
    font-size: 0.75rem;
    color: var(--color-accent);
    text-decoration: none;
    flex-shrink: 0;
    white-space: nowrap;
}

.coh-search-group__view-link:hover {
    color: #135e96;
    text-decoration: underline;
}

/* Item list */
.coh-search-group__items {
    list-style: none;
    margin: 0;
    padding: 4px 0;
}

/* ── Individual item ─────────────────────────────────────────────────────── */

.coh-search-item__link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 14px;
    text-decoration: none;
    color: inherit;
    transition: background 120ms ease;
}

.coh-search-item__link:hover {
    background: #f0f6fc;
    text-decoration: none;
    color: inherit;
}

.coh-search-item__img {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 3px;
    flex-shrink: 0;
    background: #f6f7f7;
}

.coh-search-item__img--placeholder {
    display: inline-block;
    width: 36px;
    height: 36px;
    background: #f0f0f1;
    border-radius: 3px;
    flex-shrink: 0;
}

.coh-search-item__info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

.coh-search-item__name {
    font-size: 0.875rem;
    color: #1d2327;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.coh-search-item__meta {
    font-size: 0.75rem;
    color: #646970;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.coh-search-item__price {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #1d2327;
    flex-shrink: 0;
    white-space: nowrap;
}

/* "and N more matches" link */
.coh-search-group__more {
    display: block;
    padding: 5px 14px 8px;
    font-size: 0.75rem;
    color: var(--color-accent);
    text-decoration: none;
}

.coh-search-group__more:hover {
    color: #135e96;
    text-decoration: underline;
}

/* ── Search highlight ────────────────────────────────────────────────────── */

.coh-search-highlight {
    background: color-mix(in srgb, var(--color-accent) 15%, transparent);
    color: #135e96;
    border-radius: 2px;
    font-style: normal;
    font-weight: inherit;
    padding: 0 1px;
}

/* ── Scroll-target highlight (after arriving via search link) ────────────── */

.coh-item--search-target {
    animation: coh-item-flash 2s ease forwards;
}

@keyframes coh-item-flash {
    0%   { box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 60%, transparent); background: color-mix(in srgb, var(--color-accent) 7%, transparent); }
    70%  { box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 60%, transparent); background: color-mix(in srgb, var(--color-accent) 7%, transparent); }
    100% { box-shadow: none; background: transparent; }
}

/* ── Search mode toggle ( Search items | By genus ) ─────────────────────── */

.coh-search-mode-toggle {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    white-space: nowrap;
    width: 200px;
}

.coh-search-mode-toggle__btn {
    font-size: 0.75rem;
    color: var(--color-accent);
    text-decoration: none;
    transition: color 120ms ease;
}

.coh-search-mode-toggle__btn:hover {
    color: #135e96;
    text-decoration: underline;
}

.coh-search-mode-toggle__btn--active {
    color: #1d2327;
    font-weight: 500;
    pointer-events: none;
    cursor: default;
}

.coh-search-mode-toggle__btn--active:hover {
    color: #1d2327;
    text-decoration: none;
}

.coh-search-mode-toggle__sep {
    color: #c3c4c7;
    padding: 0 5px;
    font-size: 0.75rem;
    user-select: none;
}

/* ── Genus panel ─────────────────────────────────────────────────────────── */

.coh-genus-panel {
    position: relative;
}

/* Remove left padding reserved for search icon (none in genus filter) */
.coh-genus-filter-input {
    padding-left: 10px;
}

/* ── Genus list (scrollable dropdown below filter input) ─────────────────── */

.coh-genus-list {
    max-height: 280px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.coh-genus-list__item {
    display: block;
    padding: 7px 14px;
    font-size: 0.875rem;
    color: #1d2327;
    text-decoration: none;
    transition: background 120ms ease, color 120ms ease;
}

.coh-genus-list__item:hover {
    background: #f0f6fc;
    color: var(--color-accent);
    text-decoration: none;
}

/* ── Mobile: icon-only, expands on focus ─────────────────────────────────── */

@media (max-width: 767px) {
    .coh-header-search__input {
        width: 160px;
    }

    .coh-header-search__input:focus {
        width: min(320px, 62vw);
    }

    .coh-search-dropdown {
        left: auto;
        right: 0;
        min-width: min(340px, 94vw);
    }
}
