header, 
header nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

header {
    width: 100%;
    min-height: var(--header-height);
    padding: 0.9rem 0;
    box-sizing: border-box;
    position: fixed;
    top: 0;
    left: 0;
    /* background-color: #121212; */
    background-color: var(--bg-color);
    z-index: 1000000;
    transition: all 0.2s;

    /* * {
        color: #eee;
    } */

    nav {
        display: flex;
        justify-content: space-between;

        .menu li {
            padding: 0.3rem;
            font-size: var(--small-font-size);
            text-transform: capitalize;
            font-weight: 500;
        }

        .button {
            display: inline-block;
            text-transform: capitalize;
            font-size: var(--small-font-size);
            font-weight: 500;
            background-color: var(--bg-color);
        }
    }

    .logo-area {
        display: flex;
        align-items: center;
        gap: 0.6rem;
    }

    .title {
        font-size: var(--big-font-size);
        font-weight: 700;
        font-family: Forte, Poppins, sans-serif;
    }

    .site-logo {
        display: flex;
        align-items: center;
        max-width: 11rem;

        img {
            max-width: 100%;
            height: auto;
            display: block;
        }
    }

    .alternative-site-logo {
        width: 1.5rem;
    }

    .desc {
        font-size: var(--very-small-text-size);
    }

    #nav-menus[popover] {
        inset: unset;
        top: calc(var(--header-height) + 0.5rem);
        right: 1rem;
        left: auto;
        background-color: transparent;

        .menu {
            width: max-content;
            padding: 1rem;
            display: block;
            background-color: #fff;
            border-radius: 0 0 0 0.5rem;
            box-shadow: 0.3rem 0.6rem 0.9rem rgba(0, 0, 0, 0.2);

            li {
                padding: 0.8rem 0.5rem;
            }
        }
    
        .drop-menu{
            margin-top: 1.5rem;
            min-width: max-content;
            display: none;
            padding: 1rem;
            position: absolute;
            top: 100%;
            right: 0;
            background-color: #fff;
            border-radius: 0.2rem;
            box-shadow: 0.3rem 0.6rem 0.9rem rgba(0, 0, 0, 0.2);
        }
    }

    #nav-menus:hover .drop-menu {
        display: block;
    }

    .search-field {
        display: flex;
        align-items: center;
        gap: 0 1rem;
        justify-content: space-between;
        flex: 1;
        max-width: 26rem;
        transition: max-width 0.3s ease;
    }

    .velaphix-search-wrap {
        position: relative;
        width: 100%;
    }

    #searchform {
        width: 100%;
        min-width: 10rem;
        padding: 0.65rem 0.5rem 0.65rem 0.9rem;
        border: 1px solid #e2e2e2;
        border-radius: 2rem;
        display: flex;
        align-items: center;
        gap: 0.6rem;
        background-color: #f7f7f7;
        box-shadow: 0 0.1rem 0.4rem rgba(0,0,0,0.04);
        overflow: hidden;
        transition: box-shadow 0.25s ease, background-color 0.25s ease;

        .velaphix-search-site-icon {
            width: 1.3rem;
            height: 1.3rem;
            border-radius: 50%;
            flex-shrink: 0;
        }

        .velaphix-search-leading-icon {
            width: 1.1rem;
            stroke: #888;
            flex-shrink: 0;
        }

        input {
            flex: 1;
            width: 100%;
            padding: 0.35rem 0;
            border: none;
            background-color: transparent;
            font-size: var(--normal-font-size);
        }

        #velaphix-search-close {
            display: none;
            width: 1.8rem;
            height: 1.8rem;
            flex-shrink: 0;
            align-items: center;
            justify-content: center;
            background-color: transparent;
            border-radius: 50%;

            .icon {
                width: 1rem;
                stroke: #888;
            }
        }

        #searchsubmit {
            width: 2rem;
            height: 2rem;
            flex-shrink: 0;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            background-color: transparent;

            .icon {
                width: 1.1rem;
                stroke: var(--txt-color);
            }
        }
    }

    #searchform:has(input:focus) {
        background-color: #fff;
        box-shadow: 0 0.3rem 1rem rgba(0,0,0,0.12);
        border-color: var(--primary-color-transparent);
    }

    /* "Expanded / active search" state — toggled by JS on focus.
       The bar grows to take over the header row; on mobile the
       logo and menu icon fade out of the way to give it room. */
    header nav.wrapper.search-active .site-logo,
    header nav.wrapper.search-active #menu-btn {
        opacity: 0;
        width: 0;
        overflow: hidden;
        pointer-events: none;
    }

    header nav.wrapper.search-active .search-field {
        max-width: 100%;
    }

    header nav.wrapper.search-active #velaphix-search-close {
        display: inline-flex;
    }

    .velaphix-search-wrap {
        width: 100%;
        position: relative;
    }

    .velaphix-search-results {
        width: 100%;
        max-height: 22rem;
        overflow-y: auto;
        position: absolute;
        top: calc(100% + 0.6rem);
        left: 0;
        background-color: #fff;
        border-radius: 0.6rem;
        box-shadow: 0 0.6rem 1.5rem rgba(0,0,0,0.15);
        z-index: 999999;
    }

    /* On mobile, break the dropdown out to the true full screen width
       (fixed to the viewport) instead of being constrained to the
       narrow search bar's own width — much easier to read/tap. */
    @media only screen and (max-width: 639px) {
        .velaphix-search-results {
            position: fixed;
            top: var(--header-height);
            left: 0;
            right: 0;
            width: 100vw;
            max-height: calc(100vh - var(--header-height));
            border-radius: 0;
            top: calc(var(--header-height) + 0.5rem);
        }
    }

    .velaphix-search-results .result-item {
        display: flex;
        align-items: center;
        gap: 0.7rem;
        padding: 0.7rem 1rem;
        border-bottom: 1px solid #eee;
        color: inherit;
    }

    .velaphix-search-results .result-item:last-child {
        border-bottom: none;
    }

    .velaphix-search-results .result-item:hover {
        background-color: #f7f7f7;
    }

    .velaphix-search-results .result-item img {
        width: 2.6rem;
        height: 2.6rem;
        object-fit: cover;
        border-radius: 0.4rem;
        flex-shrink: 0;
    }

    /* Keep template names on one line — cut off with "..." rather
       than wrapping to a second line and pushing the list down. */
    .velaphix-search-results .result-item span {
        flex: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        min-width: 0;
    }

    .velaphix-search-results .no-results {
        padding: 0.8rem 1rem;
        font-size: var(--very-small-font-size);
        color: #888;
    }

    /* Recent searches panel */
    .velaphix-search-history .history-heading {
        padding: 0.8rem 1rem 0.4rem;
        font-size: var(--very-small-font-size);
        font-weight: 600;
        color: #888;
        text-transform: uppercase;
        letter-spacing: 0.02em;
    }

    .velaphix-search-history .history-item {
        display: flex;
        align-items: center;
        justify-content: space-between;
        border-bottom: 1px solid #eee;
    }

    .velaphix-search-history .history-item:last-child {
        border-bottom: none;
    }

    .velaphix-search-history .history-term {
        display: flex;
        align-items: center;
        gap: 0.7rem;
        flex: 1;
        min-width: 0;
        padding: 0.7rem 0.5rem 0.7rem 1rem;
        color: inherit;
        cursor: pointer;
    }

    .velaphix-search-history .history-term:hover {
        color: var(--primary-color);
    }

    .velaphix-search-history .history-term .icon {
        width: 1rem;
        height: 1rem;
        flex-shrink: 0;
        color: #999;
    }

    .velaphix-search-history .history-term span {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .velaphix-search-history .history-remove {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0.7rem 1rem;
        flex-shrink: 0;
        color: #999;
    }

    .velaphix-search-history .history-remove:hover {
        color: var(--primary-color);
    }

    .velaphix-search-history .history-remove .icon {
        width: 1rem;
        height: 1rem;
    }

    #menu-btn {
        margin-left: 1rem;
        padding: 0.5rem 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background-color: transparent;

        .icon {
            width: 1.5rem;
            height: 1.5rem;
            stroke: var(--txt-color);
        }
    }
}



@media only screen and (min-width: 770px) {

    header {

        .site-logo {
            max-width: 13rem;
        }

        .title {
            font-size: 1.5rem;
        }

        #menu-btn {
            display: none;
        }
        
        #nav-menus[popover] {
            width: auto;
            display: block;
            position: unset;
            top: unset;

            .menu {
                padding: 0;
                display: flex;
                background-color: transparent;
                box-shadow: unset;
            }

            .menu li:has(.sub-menu) {
                position: relative;

                &:hover .sub-menu {
                    display: block;
                }

                .sub-menu {
                    width: max-content;
                    padding: 1rem;
                    position: absolute;
                    top: calc(100% + 2.2rem);
                    left: 0;
                    display: none;
                    background-color: #fff;
                    border-radius: 0.3rem;
                    box-shadow: 0.1rem 0.2rem 0.2rem rgba(0, 0, 0, 0.1);

                    li {
                        font-size: var(--small-font-size);
                    }

                    &::before {
                        width: 100%;
                        height: 2.5rem;
                        content: "";
                        display: block;
                        position: absolute;
                        top: -33%;
                        left: 0;
                        background-color: transparent;
                    }

                    &::after {
                        content: "";
                        display: inline-block;
                        border: 0.7rem solid;
                        position: absolute;
                        top: -1.3rem;
                        border-color: transparent transparent #fff transparent;
                    }
                }
            }

            .drop-menu {
                margin-top: 0;
                min-width: inherit;
                display: flex;
                align-items: center;
                justify-content: space-between;
                padding: 0;
                position: inherit;
                box-shadow: none;
            }
        }

        .search-field {
            max-width: 30rem;

            #searchform {
                min-width: 30rem;
            }
        }

        /* On desktop, keep the logo and menu visible when searching
           — only the bar itself grows wider, nothing fades away. */
        .search-active {
            .site-logo,
            #menu-btn {
                opacity: 1;
                width: auto;
                pointer-events: auto;
            }

            .search-field {
                max-width: 34rem;
            }
        }
    }

    header #nav-menus:hover .drop-menu {
        display: flex;
    }

    header #nav-menus ul {
        display: flex;
        align-items: center;
        gap: 1rem;
    }

    header nav .button {
        display: none;
    }

}