/* Keep the chat header geometry stable while placing search below its divider. */
#chatView #chatHeader.chat-header {
    position: sticky !important;
    top: 0 !important;
    z-index: 3000 !important;
    flex: 0 0 110px !important;
    height: 110px !important;
    min-height: 110px !important;
    box-sizing: border-box !important;
    padding: 0 20px !important;
    overflow: visible !important;
    isolation: isolate;
    border: 0 !important;
    background: var(--bg-dark, var(--bg-primary, #20201f)) !important;
    box-shadow: none !important;
}

/* Keep the header and chat content on one continuous surface. */
#chatView #chatHeader.chat-header::after {
    display: none !important;
    content: none !important;
    pointer-events: none !important;
}

#chatView #chatHeader .header-left-group {
    position: absolute !important;
    top: 0 !important;
    left: 20px !important;
    height: 64px !important;
    display: flex !important;
    align-items: center !important;
    z-index: 2 !important;
}

#chatView #chatHeader .chat-menu {
    position: absolute !important;
    top: 0 !important;
    right: 28px !important;
    width: auto !important;
    height: 64px !important;
    margin: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 10px !important;
    z-index: 3001 !important;
}

/* Keep the Study/Balance control in the right-side action group, just before
   the overflow menu button. */
#chatView #chatHeader .chat-menu .header-mode-switch {
    flex: 0 0 auto !important;
    margin: 0 !important;
}

/* No resting tile: only hover/focus gives the menu a quiet affordance. */
#chatView #chatHeader .chat-menu .menu-btn {
    position: relative !important;
    z-index: 3002 !important;
    width: 32px !important;
    height: 32px !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 8px !important;
    outline: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    color: var(--text-secondary) !important;
    line-height: 1 !important;
}

#chatView #chatHeader .chat-menu .menu-btn:hover,
#chatView #chatHeader .chat-menu .menu-btn:focus-visible {
    background: var(--bg-hover, rgba(255, 255, 255, 0.08)) !important;
    box-shadow: none !important;
}

#chatView #chatHeader .chat-menu .menu-btn:active {
    background: transparent !important;
}

/* The existing collapsed/open behavior is preserved, with a dedicated row below the divider. */
#chatView #chatHeader #chatSearchWrapper,
#chatView .chat-main-area.is-empty #chatHeader #chatSearchWrapper {
    top: 72px !important;
    left: 20px !important;
    right: auto !important;
    z-index: 3002 !important;
    border: 0 !important;
    border-radius: 999px !important;
    box-shadow: none !important;
}

#chatView #chatHeader #chatSearchWrapper.collapsed:hover,
#chatView #chatHeader #chatSearchWrapper.collapsed:focus-within,
#chatView #chatHeader #chatSearchWrapper.is-open {
    border: 0 !important;
    border-radius: 999px !important;
    box-shadow: none !important;
}

/* Empty chats use the same header dimensions as active conversations. */
#chatView .chat-main-area.is-empty #chatHeader {
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: 110px !important;
    min-height: 110px !important;
    border: 0 !important;
    box-shadow: none !important;
}

@media (max-width: 768px) {
    #chatView #chatHeader.chat-header {
        flex-basis: 102px !important;
        height: 102px !important;
        min-height: 102px !important;
        padding: 0 12px !important;
    }

    #chatView #chatHeader .header-left-group {
        left: 12px !important;
        height: 58px !important;
    }

    #chatView #chatHeader .chat-menu {
        right: 16px !important;
        height: 58px !important;
    }

    #chatView #chatHeader #chatSearchWrapper,
    #chatView .chat-main-area.is-empty #chatHeader #chatSearchWrapper {
        top: 66px !important;
        left: 12px !important;
    }

    #chatView .chat-main-area.is-empty #chatHeader {
        height: 102px !important;
        min-height: 102px !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    #chatView #chatHeader #chatSearchWrapper {
        transition: none !important;
    }
}
