/* The app's bottom tab bar.
 *
 * UniMap's own since D155. It started as a copy of the unimap-cards plugin
 * (`npm run copy:build` used to regenerate it); it is edited in place now.
 * Colours, corners and shadows come from the shared tokens in
 * web/app/globals.css (`--color-*`, `--radius-*`, `--shadow-*`). Never add
 * a local palette or a literal brand colour: the seam test refuses both.
 *
 * The markup is web/src/discounts/bottom-nav.tsx, which links this file.
 * It DEFINES --ump-bottom-nav-h on body.has-ump-bottom-nav, which every
 * sheet detent, floating control and toast offset in discounts.css
 * measures against, with a fallback for pages without the bar.
 */
/* ---- Cross-document View Transitions (v0.133.0) ----
   Opt every app route into the native-feeling animated page swap. A tab
   tap is a full-document navigation; without this Chrome hard-swaps the
   documents with a white flash that reads as "not a native app". With it
   the outgoing page cross-fades into the incoming one instead.

   Scope is self-limiting and safe: navigation:auto only animates when
   BOTH the old and new document carry this opt-in, and this stylesheet
   ships on card routes ONLY (same should_render() gate as the bar). So
   transitions happen strictly between app pages -- never bleeding into a
   marketing page, /wp-admin, or a WooCommerce hop. Browsers without the
   API (Safari, older Chrome) ignore the at-rule entirely and fall back to
   the same instant hard swap as before -- purely additive, no regression.
   NB unrelated to the removed v0.64.2 <link rel=prefetch> warm-up: this
   is a paint/animation opt-in, it does not pre-issue any document request
   and cannot resurrect that ERR_FAILED class of bug. */
@view-transition { navigation: auto; }
/* Fade-through, not a slide. A directional slide felt disorienting on a
   tab bar -- tabs aren't a forward/back stack, so a fixed left/right push
   fights the user's mental model. Fade-through is the tab-switch idiom:
   old content fades out quickly, new content fades in with a subtle
   scale-up so it's clearly perceptible without implying any direction.
   The bar keeps its own view-transition-name below, so only the content
   animates while the bar stays put. */
::view-transition-old(root) {
    animation: ump-vt-fade-out 110ms ease both;
}
::view-transition-new(root) {
    animation: ump-vt-fade-in 220ms cubic-bezier(.2, 0, 0, 1) both;
}
@keyframes ump-vt-fade-out {
    to   { opacity: 0; }
}
@keyframes ump-vt-fade-in {
    from { opacity: 0; transform: scale(0.985); }
    to   { opacity: 1; transform: scale(1); }
}
/* Honour reduced-motion: drop straight to an instant swap. */
@media (prefers-reduced-motion: reduce) {
    ::view-transition-group(*),
    ::view-transition-old(*),
    ::view-transition-new(*) { animation: none !important; }
}

/* Default: hidden. The bar shows only inside the mobile media query
   below when body.has-ump-bottom-nav is present (added by body_class()
   on card routes for approved members). Desktop always hides. */
.ump-bottom-nav { display: none; }

@media (max-width: 782px) {
    body.has-ump-bottom-nav,
    body.ump-nav-pwa-only.unimap-standalone {
        --ump-bottom-nav-h: calc(66px + env(safe-area-inset-bottom, 0px));
        padding-bottom: var(--ump-bottom-nav-h);
    }
    /* ump-map-route is set server-side in body_class(). The bar now sits
       identically on every route because the body is forced scrollable in
       standalone (see Unimap_PWA min-height rule + the removed map scroll-
       lock), so iOS anchors the fixed bar to the true viewport bottom
       everywhere. Only the cosmetic corner/hairline treatment below is
       map-specific now -- no height or padding override needed. */
    /* /terkep only: square the top corners and drop the 1px inset hairline
       over the live map tiles (this box-shadow override + the
       .unimap-map-locked rule further down). Placement is handled the same
       as every other tab now -- the bar keeps its normal padding-bottom:
       env(safe-area-inset-bottom) and anchors to the true viewport bottom
       once the body is scrollable. */
    body.has-ump-bottom-nav.ump-map-route .ump-bottom-nav {
        box-shadow: 0 -10px 28px rgba(0, 0, 0, .55);
    }
    body.has-ump-bottom-nav .ump-bottom-nav,
    body.ump-nav-pwa-only.unimap-standalone .ump-bottom-nav {
        display: block;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        z-index: 999;
        /* Persist the bar across the cross-document view transition instead
           of letting it cross-fade with the page body. Named on both the
           outgoing and incoming page, Chrome lifts it into its own transition
           group and morphs old->new; since the bar is identical either side,
           it reads as staying put while only the content underneath swaps --
           the native tab-bar feel. Scoped to the mobile media query, which is
           the only place the bar is visible anyway. */
        view-transition-name: ump-bottom-nav;
        /* Near-opaque base (was .78): each tab tap is a full-document
           navigation, and iOS composites backdrop-filter on a fresh
           fixed element a frame late -- so the bar paints once WITHOUT
           the blur, then "flashes" to frosted. The layer promotion below
           only helps within a single document; it can't survive the
           cross-document swap. Raising the base opacity so the un-blurred
           first frame is visually almost identical to the frosted one
           makes that unavoidable first frame imperceptible while the
           blur still adds a subtle frost once it kicks in. */
        background: rgba(24, 24, 24, .92);
        -webkit-backdrop-filter: blur(24px) saturate(160%);
        backdrop-filter: blur(24px) saturate(160%);
        /* iOS paints backdrop-filter on a position:fixed element a frame
           late after a route change unless the element already owns a
           compositing layer -- the bar renders once unblurred, then
           "jumps" to blurred. Promote it to its own GPU layer up front so
           the blur is composited from the first paint. translateZ(0) is
           what actually forces the layer on WebKit; will-change hints the
           engine to keep it hot across the tab-swap navigation. */
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        will-change: transform;
        border-radius: 0;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        font-family: 'Poppins', Arial, sans-serif;
        box-shadow:
            0 -10px 28px rgba(0, 0, 0, .55),
            0 -1px 0 rgba(255, 255, 255, .08) inset;
    }
    /* Fallback when backdrop-filter isn't supported (older Android) */
    @supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
        body.has-ump-bottom-nav .ump-bottom-nav,
        body.ump-nav-pwa-only.unimap-standalone .ump-bottom-nav { background: var(--color-ground); }
    }
    /* /terkep (mobile map route): the map fills the full viewport *behind*
       the bar (see .ud-map-col bottom:0 in the directory CSS); the bar is
       raised above it so its backdrop-filter frosts over the live map.
       Two map-specific tweaks vs the other tabs:
         1. Square the top corners. The rounded top (fine over scrolling
            content elsewhere) sits over dark map tiles here, and the area
            outside the rounded backdrop-filter clip shows raw tiles as
            hard dark corner wedges ("sharp black corners"). Edge-to-edge
            is also the standard full-screen-map bottom-bar pattern.
         2. Drop the opacity from .92 to .72. Over dark tiles .92 reads as
            near-solid; .72 lets the blurred map show through so the bar
            reads as real translucent glass, like the frost-over-content
            on the other tabs. (The higher base opacity exists to hide the
            cross-navigation blur-flash; the map's own #1C1C1C backdrop
            makes the unblurred first frame a non-issue here.)
       body/html carry .unimap-map-locked only while the map overlay is up
       (set by the directory JS, gated to <=960px + map visible). */
    body.unimap-map-locked .ump-bottom-nav {
        z-index: 99999 !important;
        border-radius: 0 !important;
        background: rgba(24, 24, 24, .72) !important;
    }
    .ump-bottom-nav__inner {
        display: flex;
        height: 66px;
        max-width: 600px;
        margin: 0 auto;
    }

    /* ---- Tab item (all four equal weight) ---- */
    .ump-bottom-nav__item {
        position: relative;
        flex: 1 1 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        min-width: 0;
        color: #6E7476;
        text-decoration: none;
        font-size: 10.5px;
        font-weight: 400;
        letter-spacing: .01em;
        line-height: 1;
        padding: 8px 4px 6px;
        transition: color .2s ease;
        -webkit-tap-highlight-color: transparent;
    }
    .ump-bottom-nav__item svg {
        width: 24px;
        height: 24px;
        display: block;
        transition: stroke-width .2s ease, transform .18s ease;
    }
    .ump-bottom-nav__label {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        transition: font-weight .2s ease;
    }

    /* ---- Top pill indicator on active ---- */
    .ump-bottom-nav__item::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%) scaleX(0);
        width: 28px;
        height: 4px;
        background: #7BAAA8;
        border-radius: 0 0 4px 4px;
        transform-origin: center;
        transition: transform .28s cubic-bezier(.32,.72,0,1),
                    box-shadow .28s ease;
    }
    .ump-bottom-nav__item.is-active {
        color: #A6D4D2;
    }
    .ump-bottom-nav__item.is-active::before {
        transform: translateX(-50%) scaleX(1);
        box-shadow: 0 0 12px rgba(123, 170, 168, .6);
    }
    .ump-bottom-nav__item.is-active svg {
        stroke-width: 2.4;
    }
    .ump-bottom-nav__item.is-active .ump-bottom-nav__label {
        font-weight: 500;
    }

    /* ---- Interactions ---- */
    .ump-bottom-nav__item:hover,
    .ump-bottom-nav__item:focus-visible {
        color: #9BC3C2;
        outline: none;
    }
    .ump-bottom-nav__item:active svg {
        transform: scale(.88);
    }

    /* --- Coexistence with /partners + /terkep floating UI ---
       The list/map FAB was removed in v0.70.0 (map is now its own
       /terkep tab), so only the toast needs lifting above the bar. */
    body.has-ump-bottom-nav .unimap-partners-directory .ud-toast {
        bottom: calc(var(--ump-bottom-nav-h, 66px) + 16px) !important;
    }
}
