/**
 * Phones: floating buttons at the bottom instead of Storefront's handheld bar.
 * - Most pages: a round search button on the left (opens .search-sheet) and
 *   "Кошик · 1 450 ₴" on the right while the cart has something in it.
 * - Product pages: "Додати в кошик · 3 000 ₴" (or "Оберіть розмір") and a round
 *   cart button.
 * Hidden from 768px, where the header has search and cart.
 */

.floating-bar,
.search-sheet {
    display: none;
}

@media (max-width: 767px) {
    .floating-bar {
        position: fixed;
        right: 16px;
        bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        left: 16px;
        z-index: 9997;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        pointer-events: none;
    }

    .floating-bar > * {
        pointer-events: auto;
    }

    /* The account icon (or the initials when logged in) moves into the green
       header, before "Menu": it was in the old bottom bar. */
    .site-header .headerAction .headerUserLink,
    .site-header .headerAction .account-menu {
        display: block;
        order: 1;
        margin: 0 4px 0 0;
    }

    .site-header .headerAction #site-navigation {
        order: 2;
    }

    .site-header .headerAction .site-header-cart {
        order: 3;
    }

    .site-header .headerAction .headerUserLink .my-account a {
        padding: 0 8px;
    }

    .site-header .headerAction .headerUserLink .my-account a::before {
        font-size: 22px;
        line-height: 44px;
    }

    /* Room under the footer so the buttons never cover its last lines. */
    .site-footer {
        padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* Storefront's sticky "add to cart" at the top would repeat the floating one. */
    .storefront-sticky-add-to-cart {
        display: none !important;
    }

    .floating-bar__search,
    .floating-bar__cart,
    .floating-bar__buy {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        height: 52px;
        margin: 0;
        border-radius: 26px;
        box-shadow: 0 6px 18px rgba(0, 0, 0, .22);
        font-family: "Roboto", sans-serif;
        font-size: 16px;
        font-weight: 500;
        line-height: 1;
        text-decoration: none;
        cursor: pointer;
        transition: transform .2s ease, opacity .2s ease;
    }

    .floating-bar__search {
        width: 52px;
        padding: 0;
        border: 1px solid #d3d1c7;
        background-color: #fff;
        color: #128108;
    }

    .floating-bar__cart {
        position: relative;
        gap: 8px;
        margin-left: auto;
        padding: 0 20px;
        border: 0;
        background-color: #128108;
        color: #fff;
        white-space: nowrap;
    }

    .floating-bar__cart:hover,
    .floating-bar__cart:focus {
        background-color: #0d5f06;
        color: #fff;
    }

    .floating-bar__cart.is-empty {
        display: none;
    }

    .floating-bar__cart .amount,
    .floating-bar__cart bdi {
        color: inherit;
        font-weight: inherit;
    }

    .floating-bar__count {
        display: none;
    }

    /* Product pages: the buy button takes the width, the cart is a round button. */
    .floating-bar__buy {
        flex: 1 1 auto;
        min-width: 0;
        padding: 0 20px;
        border: 0;
        background-color: #128108;
        color: #fff;
    }

    .floating-bar__buy:hover,
    .floating-bar__buy:focus {
        background-color: #0d5f06;
        color: #fff;
    }

    .floating-bar__buy span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* While the page's own "Додати в кошик" is on screen, the floating one steps aside. */
    .floating-bar__buy.is-hidden {
        opacity: 0;
        pointer-events: none;
        transform: translateY(12px);
    }

    .floating-bar--product .floating-bar__cart {
        width: 52px;
        padding: 0;
        border: 1px solid #d3d1c7;
        background-color: #fff;
        color: #128108;
    }

    .floating-bar--product .floating-bar__cart-text {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(1px, 1px, 1px, 1px);
    }

    .floating-bar--product .floating-bar__count {
        position: absolute;
        top: -4px;
        right: -4px;
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 20px;
        height: 20px;
        padding: 0 5px;
        border-radius: 10px;
        background-color: #128108;
        color: #fff;
        font-size: 12px;
    }

    .floating-bar__search:focus-visible,
    .floating-bar__cart:focus-visible,
    .floating-bar__buy:focus-visible {
        outline: 3px solid #000;
        outline-offset: 2px;
    }

    /* ---- Search sheet ------------------------------------------------------------------- */
    .search-sheet {
        position: fixed;
        inset: 0;
        z-index: 10000;
        display: block;
        background-color: rgba(0, 0, 0, .45);
    }

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

    .search-sheet__panel {
        position: relative;
        max-height: 100%;
        overflow-y: auto;
        padding: calc(16px + env(safe-area-inset-top, 0px)) 16px 24px;
        background-color: #fff;
        box-shadow: 0 12px 24px rgba(0, 0, 0, .2);
    }

    .search-sheet__form {
        display: flex;
        gap: 8px;
        margin: 0 44px 0 0;
    }

    .search-sheet .search-sheet__field {
        flex: 1 1 auto;
        min-width: 0;
        height: 48px;
        padding: 0 16px;
        border: 2px solid #128108;
        border-radius: 24px;
        background-color: #fff;
        color: #1b1b1b;
        font-size: 16px;
        box-shadow: none;
    }

    .search-sheet .search-sheet__field:focus {
        outline: none;
        border-color: #0d5f06;
        background-color: #fff;
    }

    .search-sheet .search-sheet__submit {
        flex: none;
        height: 48px;
        padding: 0 18px;
        border-radius: 24px;
        background-color: #128108;
        color: #fff;
        font-size: 15px;
    }

    .search-sheet .search-sheet__close {
        position: absolute;
        top: calc(18px + env(safe-area-inset-top, 0px));
        right: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        padding: 0;
        border: 0;
        background: transparent;
        color: #1b1b1b;
    }

    .search-sheet__title {
        margin: 24px 0 8px;
        color: #5f5e5a;
        font-size: 13px;
        text-transform: uppercase;
        letter-spacing: .04em;
    }

    .search-sheet__categories {
        margin: 0;
        padding: 0;
        list-style: none;
    }

    .search-sheet__categories a {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 14px 0;
        border-bottom: 1px solid #ededed;
        color: #1b1b1b;
        font-family: "Oswald", sans-serif;
        font-size: 20px;
        text-transform: uppercase;
        text-decoration: none;
    }

    .search-sheet__categories a span {
        color: #5f5e5a;
        font-family: "Roboto", sans-serif;
        font-size: 14px;
    }

    body.is-search-open {
        overflow: hidden;
    }
}

@media (max-width: 767px) and (prefers-reduced-motion: reduce) {
    .floating-bar__search,
    .floating-bar__cart,
    .floating-bar__buy {
        transition: none;
    }
}
