/* Territory map experience: free stack (Leaflet + OpenStreetMap). */
.territory-map-card {
  padding: 0;
  overflow: hidden;
  border-radius: 22px;
}
.territory-map-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.territory-map-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.territory-map-title-icon {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(11, 77, 255, .10);
  color: var(--primary);
}
.territory-map-title-icon svg { width: 27px; height: 27px; fill: none; stroke: currentColor; stroke-width: 1.9; }
.territory-map-title-text { min-width: 0; }
.territory-map-title-text strong {
  display: block;
  color: var(--text-main);
  font-size: calc(20px * var(--font-scale));
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.territory-map-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
  color: var(--muted);
  font-size: calc(12px * var(--font-scale));
  font-weight: 750;
}
.territory-map-stat { display: inline-flex; align-items: center; gap: 5px; }
.territory-map-stat.success { color: #18964b; }
.territory-map-select {
  min-width: 150px;
  max-width: 220px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 38px 0 12px;
  background: var(--solid);
  color: var(--text-main);
  font-weight: 800;
}
.territory-map-wrap {
  position: relative;
  min-height: 390px;
  background: #eaf0f7;
}
#territoryMap {
  width: 100%;
  height: 390px;
  z-index: 1;
}
.territory-map-empty,
.territory-map-loading {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  text-align: center;
  color: #5f6b7c;
  background: linear-gradient(135deg, #f5f8fc, #e9f0f9);
}
.territory-map-hint {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 500;
  border-radius: 14px;
  padding: 10px 12px;
  background: rgba(18, 29, 48, .88);
  color: #fff;
  font-size: 12px;
  font-weight: 750;
  box-shadow: 0 10px 28px rgba(10, 25, 50, .18);
}
.territory-map-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
}
.territory-map-tools button { min-height: 40px; }
.territory-map-legend {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}
.territory-map-legend span { display: inline-flex; align-items: center; gap: 5px; }
.territory-map-dot { width: 9px; height: 9px; border-radius: 999px; display: inline-block; }
.territory-map-dot.pending { background: #e22d35; }
.territory-map-dot.return { background: #e39b12; }
.territory-map-dot.visited { background: #18a453; }

/* Leaflet marker rendered without image assets. */
.csa-map-marker { background: transparent !important; border: 0 !important; }
.csa-map-pin {
  width: 34px;
  height: 34px;
  border-radius: 50% 50% 50% 8px;
  transform: rotate(-45deg);
  display: grid;
  place-items: center;
  border: 3px solid #fff;
  box-shadow: 0 5px 14px rgba(18, 43, 79, .28);
  background: #64748b;
}
.csa-map-pin > span {
  transform: rotate(45deg);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  font-weight: 900;
}
.csa-map-pin.pending { background: #e02f38; }
.csa-map-pin.return { background: #e6a118; }
.csa-map-pin.visited { background: #18a453; }
.csa-map-pin.selected {
  width: 40px;
  height: 40px;
  background: var(--primary);
  box-shadow: 0 0 0 8px rgba(11, 77, 255, .18), 0 7px 18px rgba(18, 43, 79, .3);
}

.territory-address-cards {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}
.territory-address-card {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--card);
  overflow: hidden;
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.territory-address-card.selected {
  border-color: rgba(11, 77, 255, .45);
  background: linear-gradient(135deg, rgba(11, 77, 255, .10), rgba(11, 77, 255, .03));
  box-shadow: 0 10px 26px rgba(11, 77, 255, .10);
}
.territory-address-main {
  width: 100%;
  min-height: 76px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text-main);
  padding: 13px 14px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto 24px;
  gap: 12px;
  align-items: center;
  text-align: left;
}
.territory-address-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: rgba(100, 116, 139, .10);
  color: #64748b;
  font-size: 19px;
}
.territory-address-card.selected .territory-address-icon { background: var(--primary); color: #fff; }
.territory-address-copy { min-width: 0; }
.territory-address-copy strong { display: block; font-size: calc(16px * var(--font-scale)); color: var(--text-main); }
.territory-address-copy small { display: block; margin-top: 3px; color: var(--muted); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.territory-address-status {
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}
.territory-address-status.pending { color: #c8262e; background: rgba(226, 45, 53, .11); }
.territory-address-status.return { color: #a86b00; background: rgba(227, 155, 18, .14); }
.territory-address-status.visited { color: #118541; background: rgba(24, 164, 83, .12); }
.territory-address-chevron { color: var(--muted); font-size: 24px; }
.territory-address-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 14px 14px 70px;
}
.territory-address-actions a,
.territory-address-actions button {
  min-height: 40px;
  text-decoration: none;
}
.territory-editor-details {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
}
.territory-editor-details > summary {
  cursor: pointer;
  padding: 14px 16px;
  color: var(--text-main);
  font-weight: 850;
}
.territory-editor-details > .territory-editor-list { padding: 0 14px 14px; }

html[data-theme="dark"] .territory-map-wrap { background: #172033; }
html[data-theme="dark"] .territory-map-empty,
html[data-theme="dark"] .territory-map-loading { color: #cbd5e1; background: linear-gradient(135deg, #182235, #101827); }
html[data-theme="dark"] .leaflet-control-zoom a,
html[data-theme="dark"] .leaflet-control-attribution { background: #172033; color: #dbe5f5; }

@media (max-width: 760px) {
  .territory-map-card { border-radius: 18px; }
  .territory-map-head { align-items: flex-start; padding: 14px; }
  .territory-map-title-icon { width: 42px; height: 42px; flex-basis: 42px; }
  .territory-map-title-text strong { font-size: calc(18px * var(--font-scale)); }
  .territory-map-select { min-width: 124px; max-width: 44vw; height: 42px; }
  .territory-map-wrap, #territoryMap { height: 330px; min-height: 330px; }
  .territory-map-tools { padding: 10px 12px 12px; }
  .territory-map-legend { width: 100%; margin-left: 0; }
  .territory-address-main { grid-template-columns: 42px minmax(0,1fr) auto 18px; gap: 9px; padding: 12px; }
  .territory-address-icon { width: 42px; height: 42px; }
  .territory-address-actions { padding: 0 12px 12px; }
  .territory-address-actions > * { flex: 1 1 150px; }
}
@media (max-width: 430px) {
  .territory-map-head { display: grid; grid-template-columns: 1fr; }
  .territory-map-select { width: 100%; max-width: none; }
  .territory-map-wrap, #territoryMap { height: 300px; min-height: 300px; }
  .territory-map-stats { gap: 7px; }
  .territory-address-main { grid-template-columns: 38px minmax(0,1fr) 18px; }
  .territory-address-status { grid-column: 2 / 3; justify-self: start; margin-top: -4px; }
  .territory-address-chevron { grid-column: 3; grid-row: 1 / span 2; }
}

/* Field service assignment workflow */
.field-assignment-card,
.field-admin-card,
.review-queue-card { margin-bottom: 16px; }
.field-assignment-head,
.review-queue-head {
  display:flex; align-items:flex-start; justify-content:space-between; gap:14px; margin-bottom:12px;
}
.field-assignment-head h2,
.review-queue-head h2 { margin:6px 0 4px; }
.field-assignment-head select { min-width: 180px; }
.service-assignment-map-wrap {
  border:1px solid var(--border); border-radius:18px; overflow:hidden; background:#eaf0f7;
}
#serviceAssignmentMap { width:100%; height:320px; }
.field-assignment-actions { display:flex; flex-wrap:wrap; gap:8px; margin-top:12px; }
.field-assignment-actions > * { flex:1 1 170px; }
.field-assignment-note { margin-top:10px; }
.field-report-secondary { display:flex; }
.field-report-secondary > * { flex:1; }
.review-summary { display:flex; justify-content:space-between; gap:12px; padding:12px 14px; border:1px solid var(--border); border-radius:14px; background:var(--surface-soft, rgba(11,77,255,.04)); }
.review-counts { display:flex; gap:8px; flex-wrap:wrap; }
.review-counts span { padding:7px 10px; border-radius:999px; background:rgba(11,77,255,.08); color:var(--primary); font-weight:800; font-size:12px; }
.review-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(260px,1fr)); gap:12px; }
.review-card { border:1px solid var(--border); border-radius:16px; padding:14px; background:var(--card); }
.review-card h3 { margin:6px 0; }
.review-kind { display:inline-flex; padding:5px 8px; border-radius:999px; background:rgba(11,77,255,.08); color:var(--primary); font-size:12px; font-weight:850; }
.duplicate-warning { display:grid; gap:4px; margin:10px 0; padding:10px; border-radius:12px; background:rgba(227,155,18,.12); color:#8a5d00; }
.duplicate-preview { padding:10px; border-radius:12px; background:rgba(227,155,18,.12); }
.field-assignment-admin-list { display:grid; gap:8px; margin-top:12px; }
.review-row { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:11px 12px; border:1px solid var(--border); border-radius:14px; }
.review-row div { min-width:0; }
.review-row strong, .review-row small { display:block; }
.review-row small { color:var(--muted); margin-top:2px; }
.audit-history { margin-top:14px; border-top:1px solid var(--border); padding-top:12px; }
.audit-history summary { cursor:pointer; font-weight:850; color:var(--text-main); }
.audit-list { display:grid; gap:8px; margin-top:10px; }
.audit-list article { display:grid; gap:3px; padding:10px 12px; border:1px solid var(--border); border-radius:12px; background:var(--card); }
.audit-list span, .audit-list small { color:var(--muted); font-size:12px; overflow-wrap:anywhere; }
html[data-theme="dark"] .service-assignment-map-wrap { background:#172033; }

@media (max-width:760px) {
  #serviceAssignmentMap { height:280px; }
  .field-assignment-head,.review-queue-head { flex-direction:column; }
  .field-assignment-head select { width:100%; min-width:0; }
  .review-grid { grid-template-columns:1fr; }
}
