/* ═══════════════════════════════════════════════════════════════════════
   MOBILE INTERACTION LAYER — §51: "لا تصغر شاشات سطح المكتب". Dedicated
   mobile patterns, not the desktop layout shrunk down: a bottom tab bar,
   a sticky PDP purchase bar, a filter bottom sheet, and a swipeable
   gallery. Everything below is scoped under max-width: 900px (--bp-lg,
   tokens.css) — the SAME breakpoint layout.css (.catalog-layout,
   .filters) and pdp.css (.pdp-layout, .pdp-gallery) already stack at.

   Loaded LAST — see _Layout.cshtml <head>, after every other stylesheet
   including page-specific ones (pdp.css/discovery.css/cart.css) — so the
   few rules here that intentionally override an existing selector
   (.filters, .pdp-gallery__thumbs, body) win the cascade without editing
   those files (Q9 — compose, don't fork). No color/spacing/radius/shadow
   literal below; every value is var(--token) from tokens.css/theme.css,
   or a new mobile-only dimension declared once at the top (§0) and reused.

   prefers-reduced-motion: every transition in this file uses var(--duration-*)
   and var(--ease-*) tokens, so base.css's global
   `*, *::before, *::after { transition-duration: .001ms !important; }`
   rule already neutralises all of them — nothing to duplicate here.
   Touch targets in this file are 44×44 CSS px minimum throughout (WCAG 2.5.5).
   ═══════════════════════════════════════════════════════════════════════ */

/* ── §0 — mobile-only dimensions (reused by 3+ rules below) ────────────── */
:root {
    --mobile-nav-h: 60px;
    --mobile-safe-b: env(safe-area-inset-bottom, 0px);
}

/* ═══════════════════════════════════════════════════════════════════════
   §1 — BOTTOM NAVIGATION
   ═══════════════════════════════════════════════════════════════════════ */

.mobile-nav {
    display: none;
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: var(--z-sticky);
    height: calc(var(--mobile-nav-h) + var(--mobile-safe-b));
    padding-bottom: var(--mobile-safe-b); /* home-indicator safe area — never swallowed */
    background: var(--paper);
    border-top: 1px solid var(--line);
    box-shadow: var(--shadow-pop);
}
@media (max-width: 900px) { /* --bp-lg */
    .mobile-nav { display: flex; }
    /* Room at the bottom of every page so fixed chrome never covers the footer/content. */
    body { padding-bottom: calc(var(--mobile-nav-h) + var(--mobile-safe-b)); }
}

.mobile-nav__item {
    flex: 1 1 0;
    min-width: 44px;
    height: var(--mobile-nav-h);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .2rem;
    color: var(--ink-soft);
    text-decoration: none;
    font-size: .68rem;
    font-weight: var(--weight-semibold);
    transition: color var(--duration-fast) var(--ease-standard);
}
.mobile-nav__item .icon { width: 22px; height: 22px; }
.mobile-nav__item:hover { color: var(--ink); }
.mobile-nav__item.is-active { color: var(--brand); }

/* Toast sits above the toast's default position so it never hides behind the tab bar. */
@media (max-width: 900px) { /* --bp-lg */
    .toast { bottom: calc(var(--mobile-nav-h) + var(--mobile-safe-b) + var(--space-3)); }
}

/* ═══════════════════════════════════════════════════════════════════════
   §2 — PDP STICKY PURCHASE BAR (injected by mobile.js — no markup change
   needed in Product.cshtml; see initStickyBuyBar()).
   ═══════════════════════════════════════════════════════════════════════ */

.pdp-sticky-buy {
    display: none;
    position: fixed;
    inset-inline: 0;
    bottom: calc(var(--mobile-nav-h) + var(--mobile-safe-b)); /* sits ABOVE the tab bar, never under it */
    z-index: var(--z-sticky);
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: .6rem var(--container-padding-sm);
    background: var(--paper);
    border-top: 1px solid var(--line);
    box-shadow: var(--shadow-pop);
    /* Rest position is already raised (bottom: nav-height) to sit above the
       tab bar — translateY(100%) alone only covers the box's OWN height, so
       the hidden state must ALSO cover that raise, or the top slice of the
       bar stays visible above the tab bar even while "hidden". */
    transform: translateY(calc(100% + var(--mobile-nav-h) + var(--mobile-safe-b)));
    opacity: 0;
    transition: transform var(--duration-base) var(--ease-decelerate),
                opacity var(--duration-base) var(--ease-standard);
}
@media (max-width: 900px) { /* --bp-lg */
    .pdp-sticky-buy { display: flex; }
}
.pdp-sticky-buy.is-visible { transform: translateY(0); opacity: 1; }

.pdp-sticky-buy__price {
    display: flex;
    flex-direction: column;
    min-width: 0;
    gap: .1rem;
}
.pdp-sticky-buy__name {
    font-size: var(--text-sm);
    color: var(--ink-soft);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pdp-sticky-buy .price__whole { font-size: 1.3rem; }
.pdp-sticky-buy__btn { flex: 0 0 auto; min-width: 150px; }

/* ═══════════════════════════════════════════════════════════════════════
   §3 — FILTER BOTTOM SHEET (transforms the EXISTING .filters aside — see
   Pages/Shared/_MobileFilters.cshtml + mobile.js initMobileFilters()).
   ═══════════════════════════════════════════════════════════════════════ */

.mobile-filters-trigger { display: none; }
@media (max-width: 900px) { /* --bp-lg */
    .mobile-filters-trigger {
        display: inline-flex;
        align-items: center;
        gap: .5rem;
        width: 100%;
        min-height: 46px;
        margin-block-end: var(--space-4);
        padding-inline: var(--space-4);
        background: var(--paper);
        border: 1px solid var(--line-strong);
        border-radius: var(--radius-sm);
        color: var(--ink);
        font: inherit;
        font-weight: var(--weight-semibold);
        font-size: var(--text-base);
        cursor: pointer;
    }
    .mobile-filters-trigger:hover { border-color: var(--brand); }
}

.mobile-filters-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--z-overlay);
    background: rgba(20, 23, 28, .45);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--duration-base) var(--ease-standard), visibility var(--duration-base);
}
html.mobile-filters-open .mobile-filters-overlay {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

@media (max-width: 900px) { /* --bp-lg */
    /* The real refinement sidebar becomes the sheet body — same node, same
       form, just repositioned + hidden off-screen until opened. */
    .filters {
        position: fixed;
        inset-inline: 0;
        bottom: 0;
        top: auto;
        max-height: min(85dvh, 640px); /* dvh, not vh — mobile browser chrome makes vh lie by its own height */
        z-index: var(--z-modal);
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        box-shadow: var(--shadow-pop);
        overflow-y: auto;
        overscroll-behavior: contain;
        transform: translateY(100%);
        visibility: hidden;
        pointer-events: none;
        transition: transform var(--duration-slow) var(--ease-decelerate), visibility var(--duration-slow);
    }
    /* The page's own inline heading/clear-link is replaced by the sticky
       header mobile.js clones in (title + ✕) — avoids a duplicate heading. */
    .filters > .filters__head { display: none; }

    html.mobile-filters-open .filters {
        transform: translateY(0);
        visibility: visible;
        pointer-events: auto;
    }
    html.mobile-filters-open { overflow: hidden; } /* lock background scroll while the sheet is open */
}

/* ⚠️ The two clone blocks below are HIDDEN BY DEFAULT and only revealed under the
   900px breakpoint at the end of this section. mobile.js clones them into .filters
   at ANY viewport width (it has no width guard, and must not gain one — a user who
   resizes down after load would otherwise get a sheet with no header or footer).
   Until 2026-08-25 these rules sat outside any @media, so on desktop the drag
   grabber, the "تصفية النتائج ✕" header and the "تطبيق الفلاتر" footer bar all
   painted on top of the desktop filter rail — and because the rule that hides the
   page's OWN .filters__head lives inside the mobile breakpoint, the heading showed
   twice. MEASURED on /category at 1440px. */

/* Sticky header clone (mobile.js prepends this into .filters) */
.mobile-filters-sheet__head {
    display: none;
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--paper-muted);
    border-bottom: 1px solid var(--line);
}
.mobile-filters-sheet__grabber {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 28px;
    padding-block: var(--space-2);
    background: none;
    border: 0;
    cursor: grab;
    touch-action: none;
}
.mobile-filters-sheet__grabber::before {
    content: "";
    width: 36px;
    height: 4px;
    border-radius: var(--radius-full);
    background: var(--line-strong);
}
.mobile-filters-sheet__headrow {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.1rem var(--space-4);
}
.mobile-filters-sheet__headrow h2 { font-size: var(--text-lg); font-weight: var(--weight-bold); margin: 0; }
/* .icon-btn is 44×44 in the shared components.css primitive — nothing to add here. */

/* Sticky footer clone (mobile.js appends this into .filters) */
.mobile-filters-sheet__foot {
    display: none;
    position: sticky;
    bottom: 0;
    z-index: 1;
    gap: var(--space-3);
    padding: var(--space-4) 1.1rem calc(var(--space-4) + var(--mobile-safe-b));
    background: var(--paper);
    border-top: 1px solid var(--line);
}
.mobile-filters-sheet__foot .btn { flex: 1 1 0; }

/* The clone chrome exists only as a SHEET — below the tablet breakpoint. */
@media (max-width: 900px) { /* --bp-lg */
    .mobile-filters-sheet__head { display: block; }
    .mobile-filters-sheet__foot { display: flex; }
}

/* ═══════════════════════════════════════════════════════════════════════
   §4 — SWIPE GALLERY (PDP — built by mobile.js initSwipeGallery(), which
   moves the existing #pdpMainImage into slide 0 and clones one <img> per
   .pdp-gallery__thumb[data-image-url] as the following slides; every img
   still matches pdp.css's existing ".pdp-gallery__main img" rule for
   sizing/object-fit — nothing is redeclared here, only the track/slide/
   dot layout that pdp.css has no concept of).
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 900px) { /* --bp-lg */
    /* The thumbnail strip is replaced by the swipe track + dots on mobile. */
    .pdp-gallery__thumbs { display: none; }
}

.pdp-swipe__track {
    display: flex;
    width: 100%;
    height: 100%;
}
@media (max-width: 900px) { /* --bp-lg */
    .pdp-swipe__track {
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        overscroll-behavior-x: contain;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .pdp-swipe__track::-webkit-scrollbar { display: none; }
}
.pdp-swipe__slide {
    flex: 0 0 100%;
    scroll-snap-align: start;
}

@media (min-width: 901px) { /* above --bp-lg — desktop keeps one static image, CSS-only, no JS branch needed */
    .pdp-swipe__track { overflow: hidden; }
    .pdp-swipe__slide:not(:first-child) { display: none; }
    .pdp-swipe__dots { display: none; }
}

.pdp-swipe__dots {
    display: none;
    justify-content: center;
    align-items: center;
    gap: .1rem;
    margin-block-start: var(--space-3);
}
@media (max-width: 900px) { /* --bp-lg */
    .pdp-swipe__dots { display: flex; }
}
.pdp-swipe__dot {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
}
.pdp-swipe__dot::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--line-strong);
    transition: background var(--duration-fast) var(--ease-standard), transform var(--duration-fast) var(--ease-standard);
}
.pdp-swipe__dot[aria-current="true"]::before {
    background: var(--brand);
    transform: scale(1.3);
}
