/* RCH v1.7-STAB2-P0 — Territory stabilization hotfix
   Scope:
   1) prevent empty compact header commands;
   2) restore tablet readability of the operational-scope editor;
   3) keep bulk selection responsive and easy to surface.
*/

/* --------------------------------------------------------------------------
   Header commands — icon visibility on every compact breakpoint
   -------------------------------------------------------------------------- */
body.rch-territory-v1 .rch-home-header :is(
  #refreshBtn,
  #analyticsBtn,
  #qualityBtn,
  #exportBtn
){
  position:relative;
  isolation:isolate;
}

body.rch-territory-v1 .rch-home-header :is(
  #refreshBtn,
  #analyticsBtn,
  #qualityBtn,
  #exportBtn
) :is(i,svg,.rch-v65-icon),
body.rch-territory-v1 .rch-home-header :is(
  #refreshBtn,
  #analyticsBtn,
  #qualityBtn,
  #exportBtn
) .rch-v65-icon svg{
  display:block !important;
  visibility:visible !important;
  opacity:1 !important;
  color:currentColor !important;
  stroke:currentColor !important;
  fill:none !important;
  pointer-events:none;
}

body.rch-territory-v1 .rch-home-header :is(
  #refreshBtn,
  #analyticsBtn,
  #qualityBtn,
  #exportBtn
) :is(svg,.rch-v65-icon svg){
  width:1.08rem !important;
  height:1.08rem !important;
  min-width:1.08rem !important;
  min-height:1.08rem !important;
  margin:0 !important;
  stroke-width:2.1 !important;
}

body.rch-territory-v1 .rch-home-header :is(
  #refreshBtn,
  #analyticsBtn,
  #qualityBtn,
  #exportBtn
) .rch-v65-icon{
  display:inline-flex !important;
  align-items:center !important;
  justify-content:center !important;
  width:1.08rem !important;
  height:1.08rem !important;
  min-width:1.08rem !important;
  min-height:1.08rem !important;
}

body.rch-territory-v1 .rch-home-header :is(
  #refreshBtn,
  #analyticsBtn,
  #qualityBtn
){
  color:#17365f !important;
  background:rgba(255,255,255,.96) !important;
  border-color:rgba(188,207,229,.9) !important;
}

body.rch-territory-v1 .rch-home-header #exportBtn{
  color:#fff !important;
  background:linear-gradient(135deg,#2389ff,#147cff) !important;
  border-color:#147cff !important;
}

/* Compact-header invariant: no secondary subtitle/kicker and no command wrap.
   These two rules intentionally override older responsive layers. */
body.rch-territory-v1 .rch-home-brand .brand-copy p,
body.rch-territory-v1 .rch-home-page-title > p{
  display:none !important;
}

body.rch-territory-v1 .rch-home-command-zone{
  flex-wrap:nowrap !important;
}

/* Prefer the real Lucide icon to the historical CSS-drawn refresh glyph. */
body.rch-territory-v1 .rch-home-header #refreshBtn::before,
body.rch-territory-v1 .rch-home-header #refreshBtn::after{
  display:none !important;
}

/* Compact layouts may hide labels, but never both label and icon.
   Timer + Office retain their labels; secondary commands collapse to stable
   icon-only squares before the header can wrap onto a second row. */
@media (max-width:100rem){
  body.rch-territory-v1 .rch-home-header :is(
    #refreshBtn,
    #analyticsBtn,
    #qualityBtn,
    #exportBtn
  ){
    display:inline-grid !important;
    place-items:center !important;
    width:2.55rem !important;
    min-width:2.55rem !important;
    max-width:2.55rem !important;
    padding-inline:0 !important;
    flex:0 0 2.55rem !important;
  }

  body.rch-territory-v1 .rch-home-header :is(
    #refreshBtn,
    #analyticsBtn,
    #qualityBtn,
    #exportBtn
  ) > span:not(.rch-v65-icon){
    display:none !important;
  }

  body.rch-territory-v1 .rch-home-header :is(
    #refreshBtn,
    #analyticsBtn,
    #qualityBtn,
    #exportBtn
  ) :is(i,svg,.rch-v65-icon,.rch-v65-icon svg){
    display:block !important;
    visibility:visible !important;
    opacity:1 !important;
  }

  body.rch-territory-v1 .rch-home-header :is(
    #refreshBtn,
    #analyticsBtn,
    #qualityBtn,
    #exportBtn
  ) > i{
    width:1.08rem !important;
    height:1.08rem !important;
    min-width:1.08rem !important;
    min-height:1.08rem !important;
    margin:0 !important;
  }
}

/* --------------------------------------------------------------------------
   C.4C scope editor — tablet readability / touch safety
   -------------------------------------------------------------------------- */
.rch-scope-editor__check input[type="checkbox"],
.rch-scope-editor__toggle input[type="checkbox"]{
  box-sizing:border-box !important;
  flex:0 0 1.25rem !important;
  width:1.25rem !important;
  min-width:1.25rem !important;
  max-width:1.25rem !important;
  height:1.25rem !important;
  min-height:1.25rem !important;
  max-height:1.25rem !important;
  padding:0 !important;
}

.rch-scope-editor__check > span{
  display:block;
  min-width:0;
  overflow-wrap:anywhere;
}

@media (min-width:43.01rem) and (max-width:72rem){
  .rch-scope-editor{
    right:.75rem !important;
    left:auto !important;
    bottom:.75rem !important;
    width:min(35rem,calc(100vw - 1.5rem)) !important;
    max-width:calc(100vw - 1.5rem) !important;
    max-height:calc(100dvh - 6rem) !important;
    padding:1rem !important;
    overflow:auto !important;
    overscroll-behavior:contain;
  }

  .rch-scope-editor__header h2{
    font-size:1.1rem !important;
    line-height:1.2 !important;
  }

  .rch-scope-editor__header p,
  .rch-scope-editor__reference p,
  .rch-scope-editor__source-trace p,
  .rch-scope-editor__preview-note,
  .rch-scope-editor__footer-note,
  .rch-scope-editor__north-rule,
  .rch-scope-editor__evidence-row,
  .rch-scope-editor__history-list > .muted{
    font-size:.75rem !important;
    line-height:1.5 !important;
  }

  .rch-scope-editor__toggle strong,
  .rch-scope-editor__mixed-warning strong,
  .rch-scope-editor__geometry-session strong,
  .rch-scope-editor__history-head strong,
  .rch-scope-editor__review-head strong{
    font-size:.82rem !important;
    line-height:1.35 !important;
  }

  .rch-scope-editor__toggle small,
  .rch-scope-editor__mixed-warning small,
  .rch-scope-editor__geometry-session small,
  .rch-scope-editor__history-head span,
  .rch-scope-editor__preview-title span,
  .rch-scope-editor__evidence-head > span,
  .rch-scope-editor__history-row small{
    font-size:.72rem !important;
    line-height:1.4 !important;
  }

  .rch-scope-editor__checks{
    grid-template-columns:1fr !important;
    gap:.5rem !important;
  }

  .rch-scope-editor__check{
    align-items:flex-start !important;
    gap:.65rem !important;
    min-height:2.9rem !important;
    padding:.72rem .78rem !important;
    font-size:.78rem !important;
    line-height:1.45 !important;
  }

  .rch-scope-editor__check input[type="checkbox"]{
    margin:.08rem 0 0 !important;
  }

  .rch-scope-editor__actions,
  .rch-scope-editor__reference-actions,
  .rch-scope-editor__source-actions{
    grid-template-columns:1fr 1fr !important;
    gap:.5rem !important;
  }

  .rch-scope-editor__actions .btn,
  .rch-scope-editor__reference-actions :is(.btn,a),
  .rch-scope-editor__source-actions .btn{
    min-height:2.75rem !important;
    font-size:.76rem !important;
    line-height:1.25 !important;
  }
}

/* --------------------------------------------------------------------------
   Bulk selection — stable scroll host and bounded DOM preview
   -------------------------------------------------------------------------- */
.rch-selection-panel{
  min-width:0;
  scroll-margin-top:.5rem;
}

.rch-selection-panel__head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:.75rem;
}

.rch-selection-panel__head h2{
  margin:.1rem 0 0;
}

.rch-selection-count{
  display:inline-grid;
  place-items:center;
  flex:0 0 auto;
  min-width:2.2rem;
  min-height:2.2rem;
  padding:0 .55rem;
  border-radius:999px;
  color:#175cd3;
  background:#eff8ff;
  border:1px solid #b2ddff;
  font-size:.78rem;
  font-weight:850;
}

.rch-selection-panel__summary{
  margin:.55rem 0 0;
  color:#667085;
  font-size:.74rem;
  line-height:1.45;
}

.rch-selection-preview-limit{
  padding:.65rem .75rem;
  border:1px dashed #b2ccff;
  border-radius:.65rem;
  background:#f5f8ff;
  color:#475467;
  font-size:.72rem;
  line-height:1.4;
  text-align:center;
}

.rch-selection-panel .selection-route-actions{
  margin-top:.75rem;
}

.rch-selection-panel .selection-list{
  max-height:min(22rem,36vh);
  contain:content;
}

.rch-selection-panel .bulk-actions :is(select,textarea,button){
  min-height:2.6rem;
}

@media (max-width:72rem){
  .rch-selection-panel .selection-list{
    max-height:min(18rem,30vh);
  }

  .rch-selection-panel__summary,
  .rch-selection-preview-limit{
    font-size:.78rem;
  }

  .rch-selection-panel .bulk-actions label{
    font-size:.78rem;
  }
}
