/* ============================================================================
   mobile.css — Hornback IMS V4 mobile-responsive layer (4th CSS layer)
   ----------------------------------------------------------------------------
   GOAL (founder, 2026-07-17): on a desktop/wide browser the app must look
   EXACTLY as it does today; on a phone it must feel like a polished, native
   mobile application (M3 compact: bottom nav, top app bar, cards, sheets).

   HOW THIS FILE STAYS DESKTOP-SAFE — the one rule for editing this file:
     ► EVERY rule in this file MUST live inside a `@media` block whose max-width
       is the compact breakpoint (or a mobile-only feature query). Nothing here
       may apply at desktop widths. If a rule isn't inside a mobile @media block,
       it does NOT belong in this file — put it in v32-theme.css instead.

   LOAD ORDER: app.css → v32-theme.css → tokens.css → **mobile.css** (this,
   loaded LAST via App.razor + AssetVersions.MobileCss). Loading last means our
   compact overrides win cleanly without touching the desktop layers.

   BREAKPOINT (aligned to the app's EXISTING mobile precedent, not raw M3):
     Phone    ≤ 719.98px   → this file's target (same boundary My Space already uses)
     Desktop  ≥ 720px      → untouched (today's exact look)
   Using 719.98px (not 600px) keeps ONE phone boundary app-wide: the shipped
   `.msp-*` self-service mobile view (v32-theme.css:2794) already switches here.

   STRATEGY — generalize, don't invent: the app already has a founder-approved
   phone treatment for the "My Space" pages — `.app-shell:has(.msp-page)` at
   v32-theme.css:2794 collapses the grid to one column, hides `.app-sidebar`,
   keeps the top bar, shows a fixed bottom nav (`.msp-tabbar` /
   MySpaceMobileNav.razor), stacks list/detail, single-columns `.form-grid`, and
   gives tables 48px rows. This file GENERALIZES that same pattern to every page
   (drops the `.msp-page` gate), so we reuse a proven mechanism rather than a new one.

   Design system: reuse the existing tokens (--space-*, --brand-orange, --ink-*,
   --r-*, --shadow-*, --ease-*, --dur-*) — never hard-code colour/radius here.
   Bottom-nav pattern is modelled on the proven `.msp-tabbar` / `.field-tabbar`.
   ============================================================================ */

/* ── Mobile system tokens (safe at all widths: :root var *declarations* only,
      they change nothing until referenced inside a mobile @media block) ────── */
:root {
    /* App-shell dimensions for the phone layout. Bottom-nav height matches the
       shipped `.msp-tab` (56px) so the generalized bar is visually identical.
       The top app bar reuses the existing `.app-topbar` (--topbar-h) — no new bar. */
    --m-bottomnav-h: 56px;       /* matches .msp-tab (M3 navigation bar) */
    /* iOS/Android safe-area insets (notch, home indicator). 0 on devices w/o. */
    --m-safe-top: env(safe-area-inset-top, 0px);
    --m-safe-bottom: env(safe-area-inset-bottom, 0px);
    --m-safe-left: env(safe-area-inset-left, 0px);
    --m-safe-right: env(safe-area-inset-right, 0px);
    /* Total space the fixed bottom nav occupies incl. the home-indicator inset. */
    --m-bottomnav-total: calc(var(--m-bottomnav-h) + var(--m-safe-bottom));
    /* M3 minimum touch target. */
    --m-touch: 48px;
}

/* ── Base rules — the ONLY non-@media rules allowed here, and ONLY because they
      hide brand-new mobile-only elements on desktop. These elements render nothing
      on ≥720px screens, so the desktop UI is still byte-for-byte unchanged. ─────── */
.mobile-nav-toggle { display: none; }   /* hamburger — shown on phone only */
.mobile-nav-scrim  { display: none; }   /* drawer scrim — shown on phone only */
.topbar-brand-mobile { display: none; } /* compact topbar brand — shown on phone only */

/* ===========================================================================
   PHONE ( ≤ 719.98px ) — the phone experience (same boundary as `.msp-*`)
   =========================================================================== */
@media (max-width: 719.98px) {

    /* ── 0. Foundation ────────────────────────────────────────────────────── */
    html, body {
        overflow-x: clip;                   /* never scroll sideways. clip (NOT hidden): hidden
                                               creates a scroll container that silently kills
                                               position:sticky/fixed behaviour of descendants */
        padding-left: var(--m-safe-left);   /* honour landscape-notch safe areas */
        padding-right: var(--m-safe-right);
    }
    /* Lock page scroll while the nav drawer is open (set by hornback.toggleMobileNav). */
    body.mobile-nav-locked { overflow: hidden; }

    /* =======================================================================
       1. APP SHELL — collapse the 2×2 grid to one column; the sidebar becomes
          a slide-in drawer (hamburger). Generalizes the `.msp-page` treatment
          (v32-theme.css:2794) to every page by dropping the `.msp-page` gate.
       ======================================================================= */
    .app-shell,
    .app-shell.sidebar-collapsed {          /* beat the desktop collapsed-rail width too */
        /* minmax(0,1fr) — NOT 1fr (=minmax(auto,1fr)) — so a wide child (full-bleed tables) can't
           stretch the column past the viewport and drag the topbar/avatar off-screen. */
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: "topbar" "main";
        overflow-x: clip;                   /* clip, not hidden — keeps fixed/sticky working */
    }

    /* Sidebar → off-canvas drawer. position:fixed removes it from the grid flow
       so it never fights the named areas. */
    .app-sidebar,
    .app-shell.sidebar-collapsed .app-sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: min(84vw, 300px);
        height: 100dvh;
        transform: translateX(-100%);
        transition: transform var(--dur-base, 220ms) var(--ease-out, ease);
        z-index: 1000;                      /* above topbar (--z-topbar:30) + scrim */
        box-shadow: var(--shadow-xl, 0 12px 40px rgba(0,0,0,.28));
        will-change: transform;
    }
    .app-shell.mobile-nav-open .app-sidebar { transform: translateX(0); }

    /* Drawer is full-width — neutralize the desktop "collapsed rail" compaction so
       nav labels/sections read normally even if the user had collapsed on desktop. */
    .app-shell.sidebar-collapsed .nav-label,
    .app-shell.sidebar-collapsed .nav-group-label,
    .app-shell.sidebar-collapsed .nav-soon { display: revert; }
    .app-shell.sidebar-collapsed .nav-item {
        justify-content: flex-start;
        padding: var(--space-2) var(--space-4);
        gap: var(--space-3);
    }
    /* The desktop collapse toggle at the drawer's foot is meaningless on phone. */
    .sidebar-toggle { display: none; }

    /* Scrim behind the open drawer — tap to close. */
    .mobile-nav-scrim {
        display: block;
        position: fixed; inset: 0;
        background: rgba(0, 0, 0, .45);
        opacity: 0; pointer-events: none;
        transition: opacity var(--dur-base, 220ms) var(--ease-out, ease);
        z-index: 999;                       /* below the drawer (1000), above content */
    }
    .app-shell.mobile-nav-open .mobile-nav-scrim { opacity: 1; pointer-events: auto; }

    /* =======================================================================
       2. TOP APP BAR — hamburger + compact brand appear; tighten padding; let the
          contextual search flex instead of its fixed 320px desktop width.
       ======================================================================= */
    /* App bar is FIXED on phone (M3 top app bar) — always visible while scrolling. The shell's
       first grid row (var(--topbar-h)) stays reserved, so content starts exactly below the bar. */
    .app-topbar {
        position: fixed;
        top: 0; left: 0; right: 0;
        height: calc(var(--topbar-h) + var(--m-safe-top));
        padding: var(--m-safe-top) var(--space-2) 0;
        gap: var(--space-2);
        z-index: 100;                        /* above content/FAB(90); below sheet/scrim/drawer */
    }
    .topbar-left { gap: var(--space-2); min-width: 0; }
    .topbar-right { flex: 0 0 auto; }        /* bell + avatar never get pushed off-screen */

    .mobile-nav-toggle { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
    .topbar-brand-mobile {
        display: inline-flex; align-items: center; gap: var(--space-2);
        color: inherit;                     /* inherit the topbar's own fg (light or dark skin) */
        font-family: var(--font-display, inherit);
        text-transform: uppercase; letter-spacing: .06em;
        font-size: 15px; white-space: nowrap;
    }
    .topbar-brand-mobile-logo { height: 22px; width: auto; }
    /* Below ~420px, drop the wordmark and keep the logo so search has room. */
    @media (max-width: 419.98px) { .topbar-brand-mobile-text { display: none; } }

    .topbar-search-wrap { flex: 1 1 auto; min-width: 0; max-width: none; }
    .topbar-search-wrap input { min-width: 0; width: 100%; }   /* search shrinks, never overflows */
    /* Keep the notification/profile dropdowns inside the viewport. */
    .topbar-dropdown { max-width: calc(100vw - var(--space-3) * 2); }

    /* =======================================================================
       3. MAIN + PAGE SCAFFOLD — smaller canvas padding; let full-bleed pages
          scroll with the page instead of holding a fixed 100vh inner height.
       ======================================================================= */
    .app-main { padding: var(--space-3); overflow-x: hidden; min-width: 0; }
    .fullbleed-page {
        margin: 0;                          /* drop the desktop negative full-bleed margins (they
                                               widened the shell past the viewport on phones) */
        height: auto;
        min-height: calc(100dvh - var(--topbar-h, 44px));
        overflow: visible;
        min-width: 0;
    }

    /* Page toolbar: stack title → KPIs → actions. */
    .page-toolbar { flex-direction: column; align-items: stretch; gap: var(--space-3); }
    .toolbar-actions { flex-wrap: wrap; }
    /* KPI tiles → tidy 2-up (Zoho-style). flex-wrap (not a rigid 2-col grid) so plain tiles pair up
       while GROUPED KPI banners (e.g. stock-ledger's by-process / by-location) take full width and
       lay their own cards out — a rigid grid squeezed those groups into a jagged half-column. */
    .page-stats {
        display: flex; flex-wrap: wrap; align-content: flex-start;
        gap: var(--space-2); margin-left: 0; width: 100%;
    }
    .page-stats > .page-stat { flex: 1 1 46%; min-width: 0; }
    .page-stats > .sl-stat-group { flex: 1 1 100%; }
    .sl-stat-group { flex-wrap: wrap; }
    .sl-stat-group > * { flex: 1 1 46%; min-width: 0; }
    /* Filter bar: wrap and let fields shrink instead of forcing 160px min-widths. */
    .page-filter-bar { flex-wrap: wrap; }
    .page-filter-bar .filter-field,
    .page-filter-bar .field { min-width: 0; }

    /* =======================================================================
       4. TABLES → card list (Zoho-style). hornback.initResponsiveTables mirrors each
          <thead> header onto its <td> as data-label; here each row becomes a card with
          "Label ........ value" lines. One place → all ~40 .data-table grids. Matrix /
          compare grids use other classes (.cmp-*, .ssl-matrix) and are untouched.
       ======================================================================= */
    .table-wrap {
        max-height: none;                   /* release the desktop calc() cap → page scrolls */
        overflow: visible;
        border: 0; padding: 0; background: transparent;
    }
    .data-table {
        display: block; width: 100% !important;
        min-width: 0 !important;            /* beat wide-table min-widths (e.g. 1480px) */
        border: 0;
    }
    .data-table tbody { display: block; width: 100%; }
    .data-table thead { display: none; }    /* headers now live in each cell's data-label */

    .data-table tr {
        display: flex;                      /* flex column so the title cell can order:-1 to the top */
        flex-direction: column;
        background: var(--paper);
        border: 1px solid var(--border);
        border-radius: var(--r-lg);
        padding: var(--space-2) var(--space-3);
        margin-bottom: var(--space-2);      /* density: 8px between cards, not 12px */
        box-shadow: var(--shadow-sm);
    }
    /* Zoho card order: bold title first, everything else in column order below. */
    .data-table td[data-mtitle] { order: -1; }
    /* Density: hide cells whose value is empty ("—"/blank) — they burn a full row each on a
       phone for zero information (founder: "too less info in too much space"). The auto-labeler
       marks them data-mempty. Colspan/group rows are exempt. */
    .data-table td[data-mempty]:not([colspan]) { display: none; }
    /* Key-field collapse (decision-ladder b): tables the route-config marks .m-collapsed show
       ONLY their key cells (data-mkey) — a 3-4 line Zoho-style card. The row's existing click
       (detail pane) or the expand toggle reveals everything, so no data is lost (M10). */
    .data-table.m-collapsed td:not([data-mkey]):not([colspan]) { display: none; }
    .data-table.m-collapsed tr.m-expanded td:not([data-mempty]) { display: flex; }
    .data-table.m-collapsed tr.m-expanded td[colspan] { display: flex; }

    /* row2 layout — compact 2-line list (founder spec for Home's reorder list):
       title + mono sub-code stacked LEFT, up to two micro-labelled numbers RIGHT. ~56px/row. */
    .data-table.m-row2 tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-auto-rows: min-content;
        gap: 2px var(--space-3);
        align-items: baseline;
        padding: var(--space-2) var(--space-3);
    }
    .data-table.m-row2 td { display: none; }
    .data-table.m-row2 td[data-mtitle],
    .data-table.m-row2 td[data-msub],
    .data-table.m-row2 td[data-mnum] { display: block; padding: 0 !important; text-align: left !important; }
    .data-table.m-row2 td::before { content: none; }
    /* Explicit 2×2 areas — sparse auto-placement pushed the sub-code to a 3rd row. */
    .data-table.m-row2 td[data-mtitle]   { grid-area: 1 / 1; font-size: var(--fs-13, 13px); font-weight: 600; }
    .data-table.m-row2 td[data-msub]     { grid-area: 2 / 1; font-size: 11px; color: var(--ink-500); font-family: var(--font-mono); }
    .data-table.m-row2 td[data-mnum]     { text-align: right !important; font-weight: 700; font-variant-numeric: tabular-nums; }
    .data-table.m-row2 td[data-mnum="1"] { grid-area: 1 / 2; }
    .data-table.m-row2 td[data-mnum="2"] { grid-area: 2 / 2; }
    .data-table.m-row2 td[data-mnum]::before {
        content: attr(data-label) " ";
        display: inline;               /* micro-label inline before the number — keeps the row 2 lines */
        font-size: 9px;
        font-weight: 600;
        color: var(--ink-500);
        letter-spacing: .04em;
    }
    .data-table td {
        display: flex;
        flex-wrap: wrap;                    /* multi-element cells (name + sub-line) wrap gracefully */
        justify-content: space-between;     /* label left · value right */
        align-items: baseline;
        gap: var(--space-2) var(--space-3);
        border: 0 !important;
        padding: var(--space-1) 0 !important;
        text-align: right !important;
        white-space: normal !important;     /* wrap on phone (desktop U35 ellipsis is off here) */
        min-height: 0;
        height: auto !important;            /* release U35's fixed 44px row height inside cards */
        max-width: none !important;         /* release U35's 320px ellipsis cap inside cards */
    }
    .data-table td::before {
        content: attr(data-label);
        flex: 0 0 38%;
        text-align: left;
        font-size: var(--fs-12, 12px);
        color: var(--ink-500);
        font-weight: var(--fw-semibold, 600);
    }
    /* Card title line: the cell the route-config marks data-mtitle drops its label and renders
       as the card's bold first line (Zoho card pattern: title left, primary value right). */
    .data-table td[data-mtitle] { font-weight: 700; font-size: var(--fs-md, 14.5px); }
    .data-table td[data-mtitle]::before { content: none; }
    .data-table td[data-mtitle] { justify-content: flex-start; text-align: left !important; }
    /* Control cells (checkbox / actions) have no header text → no label; left-align them. */
    .data-table td:not([data-label])::before,
    .data-table td[data-label=""]::before { content: none; }
    .data-table td:not([data-label]),
    .data-table td[data-label=""] { justify-content: flex-start; text-align: left !important; }

    /* Group / colspan rows (e.g. date-group headers) → plain full-width heading. */
    .data-table tr:has(td[colspan]) {
        background: transparent; border: 0; box-shadow: none;
        padding: var(--space-3) 0 var(--space-1); margin: 0;
    }
    .data-table td[colspan] {
        justify-content: flex-start; text-align: left !important;
        font-weight: var(--fw-semibold, 600);
    }
    .data-table td[colspan]::before { content: none; }

    /* =======================================================================
       5. LIST / DETAIL split (`.vendors-shell`) — single column. When a record is
          open, the narrow list rail hides and the detail pane takes the full width
          (the detail header's ✕/back returns to the list). "Swap, don't squeeze."
       ======================================================================= */
    .vendors-shell { flex-direction: column; gap: var(--space-3); }
    .vendors-shell.with-detail .list-pane,
    .vendors-shell.with-edit   .list-pane { display: none; }
    .vendors-shell .detail-pane { width: 100%; min-width: 0; }
    .list-pane { min-width: 0; }
    /* When a record is open, focus it — hide the page toolbar + KPIs so the detail owns the screen
       (the detail header's ✎ / More / ✕ are the controls now). */
    .fullbleed-page:has(.vendors-shell.with-detail) > .page-toolbar,
    .fullbleed-page:has(.vendors-shell.with-edit)   > .page-toolbar { display: none; }

    /* =======================================================================
       6. FORMS + VIEW GRIDS — every multi-column grid collapses to one column
          so labels/values read top-to-bottom instead of cramming two per row.
       ======================================================================= */
    .form-grid,
    .form-grid-2,
    .form-grid-3col,
    .view-grid,
    .view-section .view-grid,           /* beat app.css:1829 (0,2,0) — loads later, same specificity */
    .side-panel-body .view-grid,
    .edit-pane-body .view-grid { grid-template-columns: 1fr; }

    /* =======================================================================
       7. MODALS → full-screen sheet. Uses !important ONLY to beat the per-page
          inline `style="width:96vw;max-width:…;max-height:…"` on ~43 modals.
       ======================================================================= */
    .modal {
        inset: 0 !important;
        transform: none !important;
        width: 100vw !important;  max-width: 100vw !important;
        height: 100dvh !important; max-height: 100dvh !important;
        border-radius: 0 !important;
        display: flex; flex-direction: column;
    }
    .modal-body { flex: 1 1 auto; overflow-y: auto; }
    /* Dense multi-field "line row" grids inside modals (e.g. Consumption Log add-row) squeeze on a
       phone. Hide the tiny header-label row (the ink-50 one) and stack each data row to one column
       so every field is full-width & tappable — the field placeholders carry the labels. */
    .modal-body [style*="grid-template-columns"][style*="--ink-50"] { display: none !important; }
    .modal-body [style*="grid-template-columns"]:not([style*="--ink-50"]) {
        grid-template-columns: 1fr !important;
        gap: var(--space-2) !important;
    }

    /* =======================================================================
       8. TOUCH TARGETS — ≥40px effective hit area on the phone (U7).
       ======================================================================= */
    .btn-primary, .btn-secondary, .btn-danger { min-height: 40px; }
    .btn-icon, .topbar-icon-btn { min-width: 40px; min-height: 40px; }
    .field { min-height: 40px; }

    /* =======================================================================
       9. M3 ELEMENT POLISH (compact) — tactile feedback, type hierarchy, shape.
          All phone-only; desktop element styling is untouched. Grounded in the
          material-design-3 skill (state layers, type scale, 12dp card corner).
       ======================================================================= */
    /* M3 state-layer press feedback — token-free brightness dip works on any skin. */
    .btn-primary:active, .btn-secondary:active, .btn-danger:active,
    .btn-icon:active, .topbar-icon-btn:active,
    .nav-item:active, .data-table tbody tr:active,
    .list-rail-item:active { filter: brightness(0.96); }

    /* Cards → M3 medium corner (12dp). */
    .data-table tr { border-radius: var(--r-xl); }

    /* Type hierarchy for a phone: prominent but not oversized title; readable sub. */
    .page-toolbar h1 { font-size: clamp(20px, 6vw, 26px); line-height: 1.15; }
    .page-toolbar .subtitle { font-size: var(--fs-13, 13px); }
    .page-stat .page-stat-value { font-size: clamp(18px, 5.5vw, 22px); }

    /* Comfortable drawer nav rows. */
    .app-sidebar .nav-item { padding-top: var(--space-3); padding-bottom: var(--space-3); }

    /* =======================================================================
       10. FAB — the page's single primary action (U2) floats bottom-right as an
           M3 extended FAB (Zoho-mobile pattern). Secondary actions stay in the
           stacked toolbar. Only `.toolbar-actions .btn-primary` floats.
       ======================================================================= */
    .page-toolbar .toolbar-actions .btn-primary {
        position: fixed;
        right: calc(var(--space-4) + var(--m-safe-right));
        bottom: calc(var(--m-bottomnav-total) + var(--space-3));   /* floats above the bottom nav */
        z-index: 90;                    /* above page content; BELOW modals (200) / drawer (1000)
                                           so an open modal/sheet always covers the FAB */
        min-height: 56px;
        padding: 0 var(--space-5);
        border-radius: var(--r-full);
        box-shadow: var(--shadow-lg);
    }
    /* Keep the last content row clear of the bottom nav + floating FAB. */
    .fullbleed-page { padding-bottom: calc(var(--m-bottomnav-total) + 72px); }

    /* Accessibility — honour reduced-motion for the drawer/scrim slide. */
    @media (prefers-reduced-motion: reduce) {
        .app-sidebar, .mobile-nav-scrim { transition: none; }
    }

    /* =======================================================================
       11. Safe containment for other common surfaces — nothing overflows a phone.
       ======================================================================= */
    .side-panel { width: 100% !important; max-width: 100% !important; }   /* right side-sheet → full width */
    .dropdown-card { max-width: calc(100vw - var(--space-4)); }           /* popover cards fit the viewport */

    /* =======================================================================
       12. DASHBOARDS — the Home/Production/Dispatch/Banking/COGS dashboards build
           their stat rows + chart panels with INLINE-STYLE grids (no classes), e.g.
           grid-template-columns:repeat(5,1fr) or 200px 1fr. On a phone those overflow.
           Attribute-substring selectors collapse the dense inline grids in ONE place
           (the only justified use of !important — beating inline styles for mobile).
       ======================================================================= */
    [style*="repeat(6,1fr)"],
    [style*="repeat(5,1fr)"],
    [style*="repeat(4,1fr)"],
    [style*="repeat(3,1fr)"] { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    /* label + chart splits (fixed-px first column) → stack. */
    [style*="200px 1fr"],
    [style*="220px 1fr"],
    [style*="240px 1fr"],
    [style*="260px 1fr"],
    [style*="280px 1fr"],
    [style*="300px 1fr"] { grid-template-columns: 1fr !important; }
    /* Two-column chart/table splits (1fr 1fr, 2fr 1fr, 1fr 2fr…) → stack full-width. */
    [style*="grid-template-columns:1fr 1fr"],
    [style*="grid-template-columns:2fr 1fr"],
    [style*="grid-template-columns:1fr 2fr"],
    [style*="grid-template-columns:3fr 2fr"],
    [style*="grid-template-columns:2fr 3fr"],
    [style*="grid-template-columns:1.5fr 1fr"] { grid-template-columns: 1fr !important; }
    /* Chart.js canvases never exceed their (now full-width) container. */
    .app-main canvas { max-width: 100% !important; }
    /* Full-bleed section bars (negative side margins on desktop) clip/overflow on a phone — U47. */
    .section-bar { margin-left: 0 !important; margin-right: 0 !important; }

    /* =======================================================================
       13. HOME DASHBOARD fixes (founder 2026-07-18) — selectors verified against
           Home.razor by the analysis pass.
       ======================================================================= */
    /* Redundant stock-health legend (L95): the five tiles repeat every label — hide it.
       !important required: the legend carries inline display:flex. */
    .page-scroll-body div[style*="justify-content:space-between"] > .section-bar + div[style*="font-size:11px"] { display: none !important; }
    /* Section headers that pair a section-bar with controls: let them wrap cleanly. */
    .page-scroll-body div[style*="justify-content:space-between"] { flex-wrap: wrap; gap: var(--space-2); }
    /* Donut chart (L221): stack canvas over its legend instead of side-by-side. */
    .page-scroll-body div[style*="min(46%"] { width: 100% !important; max-width: 240px; margin: 0 auto; }
    /* Period selector + GM toggles → single-row horizontal chip strip (thumb-swipe, no wrap). */
    .page-scroll-body div[role="group"] {
        flex-wrap: nowrap !important;
        overflow-x: auto;
        max-width: 100%;
        scrollbar-width: none;
    }
    .page-scroll-body div[role="group"]::-webkit-scrollbar { display: none; }
    .page-scroll-body div[role="group"] button { white-space: nowrap; flex: 0 0 auto; }

    /* Tab strips NEVER clip (founder: COGS "Over…" cut off) — every .entity-tabs row becomes a
       horizontally swipeable strip; labels stay whole. Applies app-wide. */
    .entity-tabs {
        flex-wrap: nowrap !important;
        overflow-x: auto;
        max-width: 100%;
        min-width: 0;
        scrollbar-width: none;
    }
    .entity-tabs::-webkit-scrollbar { display: none; }
    .entity-tabs .entity-tab, .entity-tabs button { white-space: nowrap; flex: 0 0 auto; }

    /* Combined "tabs left · controls right" toolbars (COGS etc.): on a phone the controls are wider
       than the screen and the row's inline overflow:hidden CLIPS them ("↻ Refr…"). Wrap instead:
       tabs strip on line 1 (full width), controls wrap below. !important beats the inline styles. */
    .app-main div:has(> .entity-tabs) {
        flex-wrap: wrap;
        overflow: visible !important;
    }
    .app-main div:has(> .entity-tabs) > .entity-tabs { flex: 1 1 100%; }
    .app-main div:has(> .entity-tabs) > div {
        flex-wrap: wrap;
        border-left: 0 !important;
        padding: var(--space-2) !important;
        max-width: 100%;
        row-gap: var(--space-2);
    }

    /* Touch-target floor (audit finding: 18-28px buttons — GM toggles, pagination «», ℹ info).
       Visual glyphs stay small; the tappable box grows. */
    .app-main button, .app-main select { min-height: 34px; }
    .pagination-btn { min-width: 34px; }

    /* =======================================================================
       14. BOTTOM NAVIGATION (M3 navigation bar) — the app's primary nav on phone.
           4 role-aware destinations + More (opens the full gated nav as a bottom
           sheet). Pattern generalized from the shipped .msp-tabbar / .field-tabbar.
       ======================================================================= */
    .m-bottomnav {
        display: flex;
        position: fixed;
        left: 0; right: 0; bottom: 0;
        height: var(--m-bottomnav-total);
        padding-bottom: var(--m-safe-bottom);
        background: var(--paper);
        border-top: 1px solid var(--border);
        box-shadow: 0 -2px 12px rgba(0,0,0,.06);
        z-index: 95;                        /* above content+FAB(90); below app bar(100)/sheet */
    }
    .m-tab {
        flex: 1 1 0; min-width: 0;
        display: flex; flex-direction: column; align-items: center; justify-content: center;
        gap: 2px;
        border: 0; background: none; cursor: pointer;
        color: var(--ink-500);
        font-size: 10px; font-weight: 600; letter-spacing: .02em;
        text-decoration: none;
        min-height: var(--m-bottomnav-h);
        padding: var(--space-1) 0;
        border-top: 2px solid transparent;   /* msp-tab active indicator style */
    }
    .m-tab:hover { text-decoration: none; color: var(--ink-700); }
    .m-tab:focus-visible { outline: 2px solid var(--brand-orange); outline-offset: -2px; }
    .m-tab.active {
        color: var(--brand-orange);
        border-top-color: var(--brand-orange);
        font-weight: 700;
    }
    .m-tab-icon { font-size: 20px; line-height: 1; }
    .m-tab-icon svg { width: 20px; height: 20px; }
    .m-tab-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

    /* =======================================================================
       15. Nav model (founder 2026-07-18): the ☰ hamburger + LEFT slide-in drawer
           is the FULL navigation (drawer CSS = section 1); the bottom bar holds
           each role's quick feature shortcuts. No bottom-sheet restyle.
       ======================================================================= */
    .app-sidebar .sidebar-nav { overscroll-behavior: contain; }
    /* My Space's own tab bar retires — the global bottom nav covers those pages. */
    .msp-tabbar { display: none !important; }
    /* Reserve bottom-nav space on plain (non-fullbleed) pages too. */
    .app-main { padding-bottom: calc(var(--m-bottomnav-total) + var(--space-4)); }

    /* =======================================================================
       16. APP BAR v2 — page title as the anchor (founder: "user doesn't know
           which page he is on"); search collapses behind an icon.
       ======================================================================= */
    .topbar-brand-mobile-text { display: none; }        /* logo stays; title replaces wordmark */
    .m-appbar-title {
        display: block;
        min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
        font-family: var(--font-display);
        font-size: 16px; letter-spacing: .05em; text-transform: uppercase;
        color: inherit;
    }
    /* Search: hidden until the icon opens it as a full-width overlay under the app bar.
       Icon renders only when the page registered a topbar search (.m-has-search set by JS). */
    .topbar-search-wrap { display: none; }
    .app-shell.m-has-search .m-search-btn { display: inline-flex; align-items: center; justify-content: center; }
    .app-shell.m-search-open .topbar-search-wrap {
        display: block;
        position: fixed;
        top: calc(var(--topbar-h) + var(--m-safe-top));
        left: 0; right: 0;
        background: var(--ink-950);
        padding: var(--space-2) var(--space-3);
        z-index: 99;
        box-shadow: var(--shadow-lg);
    }
    .app-shell.m-search-open .topbar-search-wrap input { width: 100%; min-height: 40px; }
}

/* Desktop: mobile-only chrome never renders ≥720px (same guard style as the base rules). */
.m-bottomnav { display: none; }
.m-search-btn { display: none; }
.m-appbar-title { display: none; }
.m-desk-only { display: none; }
@media (max-width: 719.98px) {
    .m-bottomnav { display: flex; }

    /* Desk-only pages (matrix / bulk-entry): show the polite card, hide the squeezed content. */
    .m-desk-only {
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: var(--space-3);
        margin: var(--space-8) var(--space-4);
        padding: var(--space-8) var(--space-4);
        background: var(--paper);
        border: 1px solid var(--border);
        border-radius: var(--r-xl);
        box-shadow: var(--shadow-sm);
        color: var(--ink-700);
    }
    .m-desk-only-icon { color: var(--ink-400); }
    .m-desk-only h2 { font-size: 17px; margin: 0; color: var(--ink-900); }
    .m-desk-only p { font-size: 13px; margin: 0; max-width: 34ch; color: var(--ink-500); }
    .fullbleed-page:has(> .m-desk-only) > *:not(.m-desk-only) { display: none !important; }
}
