/* Copyright 2022 Oliver Smith
 * SPDX-License-Identifier: MPL-2.0 */

/* Reduce minimum window width */
#urlbar-container {
    min-width: 150px !important;
    flex-shrink: 1 !important;
}

@media (max-width: 700px) {
    /* Remove various buttons left and right of the URL bar:
       - forward-button: also reachable via longpress of back button
       - home-button: not important enough
       - customizableui-special-spring: empty space
       - library-button: also reachable via PanelUI-menu-button
       - sidebar-button: not useful on mobile (we try to gain horizontal space)
       - fxa-toolbar-menu-button: firefox cloud stuff, also reachable via
         #PanelUI-menu-button
    */
    /* #back-button */
    #forward-button,
    /* #reload-button */
    #home-button,
    #customizableui-special-spring1,
    /* (urlbar) */
    #customizableui-special-spring2,
    #library-button,
    #sidebar-button,
    #fxa-toolbar-menu-button
    /* #PanelUI-menu-button */ {
        display: none !important;
    }

    /* Show the forward button if the back button is disabled */
    #back-button[disabled] ~ #forward-button {
        display: initial !important;
    }

    #back-button[disabled] {
        display: none !important;
    }

    #urlbar {
        padding: 0px 5px;
    }

    /* Smaller font: show more of the URL */
    #urlbar-input {
        font-size: 9pt !important;
        padding: 0px 4px !important;
        /* Fade rightmost part with a gradient so it's clear that the URL is truncated */
        mask-image: linear-gradient(to right, black 90%, transparent 100%);
    }

    #urlbar[focused] #urlbar-input {
        mask-image: none;
    }

    #identity-box {
        margin: 0 !important;
    }

    /* urlbar: Hide translate and picture-in-picture icon */
    #urlbar #translations-button, #urlbar #picture-in-picture-button, #urlbar #identity-box #identity-permission-box {
        display: none !important;
    }

    /* Focused urlbar: hide all icons around it, so we have more space to edit the URL */
    #urlbar[focused] #remote-control-box,
    #urlbar[focused] #identity-box,
    #urlbar[focused] #tracking-protection-icon-container,
    /* #urlbar-input */
    #urlbar[focused] #reader-mode-button,
    #urlbar[focused] #page-action-buttons {
        display: none;
    }

    /* Label of "identity icons", e.g. firefox specific pages look weird
     * when ellipsed, e.g. "F..x" instead of "Firefox". So just hide this
     * label. The icon itself is still visible. */
    #identity-icon-label {
        display: none;
    }

    /* Bookmarks toolbar. Firefox shows it for some reason when opening a
     * private browsing window, even if it is not enabled in the normal
     * window view. Hide it for mobile, it eats precious space and can't be
     * organized properly on mobile anyway. Using the searchbar to filter
     * through bookmarks is much more efficient. */
    #PersonalToolbar {
        display: none;
    }

    /* If the bookmarks toolbar is configured to only show on the new tab page,
     * Firefox makes the toolbar overlap the browser. When it's then hidden by
     * the rule above, the urlbar is pushed off the bottom of the window. To
     * prevent this, set the height of the overlapped toolbar to 0. */
    :root {
        --bookmarks-toolbar-overlapping-browser-height: 0 !important;
    }

    vbox.urlbarView
    {
        position: fixed !important;
        bottom: 82px !important;
        box-shadow: rgba(0, 0, 0, 0.05) 0px -8px 8px 3px !important;
        left: 0 !important;
        right: 0 !important;
        border-radius: 0 !important;
        border: none !important;
        width: unset !important;
        margin: 0 !important;
    }

    vbox.urlbarView div#urlbar-results
    {
        display: flex !important;
        flex-direction: column-reverse;
    }

    /* Ensure search results are always shown at the very top */
    vbox.urlbarView div#urlbar-results div[type="search"]
    {
        order: 100 !important;
    }

    vbox.urlbarView div#urlbar-results div.urlbarView-row
    {
        margin-top: 0 !important;
    }

    vbox.urlbarView div#urlbar-results div.urlbarView-row::before
    {
        display: none !important;
    }

    hbox.search-panel-one-offs-header.search-panel-header
    {
        margin-top: 1.5px !important;
    }
}

/* Even though amazon is removed as search engine in policies.json, it gets
 * installed when FF starts for the first time. Hide the button in "This time,
 * search with" inside the urlbar. Match localizations like Amazon.de with this
 * regex. */
button[id^='urlbar-engine-one-off-item-Amazon'] {
    display: none !important;
}
