/* Ported to the React build from css/territories.css — tokens reconciled to the
   Pursuit DS 2026 canonical sheet (legacy --border/--radius/--secondary names
   replaced; see react/css/bridge.css for remaining aliases). */

/* ========================================================================
   TERRITORIES — Company → Territories admin page.
   Reuses the full-width agent/templates shell (data-mode="templates"),
   .agent-work / .agent-cols / .agent-cfg-stack and the .floating-widget
   card chrome. Only the bits unique to this page live here.
   ======================================================================== */

/* Intro line under the page title. */
.terr-intro {
  font: 400 14px/1.55 var(--font-body);
  color: var(--muted-foreground);
  max-width: 640px;
  margin: 0 0 4px;
}
/* Salesforce-connect prompt line (manual mode only). */
.terr-intro-sf {
  margin: 6px 0 0;
  color: var(--ps-primary-700);
}
/* "Integrate Salesforce" header CTA — pinned top-right of the page head. */
.terr-sf-connect { flex: 0 0 auto; margin-top: 2px; }
.terr-sf-connect .icon-frame i,
.terr-sf-connect .icon-frame svg { color: var(--ps-primary-500); }

/* List grid — mirrors the Agents index grid, sized to fill + scroll
   within the .agent-work flex column. */
.terr-grid {
  flex: 1; min-height: 0;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
}

/* Card layout — keeps the agent-card chrome but custom content:
   title + top-right overlap badge, then the configured filter chips. */
.terr-card { gap: 14px; }
.terr-card-top {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px;
}
.terr-card-title {
  font: 600 16px/1.25 var(--font-body);
  letter-spacing: -0.01em;
  color: var(--foreground);
  min-width: 0; flex: 0 1 auto;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.terr-card-chips { display: flex; }
.terr-card-chips .qs-chips { gap: 8px; }

/* Overlap badge — pinned top-right, matches the solid-pill badge
   treatment used elsewhere (.tpl-pub-pill), amber/caution variant. */
.terr-overlap-badge {
  flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 5px;
  font: 600 11px/1.1 var(--font-body);
  background: #9e7a0d; color: #fff;
  padding: 5px 9px; border-radius: 4px;
  white-space: nowrap;
}
.terr-overlap-badge i, .terr-overlap-badge svg { width: 12px; height: 12px; }

/* ---- Editor modal ------------------------------------------------------ */
/* Wider than the default 440px modal — the filter panel needs room. */
.terr-modal { width: 580px; max-width: calc(100vw - 32px); max-height: 88vh; display: flex; flex-direction: column; }
.terr-modal-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.terr-help {
  font: 400 13px/1.5 var(--font-body);
  color: var(--muted-foreground);
  margin-top: -2px;
}
/* Filter panel slot inside the modal — the "Filters" label sits above it. */
.terr-panel-slot { margin-top: 2px; }
/* The value-editor popover must float above the modal scrim (z-index 200). */
.editor-popover { z-index: 240; }

/* ---- Live overlap / match feedback ------------------------------------- */
.terr-overlap { display: flex; flex-direction: column; gap: 10px; }
.terr-match-line {
  display: inline-flex; align-items: center; gap: 7px;
  font: 500 13px/1.3 var(--font-body); color: var(--foreground);
}
.terr-match-line i { width: 15px; height: 15px; color: var(--ps-neutral-400); }
.terr-match-line strong { color: var(--primary); }

.terr-flag {
  display: flex; align-items: flex-start; gap: 10px;
  border-radius: 6px;
  padding: 12px 14px;
  font: 400 13px/1.5 var(--font-body);
}
.terr-flag i { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.terr-flag strong { font-weight: 600; }
.terr-flag.warn {
  background: var(--ps-tertiary-50);
  border: 1px solid #f0eab0;
  color: #58521c;
}
.terr-flag.warn i { color: var(--ps-tertiary-700); }
.terr-flag.ok {
  background: #ebf4ee;
  border: 1px solid #aec9b9;
  color: #284e37;
}
.terr-flag.ok i { color: #36684a; }
.terr-flag.muted {
  background: var(--muted);
  border: 1px solid var(--hairline);
  color: var(--muted-foreground);
}
.terr-flag.muted i { color: var(--ps-neutral-400); }

/* The overlap list inside the warning flag. */
.terr-flag-list { margin: 6px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 3px; }
.terr-flag-list li { display: flex; align-items: center; gap: 6px; }
.terr-flag-list .tfl-name { font-weight: 600; }
.terr-flag-list .tfl-count { font-family: var(--font-mono); font-size: 12px; opacity: 0.85; }

/* "Synced from Salesforce" note under the page title (SF tweak on). */
.terr-sync-note {
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: 10px;
  padding: 8px 12px; border-radius: 6px;
  background: var(--ps-primary-60);
  border: 1px solid var(--ps-primary-100);
  color: var(--ps-primary-700);
  font: 400 13px/1.4 var(--font-body);
  max-width: 640px;
}
.terr-sync-note i { flex-shrink: 0; }
.terr-sync-note strong { font-weight: 600; }

/* Empty-state hint (no Salesforce, nothing built yet). */
.terr-empty-hint {
  font: 400 13.5px/1.5 var(--font-body);
  color: var(--muted-foreground);
  margin: 0 0 2px;
}

/* ========================================================================
   USER ASSIGNMENTS — table of users mapped to one+ territories, beneath
   the territory grid. The whole Territories page scrolls as a unit so the
   grid + this card stack naturally.
   ======================================================================== */
.agent-work.terr-page { overflow-y: auto; }
.terr-page .terr-grid { flex: 0 0 auto; min-height: 0; overflow: visible; }

/* Assignment card overrides the default full-height, clipping widget so it
   sizes to content and lets the edit popover overflow its rounded corners. */
.uat-card { flex: 0 0 auto; height: auto; overflow: visible; }
.uat-card .fw-toolbar-title { white-space: nowrap; }
.uat-wrap { padding: 2px 18px 16px; }
.uat-intro {
  font: 400 13px/1.5 var(--font-body);
  color: var(--muted-foreground);
  margin: 0 0 12px; max-width: 660px;
}
.uat-sync-tag {
  display: inline-flex; align-items: center; gap: 5px;
  font: 500 11px/1 var(--font-body);
  color: var(--ps-primary-700);
  background: var(--ps-primary-60);
  border: 1px solid var(--ps-primary-100);
  padding: 4px 8px; border-radius: 999px;
}
.uat-sync-tag i, .uat-sync-tag svg { width: 12px; height: 12px; }

.uat { width: 100%; border-collapse: collapse; }
.uat thead th {
  text-align: left;
  font: 600 10px/1 var(--font-mono); letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--muted-foreground);
  padding: 0 14px 10px;
  border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
}
.uat tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--hairline);
  vertical-align: middle;
}
.uat tbody tr:last-child td { border-bottom: 0; }
.uat tbody tr:hover td { background: var(--ps-neutral-100); }
.uat-c-user, .uat-c-role { width: 1%; white-space: nowrap; }
.uat-c-terr { width: auto; }

.uat-user { display: flex; align-items: center; gap: 11px; }
.uat-av {
  width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font: 600 12px/1 var(--font-body); color: #fff; letter-spacing: 0.02em;
}
.uat-user-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.uat-name { font: 600 13.5px/1.25 var(--font-body); color: var(--foreground); }
.uat-email { font: 400 12px/1.2 var(--font-mono); color: var(--muted-foreground); }
.uat-role { font: 400 13px/1.3 var(--font-body); color: var(--muted-foreground); }

.uat-terr-inner { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.uat-chips { display: flex; flex-wrap: wrap; gap: 6px; flex: 1 1 auto; min-width: 0; }
.uat-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font: 500 12px/1 var(--font-body);
  background: var(--ps-primary-60); color: var(--ps-primary-700);
  border: 1px solid var(--ps-primary-100);
  padding: 5px 9px 5px 7px; border-radius: 6px;
  white-space: nowrap;
}
.uat-chip i, .uat-chip svg { width: 12px; height: 12px; color: var(--ps-primary-500); }
/* Self-defined territory — neutral tone + dashed border to read as
   "the user set this themselves", distinct from admin-assigned chips. */
.uat-chip-manual {
  background: var(--ps-neutral-100); color: var(--ps-neutral-600);
  border: 1px dashed var(--ps-neutral-300);
}
.uat-chip-manual i, .uat-chip-manual svg { color: var(--ps-neutral-500); }
.uat-none { font: 400 12.5px/1 var(--font-body); color: var(--ps-neutral-300); font-style: italic; }

/* Edit affordance + inline multi-select popover (manual mode only). */
.uat-edit { position: relative; flex-shrink: 0; }
.uat-edit-btn {
  display: inline-flex; align-items: center; gap: 5px;
  font: 500 12.5px/1 var(--font-body); color: var(--primary);
  background: transparent; border: 1px solid var(--ps-primary-100);
  padding: 6px 11px; border-radius: 7px; cursor: pointer;
  transition: background 0.14s, border-color 0.14s;
}
.uat-edit-btn:hover { background: var(--ps-primary-60); border-color: var(--ps-primary-500); }
.uat-edit-btn i, .uat-edit-btn svg { width: 13px; height: 13px; }
.uat-edit.open .uat-edit-btn { background: var(--ps-primary-60); border-color: var(--ps-primary-500); }

.uat-pop {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 60;
  width: 256px; max-height: 300px; overflow-y: auto;
  background: var(--card); border: 1px solid var(--hairline);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(15,19,51,0.16), 0 2px 6px rgba(15,19,51,0.06);
  animation: uat-pop-in 130ms cubic-bezier(0.2,0.8,0.2,1);
}
@keyframes uat-pop-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.uat-pop-head {
  font: 600 10px/1 var(--font-mono); letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--muted-foreground); padding: 11px 13px 9px;
  border-bottom: 1px solid var(--hairline);
}
.uat-pop-list { padding: 5px; display: flex; flex-direction: column; gap: 1px; }
.uat-pop-row {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 9px; border-radius: 7px; cursor: pointer;
}
.uat-pop-row:hover { background: var(--muted); }
.uat-pop-row.on { background: var(--ps-primary-60); }
.uat-pop-row input { width: 15px; height: 15px; accent-color: var(--ps-primary-500); flex-shrink: 0; cursor: pointer; }
.uat-pop-name { flex: 1 1 auto; font: 500 13px/1.2 var(--font-body); color: var(--foreground); min-width: 0; }
.uat-pop-count { font: 500 11px/1 var(--font-mono); color: var(--muted-foreground); flex-shrink: 0; }
.uat-pop-empty { padding: 14px 13px; font: 400 12.5px/1.45 var(--font-body); color: var(--muted-foreground); }

/* ========================================================================
   TWEAKS PANEL — floating in-page panel (shown via the toolbar toggle).
   ======================================================================== */
.tweaks-panel {
  position: fixed; right: 20px; bottom: 20px;
  width: 320px; max-width: calc(100vw - 32px);
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(20,20,23,0.20), 0 2px 6px rgba(20,20,23,0.08);
  z-index: 1400;
  overflow: hidden;
  font-family: var(--font-body);
  animation: tweaks-in 160ms cubic-bezier(0.2,0.8,0.2,1);
}
.tweaks-panel[hidden] { display: none; }
@keyframes tweaks-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.tweaks-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--hairline);
}
.tweaks-title {
  display: inline-flex; align-items: center; gap: 8px;
  font: 600 14px/1 var(--font-body); color: var(--foreground);
}
.tweaks-title i { color: var(--muted-foreground); }
.tweaks-close {
  width: 26px; height: 26px; border: 0; background: transparent;
  border-radius: 6px; cursor: pointer;
  font-size: 20px; line-height: 1; color: var(--muted-foreground);
  display: inline-flex; align-items: center; justify-content: center;
}
.tweaks-close:hover { background: var(--muted); color: var(--foreground); }
.tweaks-body { padding: 14px; }
.tweaks-section-title {
  font: 600 10px/1 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted-foreground); margin-bottom: 10px;
}
.tweaks-row {
  display: flex; align-items: flex-start; gap: 12px;
  cursor: pointer;
}
.tweaks-row-text { display: flex; flex-direction: column; gap: 3px; flex: 1 1 auto; min-width: 0; }
.tweaks-row-label { font: 500 13.5px/1.3 var(--font-body); color: var(--foreground); }
.tweaks-row-sub { font: 400 12px/1.45 var(--font-body); color: var(--muted-foreground); }
/* iOS-style switch */
.tweaks-switch { position: relative; flex-shrink: 0; width: 40px; height: 24px; margin-top: 1px; }
.tweaks-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.tweaks-knob {
  position: absolute; inset: 0;
  background: var(--ps-neutral-200); border-radius: 999px;
  transition: background 0.16s;
}
.tweaks-knob::before {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,0.25);
  transition: transform 0.16s;
}
.tweaks-switch input:checked + .tweaks-knob { background: var(--primary); }
.tweaks-switch input:checked + .tweaks-knob::before { transform: translateX(16px); }
