/* ==========================================================================
   Mobile app shell — phones only (max-width: 768px). Desktop never sees it.

   Loaded last in <head> by both layouts (frontend/layouts/header.blade.php and
   admin/layouts/header.blade.php), so it settles the things every page shares:
   the header, the red bottom nav, everything that floats above it, form
   controls, and Bootstrap modals (shown as bottom sheets here).

   Floating buttons and sticky action bars use the tokens below instead of
   their own magic numbers, so they always stack above the bottom nav and the
   iPhone home-indicator area.
   ========================================================================== */

@media (max-width: 768px) {
    :root {
        --m-nav-h: 58px;                                   /* the red bar itself */
        --m-safe-b: env(safe-area-inset-bottom, 0px);
        /* In a browser tab the browser's own bar sits above the page, so the
           header needs no top inset; only an installed web app (below) draws
           under the status bar. */
        --m-safe-t: 0px;
        --m-nav-total: calc(var(--m-nav-h) + var(--m-safe-b));
        --m-bump: 24px;                                    /* how far the Sell circle rises */
        --m-float-b: calc(var(--m-nav-total) + 14px);      /* round buttons at the sides */
        --m-float-center-b: calc(var(--m-nav-total) + var(--m-bump) + 12px); /* pills in the middle */
        --m-gutter: 12px;
        --m-radius: 14px;
        --m-red: #e40f15;
    }

    @media (display-mode: standalone), (display-mode: fullscreen) {
        :root {
            --m-safe-t: env(safe-area-inset-top, 0px);
        }
    }

    /* AnudaLive app: the app keeps the WebView clear of the status bar and
       the gesture bar itself (Flutter SafeArea), but newer Android WebViews
       still report those insets, which would add an empty band on top. */
    html.in-anuda-app {
        --m-safe-t: 0px;
        --m-safe-b: 0px;
    }

    /* No sideways page scroll. `clip` (not `hidden`) keeps the sticky header working. */
    html,
    body {
        overflow-x: clip;
    }

    body {
        -webkit-tap-highlight-color: rgba(228, 15, 21, 0.12);
        /* The last bit of every page stays above the bottom nav. */
        padding-bottom: var(--m-nav-total);
    }

    /* ---- Header ---------------------------------------------------------- */

    header.topbar {
        padding-top: var(--m-safe-t);
    }

    /* Stuck header is solid white (the footer script swaps in the dark logo
       for this state), so cards never show through it. */
    header.topbar.sticky {
        background: #fff;
        border-bottom: 0;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.14);
    }

    /* ---- Bottom nav ------------------------------------------------------ */

    .mobile-menus {
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        padding-bottom: var(--m-safe-b);
        border-top: 0;
        box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.14);
    }

    .mobile-menus ul {
        height: var(--m-nav-h);
        margin: 0;
        padding: 0;
        align-items: stretch;
    }

    .mobile-menus ul li {
        position: relative;
        flex: 1 1 0;
        width: auto;
        display: flex;
    }

    .mobile-menus ul li a {
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        min-width: 0;
        padding: 6px 2px 5px;
        color: #fff;
        text-decoration: none;
    }

    .mobile-menus ul li a i {
        font-size: 20px;
        line-height: 1;
        padding-bottom: 0;
    }

    .mobile-menus ul li a img {
        width: 24px;
        height: 24px;
        border-radius: 50%;
        object-fit: cover;
    }

    .mobile-menus ul li a p {
        margin: 0;
        max-width: 100%;
        overflow: hidden;
        font-size: 11px;
        line-height: 13px;
        white-space: nowrap;
        text-overflow: ellipsis;
    }

    .mobile-menus ul li a:active {
        background: rgba(0, 0, 0, 0.08);
    }

    /* The raised Sell circle sits inside its own slot, not against the page. */
    .mobile-menus .msellbtn {
        justify-content: flex-end;
    }

    .mobile-menus .msellbtn i {
        position: absolute;
        top: calc(-1 * var(--m-bump));
        bottom: auto;
        left: 50%;
        right: auto;
        width: 54px;
        height: 54px;
        margin: 0;
        transform: translateX(-50%);
        border: 3px solid var(--m-red);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
        font-size: 26px !important;
    }

    .mobile-menus .msellbtn p {
        position: static;
        bottom: auto;
    }

    /* A modal or the side menu is open: the nav steps back instead of covering it. */
    body.modal-open .mobile-menus {
        visibility: hidden;
    }

    /* ---- Things that float above the nav --------------------------------- */

    #scroll {
        right: var(--m-gutter);
        bottom: var(--m-float-b) !important;
        width: 44px;
        height: 44px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    }

    .b24-widget-button-wrapper {
        bottom: calc(var(--m-float-b) + 54px) !important;
    }

    /* ---- Form controls ---------------------------------------------------- */

    /* 16px stops iPhone Safari from zooming the page when a field gets focus. */
    input[type="text"],
    input[type="search"],
    input[type="tel"],
    input[type="email"],
    input[type="number"],
    input[type="password"],
    input[type="url"],
    input[type="date"],
    input[type="datetime-local"],
    input[type="time"],
    input:not([type]),
    select,
    textarea {
        font-size: 16px !important;
    }

    .form-control,
    .form-select {
        min-height: 44px;
    }

    textarea.form-control {
        min-height: 88px;
    }

    .btn:not(.btn-close):not(.btn-link) {
        min-height: 44px;
    }

    .btn-sm:not(.btn-close):not(.btn-link) {
        min-height: 38px;
    }

    /* ---- Bootstrap modals as bottom sheets ---------------------------------
       Add .modal-keep-center to a .modal to keep the old centred box. */

    .modal:not(.modal-keep-center) .modal-dialog:not(.modal-fullscreen) {
        display: flex;
        align-items: flex-end;
        width: 100%;
        max-width: none;
        min-height: 100%;
        margin: 0;
    }

    .modal.fade:not(.modal-keep-center) .modal-dialog:not(.modal-fullscreen) {
        transform: translateY(100%);
        transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
    }

    .modal.show:not(.modal-keep-center) .modal-dialog:not(.modal-fullscreen) {
        transform: none;
    }

    .modal:not(.modal-keep-center) .modal-dialog:not(.modal-fullscreen) .modal-content {
        width: 100%;
        max-height: 92vh;
        max-height: 92dvh;
        border: 0;
        border-radius: 20px 20px 0 0;
        padding-bottom: var(--m-safe-b);
        box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.2);
    }

    /* Grab handle, so it reads as a sheet. */
    .modal:not(.modal-keep-center) .modal-dialog:not(.modal-fullscreen) .modal-content::before {
        content: "";
        display: block;
        flex: 0 0 auto;
        width: 40px;
        height: 4px;
        margin: 8px auto 0;
        border-radius: 2px;
        background: #d5d8de;
    }

    .modal:not(.modal-keep-center) .modal-dialog:not(.modal-fullscreen) .modal-body {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .modal:not(.modal-keep-center) .modal-header {
        padding: 12px 16px;
    }

    .modal:not(.modal-keep-center) .modal-header .btn-close {
        width: 44px;
        height: 44px;
        margin: -12px -12px -12px auto;
        padding: 0;
    }

    .modal:not(.modal-keep-center) .modal-footer {
        gap: 8px;
        padding: 10px 16px 12px;
    }

    .modal:not(.modal-keep-center) .modal-footer > .btn {
        flex: 1 1 0;
        margin: 0;
    }

    /* ---- Client header: Buy / Sell and language switch ------------------- */

    header.topbar .switch-btn button {
        min-height: 34px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Only the left copy shows on phones; never touch `display` here. */
    header.topbar .topbar-left > .lang-toggle {
        height: 34px;
    }

    /* ---- Search card filter row (home banner, /properties header) ----------
       Property / Budget / More Filters: one line each, icon, text and chevron
       no longer touch, and every trigger is a full 44px tap target. */

    /* The search box fills the first line, so the three triggers share the
       second line; each starts at its text width and only a very narrow phone
       cuts the text with an ellipsis. */
    .banner-home-set .search-bar > .property_type,
    .search_propertylist > .property_type {
        flex-basis: 100%;
    }

    .banner-home-set .search-bar > .form-item:not(.property_type),
    .search_propertylist > .form-item:not(.property_type) {
        flex: 1 1 auto;
        min-width: 0;
    }

    .search_propertylist .form-item .filter-trigger,
    .banner-home-set .search-bar .form-item .filter-trigger {
        display: flex;
        align-items: center;
        min-height: 44px;
        padding: 0 14px 0 0;
        font-size: 13px;
        white-space: nowrap;
    }

    .search_propertylist .form-item .filter-trigger i,
    .banner-home-set .search-bar .form-item .filter-trigger i {
        position: static;
        transform: none;
        flex: 0 0 auto;
        margin: 0 4px 0 7px;
    }

    .search_propertylist .form-item .filter-trigger span:not(.filter-badge),
    .banner-home-set .search-bar .form-item .filter-trigger span:not(.filter-badge) {
        min-width: 0;
        padding-left: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 13px !important;
    }

    /* ---- /properties ------------------------------------------------------ */

    /* Cards keep one 12px gutter instead of container + list padding. */
    .tablist-rws2 .ss-pr-left {
        padding-left: 0;
        padding-right: 0;
    }

    /* Map / List pill clears the raised Sell circle. */
    button.pl-map-fab {
        bottom: var(--m-float-center-b);
    }

    /* Wishlist + Sort row: the sort box (16px text, see above) shrinks to the
       space left next to Wishlist instead of running off the right edge. */
    .tbs-list-new form.relvence-filter {
        min-width: 0;
        height: 44px;
    }

    .tbs-list-new form.relvence-filter select {
        min-width: 0;
        width: 100%;
        height: 42px;
        text-overflow: ellipsis;
    }

    .tbs-list-new ul.nav-tabs {
        margin: 0;
        padding: 0;
        border: 0;
    }

    .tbs-list-new ul.nav-tabs li a.saved-toggle,
    .tbs-list-new ul.nav-tabs li a.tabstrip-link {
        display: inline-flex;
        align-items: center;
        height: 44px;
        border: 1px solid #dfe3e7;
        /* property-list.css rounds only the top corners, with !important. */
        border-radius: 22px !important;
    }

    /* "More Filters" reads "Filters" on phones, as in My Anuda, so the reset
       button stays on the same line. */
    .filter-trigger .filter-more-word {
        display: none;
    }

    .search_propertylist .form-item::after,
    .banner-home-set .search-bar .form-item::after {
        right: 3px;
        font-size: 10px;
    }

    .search_propertylist .btn-search-gray,
    .banner-home-set .search-bar .btn-search-gray {
        width: 40px;
        height: 40px;
        flex: 0 0 40px;
    }
}

/* Notched iPhones held sideways are wider than 768px, so they get the desktop
   layout; keep it clear of the notch now that the page runs edge to edge. */
@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
    body {
        padding-left: env(safe-area-inset-left, 0px);
        padding-right: env(safe-area-inset-right, 0px);
    }
}
