.desktop-search {
    display: none;
}

.desktop-search [hidden] {
    display: none !important;
}

.home-search-back { display: none; }

.desktop-search-field {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 112px;
    max-width: 100%;
    height: 42px;
    margin: 0 auto;
    border: 1px solid transparent;
    border-radius: 999px;
    box-sizing: border-box;
    color: var(--text-dim);
    opacity: 0.65;
    cursor: text;
    transition: width 280ms cubic-bezier(0.22, 1, 0.36, 1), background 200ms, border-color 200ms, color 200ms, box-shadow 200ms, opacity 200ms;
}
.desktop-search-field:focus-within {
    border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}
.desktop-search-magnifier {
    position: absolute;
    left: 9px;
    transition: left 280ms cubic-bezier(0.22, 1, 0.36, 1);
    pointer-events: none;
}
.desktop-search-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-dim);
    font-size: 14px;
    font-weight: 500;
    transition: left 280ms cubic-bezier(0.22, 1, 0.36, 1), transform 280ms cubic-bezier(0.22, 1, 0.36, 1);
    pointer-events: none;
}
.desktop-search.is-open:has(#desktopSearchInput:not(:placeholder-shown)) .desktop-search-label {
    visibility: hidden;
}
#desktopSearchInput {
    position: absolute;
    inset: 0;
    width: 100%;
    min-width: 0;
    padding: 0 42px;
    border: 0;
    border-radius: inherit;
    outline: none;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 14px;
    opacity: 0;
    transition: opacity 160ms;
    appearance: none;
}
#desktopSearchInput::-webkit-search-cancel-button {
    appearance: none;
}
#desktopSearchInput::placeholder {
    /* The moving label stays the visible placeholder in every empty state. */
    color: transparent;
}
.desktop-search-clear {
    position: absolute;
    right: 8px;
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border: 0;
    border-radius: 50%;
    background: var(--hover-overlay);
    color: var(--text-dim);
    cursor: pointer;
}
.desktop-search-panel {
    cursor: default;
    margin-top: 10px;
    padding: 8px;
    max-height: min(620px, calc(100dvh - 104px));
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--bg-secondary);
    box-shadow: 0 20px 70px rgb(0 0 0 / 18%);
    animation: desktop-search-appear 180ms cubic-bezier(0.22, 1, 0.36, 1);
}
.desktop-search-heading {
    margin: 12px 12px 10px;
    color: var(--text-dim);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.02em;
}
.desktop-search-tiles {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    padding-bottom: 8px;
}
.desktop-search-option {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    border-radius: 16px;
    background: transparent;
    color: var(--text);
    text-align: left;
    font: inherit;
    cursor: pointer;
}
.desktop-search-option:hover,
.desktop-search-option[aria-selected="true"],
.desktop-search-option:focus-visible {
    outline: none;
    background: var(--hover-overlay);
}
.desktop-search-tile {
    flex-direction: column;
    gap: 8px;
    padding: 12px 6px;
    text-align: center;
}
.desktop-search-icon {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    overflow: hidden;
    border-radius: 12px;
    background: var(--hover-overlay);
    color: var(--text-dim);
    font-size: 21px;
}
.desktop-search-tile .desktop-search-icon {
    width: 52px;
    height: 52px;
    flex-basis: 52px;
    border-radius: 15px;
}
.desktop-search-person .desktop-search-icon {
    border-radius: 50%;
}
.desktop-search-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.desktop-search-copy {
    display: block;
    min-width: 0;
    max-width: 100%;
}
.desktop-search-title,
.desktop-search-subtitle {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    line-height: 19px;
}
.desktop-search-title {
    font-weight: 500;
}
.desktop-search-subtitle {
    color: var(--text-dim);
    font-size: 12px;
}
.desktop-search-status {
    padding: 12px;
    color: var(--text-dim);
    text-align: center;
    font-size: 13px;
    line-height: 21px;
}
.desktop-search-status:empty {
    display: none;
}
.desktop-search-more {
    display: block;
    margin: 4px auto 8px;
    padding: 8px 18px;
    border: 0;
    border-radius: 999px;
    background: var(--hover-overlay);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}
@keyframes desktop-search-appear {
    from { opacity: 0; transform: translateY(-6px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (min-width: 900px) {
    /* Extra space above the wordmark moves the hero and app grid down together. */
    .desktop .home-hero {
        grid-template-rows: minmax(238px, calc(32vh - 20px)) minmax(108px, auto);
    }

    /* The whole padded area reveals the field, well before reaching its label. */
    .desktop-search {
        display: block;
        position: absolute;
        z-index: 9;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: min(520px, calc(100% - 320px));
        padding: 24px 20px 30px;
        box-sizing: border-box;
        cursor: text;
        transition: width 280ms cubic-bezier(0.22, 1, 0.36, 1);
    }

    .desktop-search.is-open {
        width: min(560px, calc(100% - 48px));
    }

    body.anon .desktop-search,
    body.app-active .desktop-search,
    body.chat-open .desktop-search,
    body.sidebar-chat-open .desktop-search,
    body.page-stack-open .desktop-search,
    .desktop.section-open .desktop-search {
        display: none;
    }

    .desktop-search:hover .desktop-search-field,
    .desktop-search:focus-within .desktop-search-field,
    .desktop-search.is-open .desktop-search-field {
        width: 100%;
        color: var(--text);
        opacity: 1;
        background: var(--bg-secondary);
        border-color: var(--border);
        box-shadow: 0 3px 14px rgb(0 0 0 / 4%);
    }

    .desktop-search:hover .desktop-search-magnifier,
    .desktop-search:focus-within .desktop-search-magnifier,
    .desktop-search.is-open .desktop-search-magnifier {
        left: 15px;
    }

    .desktop-search:hover #desktopSearchInput,
    .desktop-search:focus-within #desktopSearchInput,
    .desktop-search.is-open #desktopSearchInput {
        opacity: 1;
    }

    .desktop-search:hover .desktop-search-label,
    .desktop-search:focus-within .desktop-search-label,
    .desktop-search.is-open .desktop-search-label {
        left: 42px;
        transform: translate(0, -50%);
    }

    .desktop-search:hover:has(#desktopSearchInput:not(:placeholder-shown)) .desktop-search-label,
    .desktop-search:focus-within:has(#desktopSearchInput:not(:placeholder-shown)) .desktop-search-label {
        visibility: hidden;
    }

    body.ctrl-chat-hint .desktop-search-field[data-ctrl-num]::after,
    body.ctrl-chat-hint .desktop-search-option[data-ctrl-num]::after {
        content: attr(data-ctrl-num);
        position: absolute;
        display: grid;
        place-items: center;
        width: 16px;
        height: 16px;
        border-radius: 4px;
        background: var(--accent);
        color: #fff;
        font: 700 11px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
        pointer-events: none;
    }
    body.ctrl-chat-hint .desktop-search-field[data-ctrl-num]::after {
        left: calc(100% + 8px);
        top: 50%;
        transform: translateY(-50%);
    }
    body.ctrl-chat-hint .desktop-search-option[data-ctrl-num] { background: var(--hover-overlay); }
    body.ctrl-chat-hint .desktop-search-option[data-ctrl-num]::after { top: 6px; right: 6px; }
}


@media (max-width: 899px) {
    .mobile-home-brand { min-width: 0; }
    #mobileHomeTitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .mobile-home-header.is-searching > :not(.desktop-search) { visibility: hidden; pointer-events: none; }
    .mobile-home-header .desktop-search { display: none; }
    .mobile-home-header.is-searching .desktop-search {
        position: absolute;
        top: calc(env(safe-area-inset-top, 0px) + 14px);
        left: 12px;
        right: 12px;
        display: flex;
        align-items: center;
        gap: 8px;
        height: 44px;
    }
    .home-search-back {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 44px;
        width: 44px;
        height: 44px;
        padding: 0;
        border: 0;
        border-radius: 50%;
        background: var(--hover-overlay);
        color: var(--text);
        cursor: pointer;
    }
    .mobile-home-header .desktop-search-field {
        flex: 1;
        width: 100%;
        min-width: 0;
        height: 44px;
        opacity: 1;
        color: var(--text);
        background: var(--bg-secondary);
        border-color: var(--border);
    }
    .mobile-home-header #desktopSearchInput { opacity: 1; font-size: 16px; }
    .mobile-home-header .desktop-search-magnifier { left: 15px; }
    .mobile-home-header .desktop-search-label { left: 42px; transform: translate(0, -50%); }
    .mobile-home-header .desktop-search-panel {
        position: absolute;
        top: calc(100% + 10px);
        left: 0;
        right: 0;
        margin-top: 0;
        max-height: var(--home-search-available-height, calc(100dvh - var(--mobile-home-header-h) - 12px));
        border-radius: 20px;
        box-sizing: border-box;
        -webkit-overflow-scrolling: touch;
    }
    .mobile-home-header .desktop-search-more { min-height: 44px; }
}

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