/* ==========================================================================
   RCH OS v1.7-UX1 — Responsive Navigation & Controls Polish
   Last-mile responsive layer after the visual audit. It intentionally owns
   cross-module phone/tablet navigation geometry without changing permissions.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Territory — mobile action bar must remain a real grid.
   rch-ui-toolbar is a shared flex component, so Territory explicitly restores
   the fixed action-bar layout here.
   -------------------------------------------------------------------------- */
@media (max-width:56.25rem) {
  body.rch-territory-v1 .rch-mobile-action-bar.rch-ui-toolbar {
    display:grid !important;
    flex-direction:row !important;
    grid-template-columns:repeat(4,minmax(0,1fr)) !important;
    align-items:stretch !important;
    justify-content:stretch !important;
    gap:0 !important;
    padding:.25rem .25rem env(safe-area-inset-bottom,0px) !important;
  }

  body.rch-territory-v1:not(.mobile-panel-open) .rch-mobile-action-bar > :where(a,button):not(#mobileClosePanelsBtn) {
    display:flex !important;
    width:100% !important;
    min-width:0 !important;
  }

  body.rch-territory-v1:not(.mobile-panel-open) #mobileClosePanelsBtn {
    display:none !important;
  }

  body.rch-territory-v1.mobile-panel-open .rch-mobile-action-bar.rch-ui-toolbar {
    grid-template-columns:minmax(0,1fr) !important;
  }

  body.rch-territory-v1.mobile-panel-open .rch-mobile-action-bar > :where(a,button):not(#mobileClosePanelsBtn) {
    display:none !important;
  }

  body.rch-territory-v1.mobile-panel-open #mobileClosePanelsBtn {
    display:flex !important;
    width:100% !important;
    min-width:0 !important;
  }

  /* UX1 legibility floor: mobile navigation labels are operational copy,
     not decorative microcopy. Keep them at >=11px at every compact width. */
  body.rch-territory-v1 .rch-mobile-action-bar span {
    font-size:var(--rch-text-micro) !important;
    line-height:1.1 !important;
  }
}

/* Phone header: keep the four actions that matter most during field work.
   Respect role-ui: role-gated controls remain hidden when [hidden] is present. */
@media (max-width:30rem) {
  body.rch-territory-v1 #officeNavBtn:not([hidden]),
  body.rch-territory-v1 #analyticsBtn:not([hidden]) {
    display:inline-flex !important;
  }

  body.rch-territory-v1 #qualityBtn,
  body.rch-territory-v1 #exportBtn {
    display:none !important;
  }

  body.rch-territory-v1 .rch-home-command-zone {
    gap:.25rem !important;
  }

  body.rch-territory-v1 .rch-home-command-zone :where(.btn,.rch-ui-button) {
    width:2.45rem !important;
    min-width:2.45rem !important;
    max-width:2.45rem !important;
    height:2.45rem !important;
    min-height:2.45rem !important;
    padding:0 !important;
  }

  body.rch-territory-v1 .rch-home-command-zone :where(.btn,.rch-ui-button) span {
    display:none !important;
  }
}

/* --------------------------------------------------------------------------
   Office — Territory and refresh are part of the mobile shell, not optional
   desktop leftovers. Restore them after the legacy phone hide rule.
   -------------------------------------------------------------------------- */
@media (max-width:72rem) {
  body.rch-office-v1 .office-territory-link:not([hidden]) {
    display:inline-flex !important;
  }
}

@media (max-width:47.99rem) {
  body.rch-office-v1 #refreshBtn:not([hidden]),
  body.rch-office-v1 #refreshBtn.refresh-button:not([hidden]) {
    display:grid !important;
  }

  body.rch-office-v1 .office-territory-link:not([hidden]) {
    display:inline-flex !important;
  }
}

/* --------------------------------------------------------------------------
   Field — five stable destinations everywhere the bottom navigation exists.
   Historical Phase 6.4 rules used four columns and hid Mappa with a more
   specific !important selector. UX1 intentionally owns the final navigation
   contract: Attività / Timer / Controlli / Mappa / Profilo.
   -------------------------------------------------------------------------- */
body.rch-field-v1 .field-bottom-nav,
body.rch-field-v1 .field-app-shell.field-app-v154.field-native-app .field-bottom-nav {
  grid-template-columns:repeat(5,minmax(0,1fr)) !important;
}

body.rch-field-v1 .field-nav-controls,
body.rch-field-v1 .field-native-app .field-nav-controls,
body.rch-field-v1 .field-native-app.nav-context-tasks .field-nav-controls,
body.rch-field-v1 .field-native-app:not(.nav-context-tasks) .field-nav-controls,
body.rch-field-v1 .field-nav-map,
body.rch-field-v1 .field-native-app .field-nav-map,
body.rch-field-v1 .field-native-app:not(.nav-context-tasks) .field-nav-map {
  display:grid !important;
}

/* --------------------------------------------------------------------------
   Field — five stable destinations on phone.
   Attività / Timer / Controlli / Mappa / Profilo remain visible together.
   Hiding a destination contextually made navigation harder to discover.
   -------------------------------------------------------------------------- */
@media (max-width:48rem) {
  body.rch-field-v1 .field-bottom-nav {
    grid-template-columns:repeat(5,minmax(0,1fr)) !important;
  }

  body.rch-field-v1 .field-nav-controls,
  body.rch-field-v1 .field-nav-map {
    display:flex !important;
  }

  body.rch-field-v1 .field-bottom-tab {
    min-width:0 !important;
    padding-inline:.1rem !important;
  }

  body.rch-field-v1 .field-bottom-tab em {
    display:block !important;
    font-size:var(--rch-text-micro) !important;
    line-height:1 !important;
    white-space:nowrap !important;
  }
}

@media (max-width:22.5rem) {
  body.rch-field-v1 .field-bottom-tab em {
    display:block !important;
    font-size:var(--rch-text-micro) !important;
  }
}

/* Controls form: every grid level owns the available width explicitly.
   On tablet/compact landscape reserve a navigation-safe scroll tail so the
   fixed bottom nav cannot make the last editable fields unreachable. */
@media (max-width:68rem) {
  body.rch-field-v1 .field-tab-panel[data-field-panel="controls"],
  body.rch-field-v1 .field-controls-view,
  body.rch-field-v1 .rch-v160a1-ledger,
  body.rch-field-v1 .rch-v160a1-ledger-list,
  body.rch-field-v1 .rch-v160a1-ledger-list > .control-row,
  body.rch-field-v1 .rch-v160a1-ledger-main,
  body.rch-field-v1 .rch-v160a1-ledger-secondary {
    width:100% !important;
    min-width:0 !important;
    max-width:100% !important;
    box-sizing:border-box !important;
  }

  body.rch-field-v1 .field-app-shell {
    scroll-padding-bottom:calc(var(--field-nav-height) + 2.5rem + env(safe-area-inset-bottom,0px)) !important;
  }

  body.rch-field-v1 .field-controls-view {
    padding-bottom:calc(var(--field-nav-height) + 2.25rem + env(safe-area-inset-bottom,0px)) !important;
  }
}

@media (min-width:48.01rem) and (max-width:68rem) and (max-height:50rem) {
  body.rch-field-v1 .field-controls-view {
    padding-bottom:calc(var(--field-nav-height) + 4rem) !important;
  }
}


/* ==========================================================================
   UX1 Visual Grammar — controls, filters and editable typography
   ========================================================================== */

/* Territory filters: keep the 44px geometry already established, normalize
   the text scale and radius across search/select controls. */
body.rch-territory-v1 .rch-filter-panel :is(
  input.rch-ui-field:not([type="checkbox"]):not([type="radio"]),
  select.rch-ui-field,
  textarea.rch-ui-field
) {
  min-height:var(--rch-control-comfort) !important;
  border-radius:var(--rch-radius-control) !important;
  font-family:var(--rch-font-sans) !important;
  font-size:var(--rch-text-small) !important;
  line-height:1.25 !important;
}

body.rch-territory-v1 .rch-filter-panel #searchInput {
  font-size:var(--rch-text-body) !important;
}

/* Office operational toolbars: one baseline for search, filters and dates.
   The scope selector remains pill-shaped but follows the same type scale. */
body.rch-office-v1 :is(.table-toolbar,.compact-toolbar) :is(
  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  select
) {
  height:var(--rch-control-comfort) !important;
  min-height:var(--rch-control-comfort) !important;
  border-radius:var(--rch-radius-control) !important;
  font-family:var(--rch-font-sans) !important;
  font-size:var(--rch-text-body) !important;
  line-height:1.25 !important;
}

body.rch-office-v1 :is(.table-toolbar,.compact-toolbar) .btn {
  min-height:var(--rch-control-comfort) !important;
}

body.rch-office-v1 .scope-control select {
  font-family:var(--rch-font-sans) !important;
  font-size:var(--rch-text-small) !important;
  line-height:1.2 !important;
}

/* Field: operational input text must remain readable even where historical
   compact rules use micro type. Geometry stays task-specific; type does not. */
body.rch-field-v1 .field-native-app :is(
  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  select,
  textarea
) {
  font-family:var(--rch-font-sans) !important;
  font-size:.875rem !important;
  line-height:1.3 !important;
}

body.rch-field-v1 .field-sort-label select {
  min-height:var(--rch-control-comfort) !important;
  border-radius:var(--rch-radius-control) !important;
}

body.rch-field-v1 .field-search-card input {
  min-height:var(--rch-control-comfort) !important;
  font-size:var(--rch-text-body) !important;
}

body.rch-field-v1 .rch-v160a1-ledger-cell > :is(input,select,textarea),
body.rch-field-v1 .rch-v160a1-ledger-secondary :is(input,select,textarea) {
  min-height:var(--rch-control-comfort) !important;
  border-radius:var(--rch-radius-control) !important;
}

/* Phone editing: 16px avoids browser zoom and preserves legibility.
   Main tap targets stay at or above 44 CSS px. */
@media (max-width:48rem) {
  body.rch-territory-v1 .rch-filter-panel :is(
    input.rch-ui-field:not([type="checkbox"]):not([type="radio"]),
    select.rch-ui-field,
    textarea.rch-ui-field
  ),
  body.rch-office-v1 :is(.table-toolbar,.compact-toolbar) :is(
    input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    select
  ),
  body.rch-office-v1 .scope-control select,
  body.rch-field-v1 .field-native-app :is(
    input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    select,
    textarea
  ) {
    font-size:1rem !important;
  }

  body.rch-territory-v1 .rch-home-command-zone :where(.btn,.rch-ui-button) {
    width:2.75rem !important;
    min-width:2.75rem !important;
    max-width:2.75rem !important;
    height:2.75rem !important;
    min-height:2.75rem !important;
  }

  body.rch-field-v1 .field-header-actions :is(button,.field-avatar,.field-logout-btn) {
    min-width:2.75rem !important;
    min-height:2.75rem !important;
  }
}


/* UX1 residual control-size convergence */
body.rch-office-v1 .scope-control select {
  min-height:var(--rch-control-compact) !important;
  height:var(--rch-control-compact) !important;
}

body.rch-territory-v1 #clearNotificationsBtn {
  min-height:2.25rem !important;
}

body.rch-field-v1 #fieldFilterToggle {
  min-height:var(--rch-control-comfort) !important;
}

@media (max-width:72rem) {
  body.rch-office-v1 .scope-control,
  body.rch-office-v1 .scope-control select {
    min-height:var(--rch-control-comfort) !important;
    height:var(--rch-control-comfort) !important;
  }

  body.rch-office-v1 .office-topbar :is(.btn,.rch-ui-button) {
    min-height:var(--rch-control-comfort) !important;
  }

  body.rch-territory-v1 .rch-home-header :is(.btn,.rch-ui-button) {
    min-width:var(--rch-control-comfort) !important;
    min-height:var(--rch-control-comfort) !important;
  }

  body.rch-territory-v1 #mapFullscreenBtn,
  body.rch-territory-v1 #clearNotificationsBtn {
    min-height:var(--rch-control-comfort) !important;
  }
}

@media (max-width:48rem) {
  body.rch-office-v1 .office-content :is(
    input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    select,
    textarea
  ) {
    font-size:1rem !important;
  }

  body.rch-office-v1 .office-content :is(button.btn,a.btn) {
    min-height:var(--rch-control-comfort) !important;
  }

  body.rch-territory-v1 #searchInput {
    font-size:1rem !important;
  }
}


/* UX1 deep-state form convergence — Office + CORE drawers */
body.rch-office-v1 .drawer :is(
  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  select
) {
  min-height:var(--rch-control-comfort) !important;
  height:var(--rch-control-comfort) !important;
  border-radius:var(--rch-radius-control) !important;
  font-family:var(--rch-font-sans) !important;
  font-size:var(--rch-text-body) !important;
  line-height:1.25 !important;
}

body.rch-office-v1 .drawer textarea {
  min-height:6rem;
  border-radius:var(--rch-radius-control) !important;
  font-family:var(--rch-font-sans) !important;
  font-size:var(--rch-text-body) !important;
  line-height:1.45 !important;
}

body.rch-office-v1 .drawer :is(.btn,.rch-ui-button,.icon-button) {
  min-height:var(--rch-control-comfort) !important;
}

body.rch-office-v1 .drawer .icon-button {
  width:var(--rch-control-comfort) !important;
  min-width:var(--rch-control-comfort) !important;
  height:var(--rch-control-comfort) !important;
}

@media (max-width:48rem) {
  body.rch-office-v1 .drawer :is(
    input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    select,
    textarea
  ) {
    font-size:1rem !important;
  }
}


/* UX1 final specificity pass — overrides historical high-specificity !important rules */
@media (max-width:72rem) {
  body.rch-territory-v1 .rch-home-header #territoryTimerBtn,
  body.rch-territory-v1 .rch-home-header #officeNavBtn,
  body.rch-territory-v1 .rch-home-header #refreshBtn,
  body.rch-territory-v1 .rch-home-header #analyticsBtn,
  body.rch-territory-v1 .rch-home-header #qualityBtn,
  body.rch-territory-v1 .rch-home-header #exportBtn {
    width:var(--rch-control-comfort) !important;
    min-width:var(--rch-control-comfort) !important;
    max-width:var(--rch-control-comfort) !important;
    height:var(--rch-control-comfort) !important;
    min-height:var(--rch-control-comfort) !important;
  }

  body.rch-office-v1 .office-content :is(
    input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    select
  ) {
    min-height:var(--rch-control-comfort) !important;
  }

  body.rch-office-v1 .office-content :is(button.btn,a.btn) {
    min-height:var(--rch-control-comfort) !important;
  }
}

@media (max-width:48rem) {
  body.rch-territory-v1 .rch-filter-panel #searchInput.rch-ui-field {
    font-size:1rem !important;
  }

  body.rch-field-v1 #fieldFilterToggle {
    min-width:var(--rch-control-comfort) !important;
  }
}


/* ==========================================================================
   UX1 visual refinement — search, pagination and mobile calendar composition
   ========================================================================== */

/* Same search role = same 44px control geometry. */
body.rch-office-v1 .office-content input.search-input,
body.rch-field-v1 #fieldTaskSearch {
  height:var(--rch-control-comfort) !important;
  min-height:var(--rch-control-comfort) !important;
  box-sizing:border-box !important;
  border-radius:var(--rch-radius-control) !important;
}

@media (max-width:47.99rem) {
  /* Mobile operational actions stay compact and single-line. */
  body.rch-office-v1 .office-content .toolbar-actions .btn {
    min-height:var(--rch-control-comfort) !important;
    padding-inline:.55rem !important;
    font-size:var(--rch-text-small) !important;
    line-height:1.15 !important;
    white-space:nowrap !important;
  }

  /* Calendar month header must never sacrifice the title column to actions. */
  body.rch-office-v1 #view-calendar > .panel:has(#calendarMonthGrid) .panel-heading {
    display:grid !important;
    grid-template-columns:minmax(0,1fr) !important;
    gap:var(--rch-space-3) !important;
    align-items:stretch !important;
  }

  body.rch-office-v1 #view-calendar > .panel:has(#calendarMonthGrid) .panel-heading > div:first-child {
    width:100% !important;
    min-width:0 !important;
  }

  body.rch-office-v1 #view-calendar > .panel:has(#calendarMonthGrid) .panel-heading .toolbar-actions {
    width:100% !important;
    display:grid !important;
    grid-template-columns:repeat(3,minmax(0,1fr)) !important;
    gap:var(--rch-space-2) !important;
    padding:0 !important;
    border:0 !important;
  }

  body.rch-office-v1 #view-calendar > .panel:has(#calendarMonthGrid) .panel-heading .toolbar-actions .btn {
    width:100% !important;
    min-width:0 !important;
    padding-inline:.4rem !important;
  }

  /* Activities pagination: equal 44px actions, no accidental two-line labels. */
  body.rch-office-v1 #view-activities .pagination {
    display:grid !important;
    grid-template-columns:repeat(2,minmax(0,1fr)) !important;
    align-items:stretch !important;
    gap:var(--rch-space-2) !important;
  }

  body.rch-office-v1 #view-activities .pagination .btn {
    width:100% !important;
    min-width:0 !important;
    min-height:var(--rch-control-comfort) !important;
    padding:.55rem .5rem !important;
    font-size:var(--rch-text-small) !important;
    line-height:1.15 !important;
    white-space:nowrap !important;
  }
}


/* Tablet portrait Territory: four complete KPI cards per scroll page.
   Avoid the visually unfinished half-card that appeared between phone and
   desktop breakpoints. */
@media (min-width:48.01rem) and (max-width:56.25rem) {
  body.rch-territory-v1 .rch-home-kpis {
    display:flex !important;
    align-items:stretch !important;
    gap:.55rem !important;
    overflow-x:auto !important;
    scroll-snap-type:x mandatory !important;
    scroll-padding-inline:.75rem !important;
    overscroll-behavior-inline:contain !important;
    -webkit-overflow-scrolling:touch !important;
  }

  body.rch-territory-v1 .rch-home-kpis > .rch-kpi-card {
    flex:0 0 calc((100% - 1.65rem) / 4) !important;
    width:auto !important;
    min-width:0 !important;
    scroll-snap-align:start !important;
  }
}


/* ==========================================================================
   UX1 semantic control convergence — canonical 44px operational controls
   ========================================================================== */

/* Office Audit is a filter/search toolbar even though it predates table-toolbar. */
body.rch-office-v1 #view-audit .audit-toolbar :is(
  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  select
) {
  height:var(--rch-control-comfort) !important;
  min-height:var(--rch-control-comfort) !important;
  max-height:var(--rch-control-comfort) !important;
  box-sizing:border-box !important;
  border-radius:var(--rch-radius-control) !important;
  font-family:var(--rch-font-sans) !important;
  font-size:var(--rch-text-body) !important;
  line-height:1.25 !important;
}

/* Field native v1.75 historically used 52–54px / radius 15–16px.
   UX1 aligns search and single-line form controls to the RCH design system.
   Textareas keep their multiline height intentionally. */
body.rch-field-v1 .field-native-app #fieldTaskSearch,
body.rch-field-v1 .field-native-app .field-form-card input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
body.rch-field-v1 .field-native-app .field-form-card select,
body.rch-field-v1 .field-native-app .field-controls-view input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
body.rch-field-v1 .field-native-app .field-controls-view select {
  height:var(--rch-control-comfort) !important;
  min-height:var(--rch-control-comfort) !important;
  max-height:var(--rch-control-comfort) !important;
  box-sizing:border-box !important;
  border-radius:var(--rch-radius-control) !important;
  padding-inline:var(--rch-space-3) !important;
  font-family:var(--rch-font-sans) !important;
  font-size:var(--rch-text-body) !important;
  line-height:1.25 !important;
}

body.rch-field-v1 .field-native-app .field-form-card textarea,
body.rch-field-v1 .field-native-app .field-controls-view textarea {
  min-height:5.5rem !important;
  box-sizing:border-box !important;
  border-radius:var(--rch-radius-control) !important;
  padding:var(--rch-space-3) !important;
  font-family:var(--rch-font-sans) !important;
  font-size:var(--rch-text-body) !important;
  line-height:1.45 !important;
}

@media (max-width:48rem) {
  body.rch-field-v1 .field-native-app #fieldTaskSearch,
  body.rch-field-v1 .field-native-app .field-form-card :is(
    input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    select,
    textarea
  ),
  body.rch-field-v1 .field-native-app .field-controls-view :is(
    input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    select,
    textarea
  ),
  body.rch-office-v1 #view-audit .audit-toolbar :is(
    input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    select
  ) {
    font-size:1rem !important;
  }
}


/* ==========================================================================
   UX1 final proportion pass — exact compact/comfort steps
   ========================================================================== */

/* Standard Office toolbar and pagination actions use one 44px baseline. */
body.rch-office-v1 .office-content :is(
  .table-toolbar,
  .compact-toolbar,
  .audit-toolbar,
  .pagination
) .btn,
body.rch-office-v1 .office-content .panel-heading > .toolbar-actions .btn {
  height:var(--rch-control-comfort) !important;
  min-height:var(--rch-control-comfort) !important;
  max-height:var(--rch-control-comfort) !important;
  box-sizing:border-box !important;
  border-radius:var(--rch-radius-control) !important;
  line-height:1.15 !important;
}

/* Territory desktop header is deliberately compact, but uses the exact
   canonical compact step rather than historical 2.42rem approximations. */
@media (min-width:72.01rem) {
  body.rch-territory-v1 .rch-home-header :is(
    #territoryTimerBtn,
    #officeNavBtn,
    #refreshBtn,
    #analyticsBtn,
    #qualityBtn,
    #exportBtn,
    #logoutBtn
  ) {
    height:var(--rch-control-compact) !important;
    min-height:var(--rch-control-compact) !important;
    max-height:var(--rch-control-compact) !important;
    box-sizing:border-box !important;
  }

  body.rch-territory-v1 #clearNotificationsBtn {
    min-height:var(--rch-control-compact) !important;
  }
}

/* Field filter pills are actionable controls, not metadata. */
body.rch-field-v1 .field-native-app .field-filter-pill {
  min-height:var(--rch-control-comfort) !important;
  border-radius:var(--rch-radius-pill) !important;
  font-size:var(--rch-text-small) !important;
  line-height:1.15 !important;
}

@media (max-width:48rem) {
  body.rch-field-v1 .field-native-app .field-filter-pill {
    min-height:var(--rch-control-comfort) !important;
    font-size:var(--rch-text-small) !important;
  }
}


/* ==========================================================================
   v1.7.1 Territory mobile hotfix
   Brand + essential commands share one row. Legacy mobile CSS stacked the
   command zone under the brand while the geometry layer capped header height,
   clipping every top-bar command on phones.
   ========================================================================== */
@media (max-width:48rem) {
  body.rch-territory-v1 .rch-home-header {
    display:grid !important;
    grid-template-columns:minmax(0,1fr) auto !important;
    grid-template-areas:"brand commands" !important;
    grid-template-rows:minmax(2.75rem,auto) !important;
    align-items:center !important;
    gap:.45rem !important;
    width:100% !important;
    min-width:0 !important;
    max-height:none !important;
    overflow:visible !important;
  }

  body.rch-territory-v1 .rch-home-brand-zone {
    grid-area:brand !important;
    min-width:0 !important;
    width:auto !important;
    display:flex !important;
    align-items:center !important;
    gap:.45rem !important;
    overflow:hidden !important;
  }

  body.rch-territory-v1 .rch-home-brand {
    min-width:0 !important;
    width:auto !important;
    flex:1 1 auto !important;
    overflow:hidden !important;
  }

  body.rch-territory-v1 .rch-home-brand .brand-copy {
    min-width:0 !important;
    overflow:hidden !important;
  }

  body.rch-territory-v1 .rch-home-brand .brand-copy strong {
    overflow:hidden !important;
    text-overflow:ellipsis !important;
    white-space:nowrap !important;
  }

  body.rch-territory-v1 .rch-home-page-title,
  body.rch-territory-v1 .rch-home-session-zone {
    display:none !important;
  }

  body.rch-territory-v1 .rch-home-command-zone {
    grid-area:commands !important;
    width:auto !important;
    min-width:0 !important;
    display:flex !important;
    align-items:center !important;
    justify-content:flex-end !important;
    flex-wrap:nowrap !important;
    gap:.3rem !important;
    overflow:visible !important;
  }

  body.rch-territory-v1 .rch-module-nav,
  body.rch-territory-v1 .rch-home-actions {
    width:auto !important;
    min-width:0 !important;
    display:flex !important;
    align-items:center !important;
    flex-wrap:nowrap !important;
    gap:.3rem !important;
    margin:0 !important;
    padding:0 !important;
    border:0 !important;
  }

  /* Timer remains in the bottom mobile action bar. Keep the three useful
     header shortcuts visible: Office, refresh and analytics. */
  body.rch-territory-v1 #territoryTimerBtn,
  body.rch-territory-v1 #qualityBtn,
  body.rch-territory-v1 #exportBtn {
    display:none !important;
  }

  body.rch-territory-v1 #officeNavBtn:not([hidden]),
  body.rch-territory-v1 #refreshBtn:not([hidden]),
  body.rch-territory-v1 #analyticsBtn:not([hidden]) {
    display:inline-grid !important;
    place-items:center !important;
    width:2.75rem !important;
    min-width:2.75rem !important;
    max-width:2.75rem !important;
    height:2.75rem !important;
    min-height:2.75rem !important;
    padding:0 !important;
  }

  body.rch-territory-v1 :is(#officeNavBtn,#refreshBtn,#analyticsBtn) span {
    display:none !important;
  }
}

@media (max-width:22rem) {
  /* Preserve all three command icons even at 320–352px by yielding brand copy
     before sacrificing an operational destination. */
  body.rch-territory-v1 .rch-home-brand .brand-copy {
    display:none !important;
  }
}


/* RCH v1.7-STAB2-P1-C — cross-surface control geometry */
/* RCH v1.7-STAB2-P1-C — cross-surface control geometry.
   Preserve each surface's header density; converge equivalent actionable
   controls on shared compact/comfort tokens and canonical radius. */

/* Territory is the reference surface: normalize command radius without
   changing its responsive ownership or P1-B refresh behavior. */
body.rch-territory-v1 .rch-home-header :is(
  #territoryTimerBtn,
  #officeNavBtn,
  #refreshBtn,
  #analyticsBtn,
  #qualityBtn,
  #exportBtn,
  #logoutBtn
){
  box-sizing:border-box !important;
  border-radius:var(--rch-radius-control) !important;
}

/* Office desktop: topbar operational controls use the 40px compact step. */
@media (min-width:72.01rem){
  body.rch-office-v1 .office-topbar .topbar-actions :is(
    .btn,
    .rch-ui-button,
    .refresh-button
  ){
    box-sizing:border-box !important;
    height:var(--rch-control-compact) !important;
    min-height:var(--rch-control-compact) !important;
    max-height:var(--rch-control-compact) !important;
    border-radius:var(--rch-radius-control) !important;
  }

  body.rch-office-v1 .office-topbar .scope-control select{
    box-sizing:border-box !important;
    height:var(--rch-control-compact) !important;
    min-height:var(--rch-control-compact) !important;
    max-height:var(--rch-control-compact) !important;
    border-radius:var(--rch-radius-control) !important;
  }

  body.rch-office-v1 .office-topbar :is(#refreshBtn,.refresh-button){
    width:var(--rch-control-compact) !important;
    min-width:var(--rch-control-compact) !important;
    max-width:var(--rch-control-compact) !important;
    padding:0 !important;
    display:inline-grid !important;
    place-items:center !important;
  }
}

/* Office touch/tablet: 44px targets. */
@media (max-width:72rem){
  body.rch-office-v1 .office-topbar .topbar-actions :is(
    .btn,
    .rch-ui-button,
    .refresh-button
  ),
  body.rch-office-v1 .office-topbar .scope-control select{
    box-sizing:border-box !important;
    height:var(--rch-control-comfort) !important;
    min-height:var(--rch-control-comfort) !important;
    max-height:var(--rch-control-comfort) !important;
    border-radius:var(--rch-radius-control) !important;
  }

  body.rch-office-v1 .office-topbar :is(#refreshBtn,.refresh-button){
    width:var(--rch-control-comfort) !important;
    min-width:var(--rch-control-comfort) !important;
    max-width:var(--rch-control-comfort) !important;
    padding:0 !important;
    display:inline-grid !important;
    place-items:center !important;
  }
}


/* RCH v1.7-STAB2-P1-D — overlay, safe-area and transition ownership */

/* Office drawer close belongs to the shared Office layer, not Field CSS. */
body.rch-office-v1 .drawer .icon-button{
  box-sizing:border-box !important;
  width:var(--rch-control-comfort) !important;
  min-width:var(--rch-control-comfort) !important;
  max-width:var(--rch-control-comfort) !important;
  height:var(--rch-control-comfort) !important;
  min-height:var(--rch-control-comfort) !important;
  max-height:var(--rch-control-comfort) !important;
  padding:0 !important;
  border-radius:var(--rch-radius-control) !important;
}

@media (max-width:48rem){
  /* The Office entity drawer owns the viewport scroll on phone/tablet.
     Preserve the legacy 22px composition while reserving real safe areas. */
  body.rch-office-v1 .drawer-panel{
    box-sizing:border-box !important;
    height:100dvh !important;
    max-height:100dvh !important;
    padding-top:calc(22px + env(safe-area-inset-top,0px)) !important;
    padding-bottom:calc(22px + env(safe-area-inset-bottom,0px)) !important;
    overflow-y:auto !important;
    overflow-x:hidden !important;
    overscroll-behavior:contain !important;
    scrollbar-gutter:auto !important;
    -webkit-overflow-scrolling:touch !important;
    scroll-padding-top:calc(1rem + env(safe-area-inset-top,0px)) !important;
    scroll-padding-bottom:calc(1rem + env(safe-area-inset-bottom,0px)) !important;
  }

  /* Sticky actions remain flush with the physical bottom while their content
     stays above the home-indicator safe area. */
  body.rch-office-v1 .drawer-actions{
    bottom:calc(-22px - env(safe-area-inset-bottom,0px)) !important;
    margin-bottom:calc(-22px - env(safe-area-inset-bottom,0px)) !important;
    padding-bottom:calc(15px + env(safe-area-inset-bottom,0px)) !important;
  }
}

@media (prefers-reduced-motion:reduce){
  body.rch-office-v1 .drawer-backdrop,
  body.rch-office-v1 .drawer-panel,
  body.rch-office-v1 .rch-office-mobile-nav-drawer,
  body.rch-office-v1 .rch-office-mobile-nav-backdrop,
  body.rch-territory-v1 .territory-nav-drawer,
  body.rch-territory-v1 .territory-nav-backdrop{
    transition:none !important;
    animation:none !important;
  }
}
