/* ==========================================================================
   RCH Territory v1 — pre-v0.19 consolidated
   Single page stylesheet. Replaces the legacy Territory CSS stack.
   ========================================================================== */

:root {
  --territory-header-bg: linear-gradient(110deg, #06172f, #0a2d58 58%, #071d3c);
  --territory-canvas: #edf3fa;
  --territory-panel: rgba(255, 255, 255, 0.98);
  --territory-panel-border: #dbe5f1;
  --territory-header-height: 6.1rem;
  --territory-kpi-height: 5.65rem;
  --territory-mobile-nav-height: 4.5rem;
}

html,
body.rch-territory-v1 {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body.rch-territory-v1 {
  background:
    radial-gradient(circle at 10% 0%, rgba(64, 132, 255, 0.10), transparent 30rem),
    radial-gradient(circle at 96% 3%, rgba(35, 213, 178, 0.07), transparent 25rem),
    var(--territory-canvas);
}

.rch-territory-shell {
  width: 100%;
  height: 100dvh;
  min-height: 42rem;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
}

/* Header */
.rch-home-header {
  position: relative;
  z-index: var(--rch-z-sticky);
  min-height: var(--territory-header-height);
  display: grid;
  grid-template-columns: minmax(20rem, 1fr) minmax(18rem, 33rem);
  grid-template-areas:
    "brand session"
    "brand commands";
  grid-template-rows: 2.45rem 2.45rem;
  align-items: center;
  column-gap: var(--rch-space-4);
  row-gap: var(--rch-space-1);
  padding: var(--rch-space-2) var(--rch-space-4);
  color: var(--rch-white);
  border-bottom: 1px solid rgba(140, 180, 224, 0.18);
  background:
    radial-gradient(circle at 80% -50%, rgba(35, 137, 255, 0.28), transparent 30rem),
    var(--territory-header-bg);
  box-shadow: 0 0.55rem 1.75rem rgba(4, 22, 46, 0.20);
}

.rch-home-brand-zone {
  grid-area: brand;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--rch-space-5);
}

.rch-home-brand {
  min-width: 12rem;
  display: flex;
  align-items: center;
  gap: var(--rch-space-3);
  color: var(--rch-white);
  text-decoration: none;
}

.rch-home-brand .brand-logo {
  width: 3rem;
  height: 3rem;
  flex: 0 0 auto;
  border-radius: var(--rch-radius-small);
  box-shadow: 0 0.5rem 1.4rem rgba(0, 104, 255, 0.24);
}

.rch-home-brand .brand-copy {
  min-width: 0;
  display: grid;
  gap: 0.1rem;
}

.rch-home-brand .brand-copy strong {
  font-size: 1.05rem;
  line-height: 1.05;
}

.rch-home-brand .brand-copy p {
  margin: 0;
  overflow: hidden;
  color: #abc0d9;
  font-size: var(--rch-text-micro);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rch-home-page-title {
  min-width: 0;
  padding-left: var(--rch-space-5);
  border-left: 1px solid rgba(171, 199, 230, 0.24);
}

.rch-home-page-title p {
  margin: 0 0 0.15rem;
  color: #73b3ff;
  font-size: 0.58rem;
  font-weight: 900;
  letter-spacing: 0.16em;
}

.rch-home-page-title h1 {
  margin: 0;
  color: var(--rch-white);
  font-size: clamp(1.25rem, 1.7vw, 1.65rem);
  line-height: 1.05;
  white-space: nowrap;
}

.rch-home-session-zone {
  grid-area: session;
  min-width: 0;
  justify-self: end;
}

.rch-home-auth {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--rch-space-2);
}

.rch-auth-fields {
  min-width: 0;
  display: flex;
  gap: var(--rch-space-2);
}

.rch-home-auth input {
  width: 8.8rem;
  min-height: 2.25rem;
  color: #f4f8ff;
  border-color: rgba(151, 186, 226, 0.28);
  background: rgba(2, 20, 44, 0.56);
}

.rch-home-auth input::placeholder {
  color: #8ca2bd;
}

.rch-home-auth .btn {
  min-height: 2.25rem;
}

.rch-auth-status {
  max-width: 18rem;
  min-height: 2.15rem;
  display: inline-flex;
  align-items: center;
  padding: 0 var(--rch-space-3);
  overflow: hidden;
  border: 1px solid rgba(142, 182, 225, 0.24);
  border-radius: var(--rch-radius-pill);
  color: #b8c9dc;
  background: rgba(4, 28, 59, 0.62);
  font-size: var(--rch-text-micro);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rch-auth-status.auth-ok {
  color: #c4eedb;
  border-color: rgba(51, 208, 145, 0.25);
  background: rgba(11, 99, 68, 0.22);
}

.rch-home-command-zone {
  grid-area: commands;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--rch-space-2);
}

.rch-home-status-group,
.rch-module-nav,
.rch-home-actions {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--rch-space-2);
}

.rch-home-status-group {
  display: none;
}

.rch-home-header .btn {
  min-height: 2.35rem;
  padding-inline: var(--rch-space-3);
  font-size: var(--rch-text-micro);
}

.rch-home-header .btn.secondary,
.rch-home-header .module-button {
  color: #e0ebf8;
  border-color: rgba(149, 184, 225, 0.28);
  background: rgba(5, 32, 65, 0.62);
  box-shadow: none;
}

.rch-home-header .btn.secondary:hover,
.rch-home-header .module-button:hover {
  color: var(--rch-white);
  border-color: rgba(149, 184, 225, 0.42);
  background: rgba(10, 55, 104, 0.78);
}

.rch-home-header .btn.primary,
.territory-timer-btn {
  color: var(--rch-white);
  border-color: #2a8dff;
  background: linear-gradient(135deg, #218bff, #0762e8);
  box-shadow: 0 0.5rem 1.3rem rgba(0, 101, 239, 0.23);
}

.role-scope-pill {
  color: #c4eedb;
  border-color: rgba(51, 208, 145, 0.25);
  background: rgba(11, 99, 68, 0.22);
}

/* KPI */
.rch-home-kpis {
  position: relative;
  z-index: 20;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(6, minmax(7.2rem, 1fr));
  gap: var(--rch-space-2);
  padding: var(--rch-space-2) var(--rch-space-4);
  background: rgba(238, 244, 251, 0.97);
}

.rch-kpi-card {
  position: relative;
  min-width: 0;
  min-height: var(--territory-kpi-height);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 2.45rem;
  align-items: center;
  gap: var(--rch-space-2);
  padding: var(--rch-space-3);
  overflow: hidden;
  border: 1px solid var(--rch-neutral-200);
  border-left: 0.25rem solid var(--rch-primary-600);
  border-radius: var(--rch-radius-card);
  background:
    radial-gradient(circle at 100% 0%, rgba(65, 132, 255, 0.10), transparent 3.8rem),
    var(--rch-white);
  box-shadow: var(--rch-shadow-sm);
}

.rch-kpi-card .kpi-copy {
  min-width: 0;
  display: grid;
  gap: var(--rch-space-1);
}

.rch-kpi-card .kpi-copy span {
  color: var(--rch-neutral-900);
  font-size: clamp(1.7rem, 2.2vw, 2.25rem);
  font-weight: 880;
  line-height: 0.95;
  letter-spacing: -0.04em;
}

.rch-kpi-card .kpi-copy small {
  overflow: hidden;
  color: var(--rch-neutral-500);
  font-size: 0.58rem;
  font-weight: 850;
  letter-spacing: 0.055em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.rch-kpi-card .kpi-icon {
  width: 2.35rem;
  height: 2.35rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--rch-primary-600);
  background: var(--rch-primary-100);
}

.rch-kpi-card .kpi-icon svg {
  width: 1.15rem;
  height: 1.15rem;
}

.rch-kpi-card.kpi-red {
  border-left-color: var(--rch-danger-600);
}
.rch-kpi-card.kpi-red .kpi-icon {
  color: var(--rch-danger-600);
  background: #fff0f0;
}

.rch-kpi-card.kpi-magenta {
  border-left-color: var(--rch-magenta-600);
}
.rch-kpi-card.kpi-magenta .kpi-icon {
  color: var(--rch-magenta-600);
  background: #fff0ff;
}

.rch-kpi-card.kpi-violet {
  border-left-color: var(--rch-violet-600);
}
.rch-kpi-card.kpi-violet .kpi-icon {
  color: var(--rch-violet-600);
  background: #f2efff;
}

.rch-kpi-card.kpi-green {
  border-left-color: var(--rch-success-600);
}
.rch-kpi-card.kpi-green .kpi-icon {
  color: var(--rch-success-600);
  background: #eafaf4;
}

.rch-kpi-card.kpi-purple {
  border-left-color: #d643da;
}
.rch-kpi-card.kpi-purple .kpi-icon {
  color: #d643da;
  background: #fff0ff;
}

/* Workspace */
.rch-home-workspace {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns:
    clamp(15rem, 18vw, 18rem)
    minmax(26rem, 1fr)
    clamp(17rem, 21vw, 21rem);
  gap: var(--rch-space-3);
  padding: 0 var(--rch-space-4) var(--rch-space-3);
  overflow: hidden;
}

.rch-home-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--rch-neutral-200);
  border-radius: var(--rch-radius-panel);
  background: var(--territory-panel);
  box-shadow: var(--rch-shadow-md);
}

.rch-panel-heading {
  min-height: 4.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--rch-space-3);
  padding: var(--rch-space-3) var(--rch-space-4);
  border-bottom: 1px solid #e6edf6;
  background: linear-gradient(180deg, var(--rch-white), #fbfdff);
}

.rch-panel-kicker,
.section-kicker {
  margin: 0 0 var(--rch-space-1);
  color: var(--rch-primary-600);
  font-size: 0.55rem;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.rch-panel-heading h2 {
  margin: 0;
  font-size: var(--rch-text-card);
  line-height: 1.15;
}

.rch-panel-icon {
  width: 2.5rem;
  height: 2.5rem;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: var(--rch-radius-small);
  color: var(--rch-primary-600);
  background: var(--rch-primary-100);
}

.rch-panel-icon svg {
  width: 1.2rem;
  height: 1.2rem;
}

.rch-panel-scroll {
  min-height: 0;
  padding: var(--rch-space-4);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: #aebed2 transparent;
}

/* Filters */
.rch-filter-section,
.rch-area-section {
  display: grid;
  gap: var(--rch-space-2);
  margin-bottom: var(--rch-space-4);
}

.rch-filter-grid {
  display: grid;
  gap: var(--rch-space-3);
  margin-bottom: var(--rch-space-4);
}

.rch-filter-grid label {
  display: grid;
  gap: var(--rch-space-2);
}

.rch-filter-panel label,
.rch-filter-grid label > span {
  color: var(--rch-neutral-500);
  font-size: 0.58rem;
  font-weight: 850;
  letter-spacing: 0.055em;
  text-transform: uppercase;
}

.rch-input-icon {
  position: relative;
}

.rch-input-icon svg {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: var(--rch-space-3);
  width: 1rem;
  height: 1rem;
  color: #8495ab;
  transform: translateY(-50%);
  pointer-events: none;
}

.rch-input-icon input {
  padding-left: 2.3rem;
}

.rch-filter-quick-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--rch-space-2);
}

.rch-filter-quick-actions .btn {
  min-height: 3rem;
  display: grid;
  place-items: center;
  align-content: center;
  gap: var(--rch-space-1);
  padding: var(--rch-space-2);
  white-space: normal;
  text-align: center;
}

.rch-filter-quick-actions .btn svg {
  width: 1.15rem;
  height: 1.15rem;
}

.rch-check-line {
  min-height: var(--rch-control-comfort);
  display: flex;
  align-items: center;
  gap: var(--rch-space-2);
  padding: 0 var(--rch-space-3);
  border: 1px solid #f0d7d7;
  border-radius: var(--rch-radius-control);
  background: #fff8f8;
}

.rch-check-line input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--rch-danger-600);
}

.rch-check-line span {
  color: #a33238;
  font-size: var(--rch-text-small);
  font-weight: 750;
  letter-spacing: 0;
  text-transform: none;
}

.rch-subheading h3 {
  margin: 0;
  font-size: 0.95rem;
}

/* Map */
.rch-map-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid #cbdced;
  border-radius: var(--rch-radius-panel);
  background: #dcebf5;
  box-shadow: var(--rch-shadow-md);
}

#map {
  width: 100%;
  height: 100%;
  min-height: 0;
  border-radius: inherit;
  background:
    linear-gradient(35deg, transparent 46%, rgba(92, 139, 178, 0.10) 47%, rgba(92, 139, 178, 0.10) 49%, transparent 50%) 0 0 / 3rem 3rem,
    #dcebf5;
}

.rch-map-overlay {
  position: absolute;
  z-index: var(--rch-z-map-overlay);
  display: flex;
  align-items: center;
  pointer-events: none;
  backdrop-filter: blur(0.75rem);
}

.rch-map-title-card {
  top: var(--rch-space-4);
  left: 4.5rem;
  gap: var(--rch-space-3);
  padding: var(--rch-space-2) var(--rch-space-3);
  border: 1px solid rgba(215, 229, 243, 0.90);
  border-radius: var(--rch-radius-small);
  background: rgba(255, 255, 255, 0.91);
  box-shadow: var(--rch-shadow-sm);
}

.rch-map-title-card p {
  margin: 0 0 0.1rem;
  color: var(--rch-neutral-500);
  font-size: 0.53rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rch-map-title-card strong {
  color: #192a40;
  font-size: var(--rch-text-small);
}

.rch-live-dot {
  width: 0.65rem;
  height: 0.65rem;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #1acb83;
  box-shadow: 0 0 0 0.3rem rgba(26, 203, 131, 0.13);
}

.rch-map-legend {
  left: var(--rch-space-4);
  bottom: var(--rch-space-4);
  gap: var(--rch-space-3);
  padding: var(--rch-space-2) var(--rch-space-3);
  border: 1px solid rgba(215, 229, 243, 0.88);
  border-radius: var(--rch-radius-pill);
  color: var(--rch-neutral-500);
  background: rgba(255, 255, 255, 0.91);
  box-shadow: var(--rch-shadow-sm);
  font-size: 0.58rem;
  font-weight: 760;
}

.rch-map-legend span {
  display: inline-flex;
  align-items: center;
  gap: var(--rch-space-1);
}

.legend-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
}

.legend-dot.blue { background: var(--rch-info-600); }
.legend-dot.green { background: var(--rch-success-600); }
.legend-dot.red { background: var(--rch-danger-600); }

.map-fullscreen-btn,
.map-fullscreen-close-btn {
  position: absolute;
  z-index: calc(var(--rch-z-map-overlay) + 10);
  top: var(--rch-space-4);
  right: var(--rch-space-4);
  min-height: 2.55rem;
  display: inline-flex;
  align-items: center;
  gap: var(--rch-space-2);
  padding: 0 var(--rch-space-3);
  border: 1px solid rgba(215, 229, 243, 0.92);
  border-radius: var(--rch-radius-small);
  color: #2c4059;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--rch-shadow-sm);
  font-size: var(--rch-text-micro);
  font-weight: 800;
}

.map-fullscreen-close-btn {
  display: none;
}

.map-fullscreen-active .rch-map-stage {
  position: fixed;
  z-index: var(--rch-z-critical);
  inset: var(--rch-space-3);
  border-radius: var(--rch-radius-panel);
}

.map-fullscreen-active .map-fullscreen-btn {
  display: none;
}

.map-fullscreen-active .map-fullscreen-close-btn {
  display: inline-flex;
}

.map-fullscreen-active .rch-map-title-card {
  left: var(--rch-space-4);
}

/* Context panel */
.rch-context-panel .rch-panel-scroll {
  display: grid;
  align-content: start;
  gap: var(--rch-space-3);
}

.rch-context-card {
  padding: var(--rch-space-4);
  box-shadow: none;
}

.rch-context-card h2 {
  margin: var(--rch-space-1) 0 var(--rch-space-2);
}

.rch-context-card p {
  margin: 0;
  font-size: var(--rch-text-small);
}

.detail-empty-icon {
  width: 2.7rem;
  height: 2.7rem;
  display: grid;
  place-items: center;
  margin-bottom: var(--rch-space-3);
  border: 1px solid #d8e7fa;
  border-radius: var(--rch-radius-small);
  color: var(--rch-primary-600);
  background: var(--rch-primary-100);
}

.detail-empty-icon svg {
  width: 1.3rem;
  height: 1.3rem;
}

.rch-context-card .btn.full {
  margin-top: var(--rch-space-3);
}

/* Leaflet controls */
.leaflet-control-zoom,
.leaflet-draw,
.leaflet-bar {
  border: 0;
  border-radius: var(--rch-radius-small);
  box-shadow: var(--rch-shadow-md);
}

.leaflet-bar a {
  border-bottom-color: var(--rch-neutral-200);
}

/* Mobile action bar */
.rch-mobile-action-bar {
  display: none;
}

/* Responsive: compact notebook */
@media (max-width: 90rem) and (min-width: 64.01rem) {
  .rch-home-page-title {
    display: none;
  }

  .rch-home-header {
    grid-template-columns: minmax(17rem, 1fr) minmax(18rem, 31rem);
  }

  .rch-home-actions .btn span {
    display: none;
  }

  .rch-home-actions .btn {
    width: 2.35rem;
    padding: 0;
  }

  .territory-timer-btn span,
  #officeNavBtn span {
    display: inline;
  }

  .rch-home-workspace {
    grid-template-columns: 14.5rem minmax(23rem, 1fr) 17.25rem;
    gap: var(--rch-space-2);
    padding-inline: var(--rch-space-2);
  }

  .rch-home-kpis {
    padding-inline: var(--rch-space-2);
  }
}

@media (max-width: 68.75rem) and (min-width: 56.26rem) {
  :root {
    --territory-header-height: 8rem;
  }

  .rch-home-header {
    grid-template-columns: minmax(17rem, 1fr) auto;
    grid-template-areas:
      "brand session"
      "commands commands";
    grid-template-rows: 3rem 3rem;
  }

  .rch-home-command-zone {
    width: 100%;
  }

  .rch-home-page-title {
    display: none;
  }

  .rch-home-workspace {
    grid-template-columns: 14rem minmax(22rem, 1fr) 16.5rem;
  }

  .rch-kpi-card .kpi-copy small {
    font-size: 0.53rem;
  }
}

/* Mobile and tablet */
@media (max-width: 56.25rem) {
  html,
  body.rch-territory-v1 {
    height: auto;
    min-height: 100%;
    overflow: auto;
  }

  .rch-territory-shell {
    height: auto;
    min-height: 100dvh;
    display: block;
    padding-bottom: calc(var(--territory-mobile-nav-height) + var(--rch-safe-bottom));
    overflow: visible;
  }

  .rch-home-header {
    position: sticky;
    top: 0;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "brand commands";
    grid-template-rows: 3.25rem;
    min-height: 4.2rem;
    padding: var(--rch-space-2);
  }

  .rch-home-brand {
    min-width: 0;
  }

  .rch-home-brand .brand-logo {
    width: 2.7rem;
    height: 2.7rem;
  }

  .rch-home-brand .brand-copy p,
  .rch-home-page-title,
  .rch-home-session-zone,
  .rch-home-status-group {
    display: none;
  }

  .rch-home-command-zone {
    gap: var(--rch-space-1);
  }

  .rch-module-nav .btn,
  .rch-home-actions .btn {
    width: 2.5rem;
    min-width: 2.5rem;
    min-height: 2.5rem;
    padding: 0;
  }

  .rch-module-nav .btn span,
  .rch-home-actions .btn span {
    display: none;
  }

  .rch-home-kpis {
    display: flex;
    gap: var(--rch-space-2);
    padding: var(--rch-space-2);
    overflow-x: auto;
    scrollbar-width: none;
  }

  .rch-home-kpis::-webkit-scrollbar {
    display: none;
  }

  .rch-kpi-card {
    flex: 0 0 9rem;
    min-height: 4.4rem;
  }

  .rch-home-workspace {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--rch-space-2);
    padding: 0 var(--rch-space-2) var(--rch-space-3);
    overflow: visible;
  }

  .rch-map-stage {
    grid-row: 1;
    height: min(68dvh, 42rem);
    min-height: 27rem;
  }

  .rch-home-panel {
    position: fixed;
    z-index: var(--rch-z-critical);
    inset: 0;
    display: none;
    border: 0;
    border-radius: 0;
  }

  .mobile-panel-filters-open .left-panel,
  .mobile-panel-detail-open .right-panel,
  .mobile-panel-route-open .right-panel {
    display: grid;
  }

  .rch-panel-heading {
    padding-top: calc(var(--rch-space-4) + var(--rch-safe-top));
  }

  .rch-panel-scroll {
    padding-bottom: calc(var(--territory-mobile-nav-height) + var(--rch-space-5) + var(--rch-safe-bottom));
  }

  .rch-mobile-action-bar {
    position: fixed;
    z-index: calc(var(--rch-z-critical) + 10);
    left: 0;
    right: 0;
    bottom: 0;
    min-height: calc(var(--territory-mobile-nav-height) + var(--rch-safe-bottom));
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    padding: var(--rch-space-1) var(--rch-space-1) var(--rch-safe-bottom);
    border-top: 1px solid rgba(112, 157, 205, 0.25);
    background: rgba(6, 28, 57, 0.97);
    box-shadow: 0 -0.75rem 2rem rgba(5, 27, 54, 0.26);
  }

  .rch-mobile-action-bar > * {
    min-width: 0;
    min-height: 3.6rem;
    display: grid;
    place-items: center;
    align-content: center;
    gap: var(--rch-space-1);
    padding: var(--rch-space-1);
    border: 0;
    color: #afc0d4;
    background: transparent;
    text-decoration: none;
  }

  .rch-mobile-action-bar svg {
    width: 1.35rem;
    height: 1.35rem;
  }

  .rch-mobile-action-bar span {
    font-size: 0.58rem;
    font-weight: 750;
  }

  .mobile-panel-open .rch-mobile-action-bar {
    grid-template-columns: 1fr;
  }

  .mobile-panel-open .rch-mobile-action-bar > *:not(#mobileClosePanelsBtn) {
    display: none;
  }

  .mobile-panel-open #mobileClosePanelsBtn {
    color: var(--rch-white);
    background: var(--rch-primary-700);
  }

  .rch-map-title-card {
    left: 3.8rem;
    max-width: calc(100% - 8.6rem);
  }
}

@media (max-width: 30rem) {
  .rch-home-brand .brand-copy strong {
    font-size: 0.95rem;
  }

  #officeNavBtn,
  .rch-home-actions #analyticsBtn,
  .rch-home-actions #qualityBtn {
    display: none;
  }

  .rch-map-legend {
    display: none;
  }

  .rch-map-title-card strong {
    overflow: hidden;
    display: block;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .rch-filter-quick-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-height: 45rem) and (min-width: 56.26rem) {
  :root {
    --territory-header-height: 5.35rem;
    --territory-kpi-height: 4.65rem;
  }

  .rch-home-header {
    grid-template-rows: 2.1rem 2.1rem;
    padding-block: var(--rch-space-1);
  }

  .rch-home-kpis {
    padding-block: var(--rch-space-1);
  }

  .rch-panel-heading {
    min-height: 3.7rem;
    padding-block: var(--rch-space-2);
  }

  .rch-panel-scroll {
    padding: var(--rch-space-3);
  }
}

/* ==========================================================================
   Fase 2.1 — Correzioni layout emerse dal test reale
   Queste regole fanno parte dello stesso foglio consolidato Territory.
   Non viene aggiunto un ulteriore CSS alla pagina.
   ========================================================================== */

/* La shell usa righe di dimensione reale: l'header non può essere compresso
   o trascinato fuori dal viewport da regole residue del vecchio layout. */
.rch-territory-shell {
  grid-template-rows: max-content max-content minmax(0, 1fr);
  align-content: stretch;
}

.topbar.rch-home-header,
.rch-home-header {
  position: relative;
  inset: auto;
  top: 0;
  left: 0;
  right: auto;
  bottom: auto;
  width: 100%;
  height: auto;
  margin: 0;
  overflow: visible;
  transform: none;
}

/* KPI: nel markup l'icona precede il testo. La posizione viene dichiarata
   esplicitamente per evitare che il testo finisca nella colonna stretta
   riservata all'icona. */
.rch-kpi-card {
  grid-template-columns: minmax(0, 1fr) 2.65rem;
  grid-template-areas: "copy icon";
  column-gap: var(--rch-space-3);
}

.rch-kpi-card .kpi-copy {
  grid-area: copy;
  width: 100%;
  align-self: center;
}

.rch-kpi-card .kpi-icon {
  grid-area: icon;
  justify-self: end;
  align-self: center;
}

.rch-kpi-card .kpi-copy span {
  display: block;
  width: 100%;
  overflow: visible;
  text-align: left;
  text-overflow: clip;
  white-space: nowrap;
}

.rch-kpi-card .kpi-copy small {
  display: block;
  width: 100%;
  overflow: visible;
  line-height: 1.15;
  text-overflow: clip;
  white-space: normal;
}

/* Migliore equilibrio delle schede su Full HD. */
@media (min-width: 90.01rem) {
  .rch-home-kpis {
    grid-template-columns: repeat(6, minmax(9.5rem, 1fr));
  }

  .rch-kpi-card {
    min-height: 5.5rem;
    padding-inline: var(--rch-space-4);
  }

  .rch-kpi-card .kpi-copy span {
    font-size: clamp(1.85rem, 2vw, 2.25rem);
  }

  .rch-kpi-card .kpi-copy small {
    max-width: 9rem;
    font-size: 0.6rem;
  }
}

/* Notebook: due righe ordinate, senza comprimere testi e numeri. */
@media (max-width: 75rem) and (min-width: 56.26rem) {
  .rch-home-kpis {
    grid-template-columns: repeat(3, minmax(10rem, 1fr));
  }

  .rch-kpi-card {
    min-height: 4.75rem;
  }
}

/* I pannelli laterali devono usare lo spazio senza ingrandire inutilmente
   i testi o le card interne. */
.rch-context-panel .rch-context-card {
  padding: var(--rch-space-3);
}

.rch-context-panel .notifications-list {
  gap: var(--rch-space-2);
}

.rch-context-panel .notification-item {
  padding: var(--rch-space-3);
}

.rch-context-panel .notification-item strong {
  font-size: var(--rch-text-small);
  line-height: 1.25;
}

.rch-context-panel .notification-item p,
.rch-context-panel .notification-item span,
.rch-context-panel .notification-item small {
  font-size: var(--rch-text-micro);
  line-height: 1.35;
}

/* La mappa mantiene sempre il centro del workspace. */
.rch-map-stage,
#map {
  min-width: 0;
  min-height: 0;
}

/* Mobile: mantiene il comportamento a scorrimento orizzontale dei KPI. */
@media (max-width: 56.25rem) {
  .rch-home-kpis {
    grid-template-columns: none;
  }

  .rch-kpi-card {
    grid-template-columns: minmax(0, 1fr) 2.4rem;
  }

  .rch-kpi-card .kpi-copy small {
    white-space: normal;
  }
}

/* ==========================================================================
   Fase 2.2 — Header e barra comandi Territory
   Corregge sovrapposizioni, pulsanti compressi e contenuto tagliato.
   Rimane parte del foglio consolidato rch-territory-v1.css.
   ========================================================================== */

@media (min-width: 56.26rem) {
  /* Prima riga: identità pagina e sessione.
     Seconda riga: comandi su tutta la larghezza disponibile. */
  .rch-home-header {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand session"
      "commands commands";
    grid-template-rows: minmax(2.65rem, auto) minmax(2.65rem, auto);
    min-height: 7.1rem;
    column-gap: var(--rch-space-4);
    row-gap: 0.35rem;
    padding: 0.55rem var(--rch-space-4) 0.65rem;
  }

  .rch-home-brand-zone {
    min-width: 0;
    width: 100%;
    display: flex;
    align-items: center;
    gap: var(--rch-space-4);
    overflow: hidden;
  }

  .rch-home-brand {
    flex: 0 0 auto;
    min-width: 11.5rem;
  }

  .rch-home-page-title {
    display: block;
    min-width: 0;
    flex: 1 1 auto;
  }

  .rch-home-page-title h1 {
    overflow: hidden;
    font-size: clamp(1.35rem, 1.75vw, 1.8rem);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .rch-home-session-zone {
    min-width: 0;
    max-width: min(100%, 40rem);
    align-self: center;
    justify-self: end;
  }

  .rch-home-auth {
    min-width: 0;
    max-width: 100%;
  }

  .rch-auth-status {
    max-width: min(24rem, 34vw);
  }

  .rch-home-command-zone {
    width: 100%;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--rch-space-2);
    overflow: visible;
  }

  .rch-module-nav,
  .rch-home-actions {
    min-width: 0;
    display: flex;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    align-items: center;
    gap: var(--rch-space-2);
  }

  .rch-home-command-zone .btn {
    position: relative;
    flex: 0 0 auto;
    min-width: max-content;
    max-width: none;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #territoryTimerBtn,
  #officeNavBtn {
    min-width: max-content;
  }
}

/* Su notebook, zoom 125/150% e viewport intermedi:
   Timer e Office mantengono il testo; le azioni secondarie diventano icone. */
@media (max-width: 100rem) and (min-width: 56.26rem) {
  .rch-home-actions .btn {
    width: 2.55rem;
    min-width: 2.55rem;
    padding-inline: 0;
  }

  .rch-home-actions .btn span {
    display: none;
  }

  #territoryTimerBtn span,
  #officeNavBtn span {
    display: inline;
  }
}

/* Notebook più compatti: logo e titolo restano leggibili,
   mentre RCH Office può diventare un pulsante a sola icona. */
@media (max-width: 75rem) and (min-width: 56.26rem) {
  .rch-home-brand {
    min-width: auto;
  }

  .rch-home-brand .brand-copy {
    display: none;
  }

  .rch-home-page-title {
    padding-left: 0;
    border-left: 0;
  }

  #officeNavBtn {
    width: 2.55rem;
    min-width: 2.55rem;
    padding-inline: 0;
  }

  #officeNavBtn span {
    display: none;
  }

  .rch-auth-status {
    max-width: 15rem;
  }
}

/* Schermi bassi: mantiene la barra compatta senza sovrapposizioni. */
@media (max-height: 45rem) and (min-width: 56.26rem) {
  .rch-home-header {
    min-height: 6.35rem;
    grid-template-rows: 2.3rem 2.3rem;
    padding-block: 0.4rem;
  }

  .rch-home-header .btn {
    min-height: 2.25rem;
  }
}

/* ==========================================================================
   Fase 6.1 - Stable command icons
   ========================================================================== */

body.rch-territory-v1 .territory-timer-btn,
body.rch-territory-v1 #refreshBtn {
  position: relative;
}

body.rch-territory-v1 .territory-timer-btn > i,
body.rch-territory-v1 #refreshBtn > i {
  display: none !important;
}

body.rch-territory-v1 .territory-timer-btn::before {
  content: "";
  width: 1.05rem;
  height: 1.05rem;
  border: 0.13rem solid currentColor;
  border-radius: 50%;
  box-shadow: inset 0 0 0 0.18rem transparent;
}

body.rch-territory-v1 .territory-timer-btn::after {
  content: "";
  position: absolute;
  width: 0.13rem;
  height: 0.38rem;
  top: 50%;
  left: 50%;
  border-radius: 999px;
  background: currentColor;
  transform: translate(-50%, -75%);
  box-shadow: 0.22rem 0.3rem 0 -0.02rem currentColor;
}

body.rch-territory-v1 #refreshBtn::before {
  content: "";
  width: 1.05rem;
  height: 1.05rem;
  border: 0.15rem solid currentColor;
  border-left-color: transparent;
  border-radius: 50%;
  transform: rotate(-38deg);
}

body.rch-territory-v1 #refreshBtn::after {
  content: "";
  position: absolute;
  width: 0;
  height: 0;
  margin: -0.7rem 0 0 0.7rem;
  border-top: 0.24rem solid transparent;
  border-bottom: 0.24rem solid transparent;
  border-left: 0.36rem solid currentColor;
  transform: rotate(18deg);
}

@media (max-width: 48rem) {
  body.rch-territory-v1 .territory-timer-btn,
  body.rch-territory-v1 #refreshBtn {
    display: inline-grid !important;
    place-items: center;
    min-width: 2.8rem;
    width: 2.8rem;
    min-height: 2.8rem;
    height: 2.8rem;
    padding: 0;
    overflow: visible;
    font-size: 0;
  }
}
