/* =========================================================================
   MAGNET — RESPONSIVE SHELL FOUNDATIONS
   Structure only. No redesign. Everything below references existing tokens
   (tokens.css) — spacing scale, radii, shadows, colours, typography.

   Breakpoints (single source of truth):
     desktop  ≥ 1025px   — current grid shell, unchanged
     tablet   641–1024px — sidebar auto-collapses, expands as an OVERLAY
     mobile   ≤ 640px    — sidebar hidden, bottom nav + quick-action FAB

   Reusable components added here:
     .app                 DesktopShell        (existing grid — documented, not restyled)
     .sb-scrim            TabletSidebarOverlay (dim layer behind floating sidebar)
     .mobile-bottom       MobileShell         (fixed bottom region: nav + FAB)
     .bottom-nav          MobileBottomNav
     .quick-fab           QuickActionButton
     .quick-sheet         QuickActionsSheet
     .mobile-page         MobilePageContainer (opt-in per-page wrapper, used later)
   ========================================================================= */

:root {
  /* ---- Safe-area spacing (iPhone notch / home indicator) ----------- */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);

  /* ---- Responsive shell metrics ------------------------------------ */
  --sidebar-rail:   84px;   /* collapsed icon rail (matches .app.collapsed) */
  --bottomnav-h:    60px;   /* mobile bottom bar content height */
  --mobile-topbar-h:54px;   /* compact mobile header height */
}

/* =========================================================================
   TABLET — 641 … 1024px
   The grid main column is flexible (1fr). When the sidebar is expanded it
   floats OVER the content instead of widening the column and pushing it.
   ========================================================================= */
/* Standard sheet header is mobile-only — hidden by default; the mobile media
   query (FilterSheet block) sets display:flex. Visual styles live here in base
   so the Design System can preview it on desktop. Baked into static menus so
   it only appears when they render as bottom sheets. */
.sheet-head {
  position: relative; display: none; align-items: center; gap: 8px;
  /* the sheet container contributes 12px above (its top inset), so 0 here +
     12px below keeps the buttons/title perfectly centred — 12px all around,
     matching the 12px side padding */
  min-height: 56px; padding: 0 6px 12px;
  border-bottom: 1px solid var(--border);
}
.sheet-head-title {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  font-size: var(--text-base); font-weight: var(--fw-semibold);
  color: var(--text-strong); pointer-events: none;
  max-width: 58%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sheet-head-x, .sheet-head-ok {
  width: 44px; height: 44px; border-radius: var(--radius-full); flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.sheet-head-x { background: var(--surface-field); color: var(--text-strong); }
@media (hover: hover) and (pointer: fine) {
  .sheet-head-x:hover { background: var(--border); }
}
.sheet-head-x svg { width: 18px; height: 18px; }
.sheet-head-ok { margin-left: auto; background: var(--primary-600); color: var(--on-primary); }
.sheet-head-ok svg { width: 19px; height: 19px; }

@media (min-width: 641px) and (max-width: 1024px) {
  /* Reserve a fixed 84px rail and pin the page content to column 2 so it
     NEVER shifts. The sidebar is always absolute (floating); expanding only
     animates its own width (84 → full) on top of the content — same open
     motion as desktop, minus the content push. */
  .app {
    grid-template-columns: var(--sidebar-rail) 1fr;
  }
  .app > .main { grid-column: 2; }

  .app > .sidebar {
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-rail);
    z-index: var(--z-popover);
    transition: width var(--dur-slow) var(--ease), box-shadow var(--dur-slow) var(--ease);
  }
  .app:not(.collapsed) > .sidebar {
    width: var(--sidebar-w);
    box-shadow: var(--shadow-lg);
  }
  /* dim layer behind the floating sidebar — tap to collapse */
  .app:not(.collapsed) > .sb-scrim { opacity: 1; pointer-events: auto; }
}

/* TabletSidebarOverlay scrim — only ever active on tablet (see media query) */
.settings-nav-scrim { display: none; }   /* shown only on mobile (settings drawer) */
.sb-scrim {
  display: none;
  position: absolute; inset: 0;
  z-index: calc(var(--z-popover) - 1);
  background: rgba(20, 20, 28, 0.42);
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur) var(--ease);
}
@media (min-width: 641px) and (max-width: 1024px) {
  .sb-scrim { display: block; }
}

/* =========================================================================
   MOBILE — ≤ 640px
   Desktop sidebar fully hidden. Compact top header. Fixed bottom nav + FAB.
   ========================================================================= */
@media (max-width: 640px) {
  /* viewport-accurate height so the bottom bar never floats over fold */
  .app-frame { height: 100dvh; }

  /* single column — desktop sidebar removed from layout entirely */
  .app { grid-template-columns: 1fr; }
  .app > .sidebar { display: none; }
  .sb-scrim { display: none; }

  /* ---- compact top header (MobileShell header) -------------------- */
  .topbar.shell-header {
    height: calc(var(--mobile-topbar-h) + var(--safe-top));
    padding-top: var(--safe-top);
    padding-left: max(var(--space-4), var(--safe-left));
    padding-right: max(var(--space-4), var(--safe-right));
    gap: var(--space-2);
  }
  /* drop the wide AI search (mobile uses the FAB search sheet) */
  .topbar .search,
  .topbar.search-open .search { display: none; }
  .topbar-right { gap: 8px; }
  .topbar .crumb { font-size: var(--text-base); }
  .topbar .crumb .ico {
    min-width: 24px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
  .topbar-right .btn,
  .topbar-right .btn-icon {
    min-width: 44px;
    height: 44px;
  }
  .topbar-right .btn-icon {
    width: 44px;
    padding: 0;
  }
  .topbar-right .btn svg {
    width: 19px;
    height: 19px;
  }
  .topbar-right .segmented {
    min-height: 44px;
    padding: 4px;
  }
  .topbar-right .segmented button {
    height: 36px;
    min-width: 58px;
    padding: 0 14px;
    font-size: var(--text-sm);
  }

  /* page toolbar row — let it scroll horizontally rather than wrap/clip */
  .main-toolbar.shell-header {
    padding-left: max(var(--space-4), var(--safe-left));
    padding-right: max(var(--space-4), var(--safe-right));
  }

  /* ---- page content: clear the bottom bar, respect side safe areas -- */
  .view-scroll {
    padding-bottom: calc(var(--bottomnav-h) + var(--space-6) + var(--safe-bottom));
    scrollbar-gutter: auto;
  }

  .keyboard-up:not(.keyboard-avoidance-paused) .view-scroll {
    padding-bottom: calc(var(--bottomnav-h) + var(--space-6) + var(--safe-bottom) + var(--app-keyboard-height, 0px));
  }

  .keyboard-up:not(.keyboard-avoidance-paused) .view-scroll,
  .keyboard-up:not(.keyboard-avoidance-paused) .drawer-body,
  .keyboard-up:not(.keyboard-avoidance-paused) .td-scroll,
  .keyboard-up:not(.keyboard-avoidance-paused) .ne-scroll,
  .keyboard-up:not(.keyboard-avoidance-paused) .modal-body,
  .keyboard-up:not(.keyboard-avoidance-paused) .sched-body,
  .keyboard-up:not(.keyboard-avoidance-paused) .settings-body,
  .keyboard-up:not(.keyboard-avoidance-paused) .cal-time-body {
    scroll-padding-bottom: calc(var(--app-keyboard-height, 0px) + 24px);
  }

  /* Anchored bottom sheets stay put when the keyboard opens (native reveal scroll
     is suppressed); instead their OWN scroll container gets keyboard-height of
     extra bottom room so the in-app avoidance can lift any focused input clear of
     the keyboard by scrolling inside the sheet — never by moving the sheet. The
     padding sits below the fold, so adding/removing it doesn't shift visible
     content. (.view-scroll has its own keyboard padding above.) */
  .keyboard-up:not(.keyboard-avoidance-paused) .drawer-body,
  .keyboard-up:not(.keyboard-avoidance-paused) .td-scroll,
  .keyboard-up:not(.keyboard-avoidance-paused) .ne-scroll,
  .keyboard-up:not(.keyboard-avoidance-paused) .modal-sheet .modal-body,
  .keyboard-up:not(.keyboard-avoidance-paused) .sched-body,
  .keyboard-up:not(.keyboard-avoidance-paused) .cal-time-body {
    padding-bottom: calc(var(--app-keyboard-height, 0px) + 24px);
  }
}

/* =========================================================================
   MobileShell — fixed bottom region holding the nav bar + quick FAB.
   Hidden by default; shown only at ≤640px (rule above).
   ========================================================================= */
.mobile-bottom {
  display: none;
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--space-3) + var(--safe-bottom));   /* float above the edge */
  z-index: var(--z-toolbar);
  align-items: stretch;
  gap: var(--space-3);
  padding-left: max(var(--space-4), var(--safe-left));
  padding-right: max(var(--space-4), var(--safe-right));
  pointer-events: none;   /* let taps fall through the gaps between pieces */
}
.mobile-bottom > * { pointer-events: auto; }
/* The mobile search sheet is kept mounted at every width (preloaded so the first
   tap is instant), but it's a phone-only UI. Hide it by default — otherwise above
   640px it has no layout rules and renders as a stray block with a full-width
   icon. The max-width:640px block below lays it out (display:flex wins on source
   order). */
.mobile-search-sheet { display: none; }
/* show the bottom region only on mobile. Declared AFTER the base rule above so
   it wins on source order (equal specificity); also hide the dashboard's
   secondary toolbar on mobile. */
@media (max-width: 640px) {
  .mobile-bottom { display: flex; }
  #main:has(#viewScroll > .dash) #mainToolbar { display: none; }

  /* New Event is reachable via the calendar FAB on mobile — hide the
     redundant toolbar button so it isn't shown twice. */
  [data-new-event] { display: none; }

  /* Clients toolbar: "Create new profile" shrinks to an icon-only + button —
     with its label the toolbar ran ~535px wide (unreachable overflow), and
     the quick sheet's "Clients" entry only browses, so create must stay. */
  #mainToolbar [data-new-client] { width: 36px; height: 36px; padding: 0; justify-content: center; }
  #mainToolbar [data-new-client] > span { display: none; }
  /* Keep the Grid/List/Performance switch compact like the calendar's
     Month/Day segmented control. The toolbar spacer places it beside create
     (+) on the right instead of stretching three icons across the whole row. */
  #mainToolbar .proj-viewseg { flex: 0 0 auto; }
  #mainToolbar .proj-viewseg button {
    display: inline-flex;
    align-items: center;
    flex: 0 0 44px;
    width: 44px;
    padding: 0;
    justify-content: center;
  }
  /* the All/Pinned/Overdue/Inactive segment collapses into the ⋮ kebab that
     applyMobileLeadTools moves up beside the "Clients" crumb (its .filter-menu
     renders as the shared FilterSheet, same as Tasks/Leads). */
  #mainToolbar .proj-filterseg { display: none; }
  .topbar-right .proj-filterdd.tb-moved { display: block; }

  /* Client detail: section navigation moves into the topbar as a labelled
     selector, with a separate ⋮ actions sheet. The overview toolbar disappears
     entirely; other tabs retain only their context-specific actions. */
  .topbar-right .client-sectiondd.tb-moved,
  .topbar-right .client-actionsdd.tb-moved { display: block; }
  .topbar-right .client-section-trigger {
    max-width: 116px;
    padding: 0 10px 0 12px;
    gap: 5px;
  }
  .topbar-right .client-section-trigger > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .topbar-right .client-section-trigger > svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
  }
  #mainToolbar[data-route="client"] .cd-tabseg,
  #mainToolbar[data-route="client"] .cd-overview-actions { display: none; }
  #mainToolbar[data-route="client"]:has(.cd-overview-actions) { display: none; }
  #mainToolbar[data-route="client"] {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #mainToolbar[data-route="client"]::-webkit-scrollbar { display: none; }
  #mainToolbar[data-route="client"] > * { flex-shrink: 0; }

  /* Keep the breadcrumb readable beside the two client-detail controls. */
  .topbar .crumb:has(.crumb-client) {
    flex: 1;
    min-width: 0;
    overflow: hidden;
  }
  .topbar .crumb:has(.crumb-client) .crumb-link,
  .topbar .crumb:has(.crumb-client) .crumb-sep { flex-shrink: 0; }
  .topbar .crumb .crumb-client {
    min-width: 0;
    overflow: hidden;
  }
  .crumb-client-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Assignment belongs with client identity on mobile; edit/delete live in the
     topbar actions sheet, so the duplicate title pencil is removed. */
  .cd-title-wrap { min-width: 0; flex: 1; }
  .cd-title { width: 100%; min-width: 0; }
  .cd-title-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .cd-title .cd-edit { display: none; }
  .cd-sub { flex-wrap: nowrap; }
  .cd-mobile-assign {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-height: 28px;
    padding: 0 9px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-field);
    color: var(--text);
    font-size: var(--text-xs);
    font-weight: var(--fw-semibold);
    margin-left: auto;
    flex-shrink: 0;
  }
  .cd-mobile-assign svg { width: 14px; height: 14px; color: var(--primary-600); }

  /* Create note + Manage templates live in the FAB / elsewhere on mobile, so
     the notes toolbar row is empty — hide it (keep the empty-state CTA). */
  #mainToolbar[data-route="notes"] { display: none; }

  /* Calendars filter → icon-only on mobile (drop the label). It is relocated
     into the topbar next to the Month/Day toggle by applyMobileLeadTools(). */
  .cal-filter-btn { width: 44px; height: 44px; padding: 0; justify-content: center; }
  .cal-filter-btn > span { display: none; }

  /* mobile calendar: the period label now lives in the topbar crumb (tappable →
     today) and paging is by swipe, so the second toolbar row is empty — hide it. */
  #mainToolbar[data-route="calendar"] { display: none; }
  .cal-crumb-date {
    background: none; border: none; padding: 0 2px; margin: 0;
    font: inherit; cursor: pointer; min-height: 44px;
    display: inline-flex; align-items: center; gap: 5px;
  }
  .cal-crumb-date:active { opacity: 0.55; }

  /* settings: the nav rail becomes a left slide-in drawer; the crumb toggles it */
  .app > .settings-sidebar {
    display: flex;
    position: fixed; top: 0; bottom: 0; left: 0;
    width: min(84vw, 320px);
    z-index: calc(var(--z-popover) + 4);
    transform: translateX(-100%);
    transition: transform 280ms cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: var(--shadow-lg);
  }
  body.settings-nav-open .app > .settings-sidebar { transform: translateX(0); }
  .settings-nav-scrim {
    display: block; position: fixed; inset: 0;
    z-index: calc(var(--z-popover) + 3);
    background: rgba(11, 11, 15, 0.4);
    opacity: 0; pointer-events: none;
    transition: opacity 240ms cubic-bezier(0.22, 1, 0.36, 1);
  }
  body.settings-nav-open .settings-nav-scrim { opacity: 1; pointer-events: auto; }
  .settings-nav-toggle {
    display: inline-flex; align-items: center; gap: var(--space-2);
    background: none; border: none; padding: 0; margin: 0; font: inherit;
    cursor: pointer; color: inherit; min-height: 44px;
  }
  .settings-nav-toggle .ico { color: var(--text-strong); display: inline-flex; }
  .settings-nav-toggle .ico svg { width: 19px; height: 19px; }
  .settings-nav-toggle > svg:last-child { width: 16px; height: 16px; color: var(--text-soft); }
  @media (prefers-reduced-motion: reduce) {
    .app > .settings-sidebar, .settings-nav-scrim { transition: none; }
  }

  /* leads filter controls moved into the topbar — Status & Filter become
     icon-only; the view switch keeps its label. */
  .topbar-right .tb-moved { flex-shrink: 0; }
  .topbar-right #filterDd .btn,
  .topbar-right #orderDd .btn {
    width: 44px; height: 44px; padding: 0; justify-content: center;
  }
  .topbar-right #filterDd .btn > span,
  .topbar-right #filterDd .btn > svg:last-child,
  .topbar-right #orderDd .btn > span,
  .topbar-right #orderDd .btn > svg:last-child { display: none; }
  /* Add lead — icon-only (+) in the topbar, like the other moved controls */
  .topbar-right [data-new-lead].tb-moved { width: 44px; height: 44px; padding: 0; justify-content: center; }
  .topbar-right [data-new-lead].tb-moved > span { display: none; }
  /* the ⋮ kebab replaces the Status/Filter/View triggers — the filter dd's move
     up only so their menus can render as bottom sheets; triggers hide */
  .topbar-right .leads-tools-dd.tb-moved { display: block; }
  .topbar-right #filterDd > .btn,
  .topbar-right #orderDd > .btn { display: none; }
  /* disabled status (board view) → icon-only too */
  .topbar-right > button.btn.tb-moved[disabled] {
    width: 44px; height: 44px; padding: 0; justify-content: center;
  }
  .topbar-right > button.btn.tb-moved[disabled] > span,
  .topbar-right > button.btn.tb-moved[disabled] > svg:last-child { display: none; }
  /* keyboard-attached mobile search sheet (opened from the Leads FAB). */
  .mobile-search-sheet {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: calc(var(--z-popover) + 3);
    padding: var(--space-3) max(var(--space-4), var(--safe-right))
             calc(var(--space-3) + var(--safe-bottom)) max(var(--space-4), var(--safe-left));
    background: var(--surface);
    border-top: 1px solid var(--border);
    border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    box-shadow: var(--shadow-lg);
    will-change: padding-bottom, transform, opacity;
    overflow: visible;
    opacity: 0;
  }
  /* Kept mounted + warm between opens (preloadMobileSearchSheet) so the first
     tap pays no init cost. Invisible (opacity:0 from the base rule) and inert so
     it never intercepts taps on the bottom nav / FAB while idle. */
  .mobile-search-sheet.is-preload {
    pointer-events: none;
    transform: translateY(100%);
  }
  .mobile-search-sheet.is-ready { opacity: 1; }
  .mobile-search-sheet.is-kb {
    padding-bottom: var(--space-3);
  }
  .mobile-search-sheet::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(-1 * var(--keyboard-offset, 0px));
    height: var(--keyboard-offset, 0px);
    background: var(--surface);
    pointer-events: none;
  }
  .mobile-search-sheet.is-closing {
    opacity: 0;
    transform: translateY(calc(100% - var(--keyboard-offset, 0px)));
  }
  .mobile-search-field {
    flex: 1;
    min-width: 0;
    height: 48px;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 0 var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface-field);
    color: var(--text-soft);
  }
  .mobile-search-field svg {
    width: 19px;
    height: 19px;
    color: var(--primary-500);
    flex-shrink: 0;
  }
  .mobile-search-field input {
    width: 100%;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
    font-size: var(--text-base);
  }
  .mobile-search-field input:focus,
  .mobile-search-field input:focus-visible {
    outline: none;
    border: 0;
    box-shadow: none;
  }
  .mobile-search-field input::placeholder { color: var(--text-soft); }
  .mobile-search-field input::-webkit-search-cancel-button { display: none; }
  .mobile-search-close {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    background: var(--surface-field);
    color: var(--text);
  }
  .mobile-search-close svg {
    width: 20px;
    height: 20px;
  }
  /* =======================================================================
     FilterSheet — ONE shared bottom-sheet shell, reused by every filter /
     picker popover on mobile: the leads Status & Sort menus, the lead stage /
     follow-up picker, and the calendar "Calendars" filter. Each control keeps
     its own inner markup; this shell standardises the surface, top radius,
     grab handle, slide-up animation and scrim. Built on shared tokens.
     ======================================================================= */
  .filter-sheet,
  .topbar-right .filter-dd .filter-menu,
  .stage-picker.sp-sheet,
  .cal-filt-pop {
    position: fixed; left: 0; right: 0; top: auto; bottom: 0;
    width: 100%; min-width: 0; max-height: 80dvh; overflow-y: auto;
    border: none; border-top: 1px solid var(--border);
    border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    padding: var(--space-2) max(var(--space-3), var(--safe-left))
             calc(var(--space-4) + var(--safe-bottom)) max(var(--space-3), var(--safe-right));
    box-shadow: var(--shadow-lg);
    z-index: calc(var(--z-popover) + 2);
    animation: leadSheetUp var(--motion-sheet-open) var(--ease-enter);   /* shared open curve, matching every other sheet */
  }
  /* (grab-handle pill removed — sheets are dismissed by swipe-down / scrim /
     the header X; a small top inset keeps the chrome from hugging the edge) */
  .filter-sheet,
  .topbar-right .filter-dd .filter-menu,
  .stage-picker.sp-sheet,
  .cal-filt-pop { padding-top: var(--space-3); }
  /* comfortable (≥48px) tap targets inside any filter sheet */
  .filter-sheet .filter-opt,
  .topbar-right .filter-dd .filter-menu .filter-opt,
  .stage-picker.sp-sheet .filter-opt,
  .stage-picker.sp-sheet .sp-fu { min-height: 48px; font-size: var(--text-base); }
  .cal-filt-pop .cal-filt-row { min-height: 48px; padding: 10px 8px; }
  /* the sheet header now provides the title — hide the inline one, keep Select all */
  .cal-filt-pop.filter-sheet .cal-filt-head { justify-content: flex-end; }
  .cal-filt-pop.filter-sheet .cal-filt-head > span:first-child { display: none; }
  /* ===== Standard sheet header — shown on mobile (visual styles in base) ====
     Circular X (left) · centered title · primary tick (right). Matches the
     note editor + drawer sheets so every bottom sheet reads the same. */
  .sheet-head {
    display: flex;
    margin: 0 calc(-1 * max(var(--space-3), var(--safe-right))) 4px
            calc(-1 * max(var(--space-3), var(--safe-left)));
    padding-left: max(var(--space-3), var(--safe-left));
    padding-right: max(var(--space-3), var(--safe-right));
  }
  /* the standard sheet header sits just below the shared grab handle */

  /* shared scrim — dim layer that blocks page hover/clicks and dismisses on tap */
  .filter-sheet-scrim,
  .sheet-scrim,
  .sp-scrim {
    position: fixed; inset: 0;
    z-index: calc(var(--z-popover) + 1);
    background: var(--sheet-scrim);
  }
  /* leads filter sheets: fade the dim in alongside the sheet's slide-up */
  .lead-menu-scrim { animation: scrimFade var(--motion-overlay) var(--ease-enter); }

  /* remove the leads settings (gear) + Exports button on mobile */
  #mainToolbar[data-route="reports"] [data-leadsettings],
  #mainToolbar[data-route="reports"] .btn-split:has(.btn-primary) { display: none; }
  /* remove the date-scope ("All time") control on mobile */
  #mainToolbar[data-route="reports"] #sortDd { display: none; }
  /* with Status/Filter/view moved to the topbar and the rest removed, the
     leads toolbar row is empty on mobile — hide it entirely */
  #mainToolbar[data-route="reports"] { display: none; }

  /* Content tab — the toolbar row carries client tabs + Sharing|Scheduling +
     the primary action; go icon-only on the right side so it all fits (the
     client tabs' ResponsiveTabs collapse handles the left), and tighten the
     row's padding/gaps — 24px gutters + 12px gaps don't fit on 375px */
  #mainToolbar .ch-tabs button span,
  #mainToolbar [data-cc-new-share] span,
  #mainToolbar [data-cc-compose] span { display: none; }
  #mainToolbar { padding: 0 var(--space-4); gap: var(--space-2); }
  #mainToolbar .ch-tabs button { padding: 0 10px; }

  /* Tasks — the All/Today/Upcoming segmented collapses into a kebab (3-dot)
     menu relocated to the topbar top-right; its menu renders as the shared
     FilterSheet. The toolbar row is then empty — hide it. */
  #mainToolbar[data-route="tasks"] { display: none; }
  .topbar-right .tasks-viewdd.tb-moved { display: block; }
  .topbar-right .tasks-view-trigger {
    width: auto;
    min-width: 44px;
    padding: 0 10px 0 12px;
    gap: 4px;
  }
  .topbar-right .tasks-view-trigger .tasks-view-current {
    font-size: var(--text-sm);
    font-weight: var(--fw-semibold);
    line-height: 1;
  }
  .topbar-right .tasks-view-trigger svg { flex-shrink: 0; }
  /* the inline capture bar gives way to the FAB-opened quick-add composer */
  .ctasks .task-qa { display: none; }
  /* the due-date + priority pickers join the FilterSheet shell but must stay
     ABOVE the quick-add composer (+3) — the generic shell z (+2) would sink them */
  .td-due-menu.filter-sheet, .td-pri-menu.filter-sheet { z-index: calc(var(--z-popover) + 4); }
  .td-due-scrim { z-index: calc(var(--z-popover) + 4); }
  /* finger-sized priority options, like the due presets */
  .td-pri-menu.filter-sheet [data-pri] { min-height: 48px; font-size: var(--text-base); border-radius: var(--radius-md); }
  .td-pri-menu.filter-sheet { gap: 2px; }
  /* finger-sized quick-action icons in the sheet (≥48px) */
  .td-due-menu.filter-sheet .td-due-quick { gap: var(--space-2); margin: var(--space-3) 0 var(--space-2); }
  .td-due-menu.filter-sheet .td-due-quick button { height: 48px; border-radius: var(--radius-md); }
  .td-due-menu.filter-sheet .td-due-quick button svg { width: 20px; height: 20px; }
  /* swipe-down dismiss (wireSheetDrag) — drag wins on the handle/header
     chrome, content keeps vertical scroll (same split as .drawer.sheet) */
  .td-due-menu.filter-sheet { touch-action: none; }
  .td-due-menu.filter-sheet .td-due-quick,
  .td-due-menu.filter-sheet .sp-dtp,
  .td-due-menu.filter-sheet .td-time-list { touch-action: pan-y; }
  /* finger-sized Time button + time slots in the sheet */
  .td-due-menu.filter-sheet .td-due-time-btn { height: 48px; font-size: var(--text-base); border-radius: var(--radius-md); }
  .td-due-menu.filter-sheet .td-time-list { max-height: 46vh; overscroll-behavior: contain; }
  .td-due-menu.filter-sheet .td-time-slot { height: 40px; font-size: var(--text-base); }
  .td-due-menu.filter-sheet .td-time-clear { height: 44px; font-size: var(--text-base); border-radius: var(--radius-md); }
  /* finger-sized footer (Clear + OK, equal width) */
  .td-due-menu.filter-sheet .td-due-foot .td-due-clear,
  .td-due-menu.filter-sheet .td-due-foot .td-due-done { height: 48px; font-size: var(--text-base); }
}

/* Preserve the client name on very narrow phones by reducing the breadcrumb
   back affordance to its familiar Clients icon. */
@media (max-width: 360px) {
  .topbar .crumb:has(.crumb-client) { gap: 6px; }
  .topbar .crumb:has(.crumb-client) .crumb-link-label,
  .topbar .crumb:has(.crumb-client) .crumb-sep { display: none; }
  .topbar-right .client-section-trigger { max-width: 104px; }
}

/* bottom fade layer — above page content, behind the floating nav.
   Hidden by default; shown only on mobile (rule below, after the base so it
   wins on source order). Never blocks taps. */
.mobile-bottom-fade {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(104px + var(--safe-bottom));
  z-index: calc(var(--z-toolbar) - 1);
  pointer-events: none;
  background: linear-gradient(to bottom, transparent, rgba(20, 20, 28, 0.06));
}
@media (max-width: 640px) {
  .mobile-bottom-fade { display: block; }
}

/* ---- MobileBottomNav — floating glass tab bar (Apple HIG style) ----- */
.bottom-nav {
  flex: 1;
  display: flex;
  align-items: stretch;
  gap: var(--space-1);
  min-width: 0;
  padding: 6px;
  border-radius: var(--radius-full);
  /* frosted liquid glass: translucent fill + heavy blur/saturation, a bright
     top edge highlight and soft outer shadow for the "lifted glass" feel */
  background: color-mix(in srgb, var(--surface) 60%, transparent);
  -webkit-backdrop-filter: blur(28px) saturate(200%);
  backdrop-filter: blur(28px) saturate(200%);
  border: 1px solid color-mix(in srgb, #ffffff 28%, var(--border));
  box-shadow:
    var(--shadow-lg),
    inset 0 1px 1px rgba(255, 255, 255, 0.55),
    inset 0 -1px 1px rgba(20, 20, 28, 0.04);
}
.bottom-nav-item {
  flex: 1;
  min-width: 0;
  min-height: 44px;                 /* ≥44px tap target */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: var(--space-1) 2px;
  border-radius: var(--radius-full);
  color: var(--text);
  font-size: var(--text-2xs);
  font-weight: var(--fw-semibold);
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.bottom-nav-item svg { width: 22px; height: 22px; }
.bottom-nav-item .bn-label {
  max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bottom-nav-item.active { color: var(--primary-600); background: color-mix(in srgb, var(--primary-600) 12%, transparent); }
.bottom-nav-item.active svg { color: var(--primary-600); }

/* Tab badge (Tasks due-count) — a small count pill pinned to the icon's
   top-right, app-badge style. Injected by ResponsiveShell.setTabBadge;
   removed entirely at zero, so an empty pill never renders. */
.bottom-nav-item { position: relative; }
.bottom-nav-item .bn-badge {
  position: absolute;
  top: 3px; left: calc(50% + 6px);
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 999px;
  background: var(--primary-600); color: var(--on-primary);
  font-size: 10px; font-weight: var(--fw-semibold); line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  pointer-events: none;
  box-shadow: 0 0 0 2px var(--surface);   /* ring so it reads over the icon */
}

/* ---- QuickActionButton — circular, separate floating action -------- */
.quick-fab {
  flex: 0 0 auto;
  align-self: center;
  width: 56px; height: 56px;        /* fixed square → perfect circle */
  border-radius: var(--radius-full);
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary-600);
  color: var(--on-primary);
  box-shadow: var(--shadow-lg), var(--primary-glow-lg), inset 0 1px 1px rgba(255, 255, 255, 0.35);
  transition: background var(--dur) var(--ease), transform var(--dur-fast) var(--ease);
}
.quick-fab svg { width: 24px; height: 24px; }
  @media (hover: hover) and (pointer: fine) {
    .quick-fab:hover { background: var(--primary-700); }
  }
.quick-fab:active { transform: scale(0.94); }
.quick-fab.is-open { background: var(--primary-700); }

/* =========================================================================
   QuickActionsSheet — bottom sheet of quick actions (mobile).
   Built on the same scrim/surface/radius/shadow tokens as Modal.
   ========================================================================= */
.quick-sheet-scrim {
  position: fixed; inset: 0;
  z-index: var(--z-popover);
  background: var(--sheet-scrim);
  opacity: 0; pointer-events: none;
  transition: opacity var(--motion-overlay) var(--ease-enter);
}
.quick-sheet-scrim.show { opacity: 1; pointer-events: auto; }

.quick-sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: calc(var(--z-popover) + 1);
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-top-left-radius: var(--radius-2xl);
  border-top-right-radius: var(--radius-2xl);
  box-shadow: var(--shadow-lg);
  padding: var(--space-3)
           max(var(--space-4), var(--safe-right))
           calc(var(--space-4) + var(--safe-bottom))
           max(var(--space-4), var(--safe-left));
  transform: translateY(100%);
  transition: transform var(--motion-sheet-open) var(--ease-enter);
}
.quick-sheet.show { transform: translateY(0); }
.quick-sheet-handle { display: none; }
.quick-sheet-title {
  font-size: var(--text-2xs); font-weight: var(--fw-bold);
  letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-soft);
  padding: 0 var(--space-2) var(--space-2);
}
.quick-sheet-actions { display: flex; flex-direction: column; }
.quick-sheet-action {
  display: flex; align-items: center; gap: var(--space-3);
  width: 100%; min-height: 52px;     /* ≥44px tap target */
  padding: 0 var(--space-2);
  border-radius: var(--radius-md);
  color: var(--text); font-size: var(--text-base); font-weight: var(--fw-medium);
  text-align: left;
  transition: background var(--dur) var(--ease);
}
  @media (hover: hover) and (pointer: fine) {
    .quick-sheet-action:hover { background: var(--nav-hover-bg); }
  }
.quick-sheet-action:active { background: var(--surface-field); }
.quick-sheet-action .qa-ico {
  width: 40px; height: 40px; flex-shrink: 0;
  border-radius: var(--radius-md);
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-field); color: var(--primary-600);
}
.quick-sheet-action .qa-ico svg { width: 20px; height: 20px; }

/* =========================================================================
   MobilePageContainer — opt-in wrapper for per-page mobile work (later).
   Provides responsive padding + the bottom-bar clearance in one class so
   individual pages don't re-invent it when they're optimised one by one.
   ========================================================================= */
.mobile-page {
  padding: var(--space-5) var(--space-6);
}
@media (max-width: 640px) {
  .mobile-page {
    padding: var(--space-4) max(var(--space-4), var(--safe-left)) 0
             max(var(--space-4), var(--safe-right));
  }
}

/* leads toolbar reveal — slide-up bottom-sheet keyframe + reduced-motion */
@keyframes leadSheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes scrimFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes searchDrop { from { transform: translateY(-14px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@media (max-width: 640px) and (prefers-reduced-motion: reduce) {
  .filter-sheet,
  .topbar-right .filter-dd .filter-menu,
  .stage-picker.sp-sheet,
  .cal-filt-pop { animation: none; }
}
