/* Territory Distribution Map Styling */
.territory-view-switcher {
  display: inline-flex;
  align-items: center;
  background: var(--surface-hover, rgba(0,0,0,0.05));
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 3px;
  gap: 2px;
}

.territory-view-switcher a,
.territory-view-switcher button {
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--muted);
  border: none;
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.territory-view-switcher a:hover,
.territory-view-switcher button:hover {
  color: var(--text);
}

.territory-view-switcher a.active,
.territory-view-switcher button.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.territory-map-layout {
  display: grid;
  grid-template-columns: 390px 1fr;
  gap: 18px;
  margin-top: 18px;
  align-items: stretch;
  min-height: 640px;
}

@media (max-width: 1024px) {
  .territory-map-layout {
    grid-template-columns: 1fr;
  }
}

/* Sidebar */
.territory-map-sidebar {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
  max-height: calc(100vh - 170px);
  min-height: 560px;
}

.territory-sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.territory-search-wrap {
  position: relative;
  width: 100%;
}

.territory-search-wrap input {
  width: 100%;
  padding: 9px 12px 9px 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-input, var(--surface));
  color: var(--text);
  font-size: 0.88rem;
  transition: border-color 0.15s ease;
}

.territory-search-wrap input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(201, 101, 0, 0.15);
}

.territory-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
  font-size: 0.9rem;
}

.territory-sidebar-filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.territory-sidebar-filters select {
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.8rem;
}

.territory-sidebar-count {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.territory-sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
}

/* Single Card Container for Listed Businesses */
.territory-business-list-card {
  margin: 0;
  border-radius: 12px 12px 0 0;
  border: none;
  border-bottom: 1px solid var(--border);
  box-shadow: none;
  background: var(--surface);
  display: flex;
  flex-direction: column;
}

.territory-card-list-head {
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.territory-list-controls {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle, rgba(0,0,0,0.015));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.territory-business-list-items {
  max-height: 290px;
  overflow-y: auto;
}

/* Individual list row inside the single card */
.territory-list-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}

.territory-list-row:last-child {
  border-bottom: none;
}

.territory-list-row:hover {
  background: var(--hover-bg, rgba(0, 0, 0, 0.025));
}

.territory-list-row.is-selected {
  background: rgba(201, 101, 0, 0.07);
  border-left: 3px solid var(--primary);
}

.territory-list-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  background: var(--bg-subtle, #f1f5f9);
  border: 1px solid var(--border);
  margin-top: 2px;
}

.territory-list-avatar.status-active {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.3);
}

.territory-list-avatar.status-review {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.3);
}

.territory-list-avatar.status-inactive {
  background: rgba(107, 114, 128, 0.12);
  border-color: rgba(107, 114, 128, 0.3);
}

.territory-list-main {
  flex: 1;
  min-width: 0;
}

.territory-list-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}

.territory-list-sub {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 1px;
}

.territory-list-chevron {
  font-size: 1.2rem;
  color: var(--muted);
  font-weight: 300;
  align-self: center;
  padding-left: 4px;
}

.territory-list-row.is-selected .territory-list-chevron {
  color: var(--primary);
  font-weight: 700;
}

.territory-item-card {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}

.territory-item-card:hover {
  border-color: var(--primary-light, #f59e0b);
  background: var(--hover-bg, rgba(0,0,0,0.02));
  transform: translateY(-1px);
}

.territory-item-card.is-selected {
  border-color: var(--primary);
  background: rgba(201, 101, 0, 0.04);
  box-shadow: 0 0 0 1px var(--primary);
}

.territory-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.territory-card-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.territory-card-firm {
  font-weight: 700;
  font-size: 0.94rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.territory-card-customer {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.territory-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 6px;
}

.territory-card-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--surface-hover, rgba(0,0,0,0.05));
  font-weight: 600;
}

.territory-card-badge.radius-badge {
  background: rgba(59, 130, 246, 0.12);
  color: #2563eb;
}

.territory-card-badge.status-active {
  background: rgba(16, 185, 129, 0.12);
  color: #059669;
}

.territory-card-badge.status-review {
  background: rgba(245, 158, 11, 0.12);
  color: #d97706;
}

.territory-card-badge.status-inactive {
  background: rgba(107, 114, 128, 0.12);
  color: #4b5563;
}

.territory-card-progress {
  margin-top: 8px;
  background: var(--border);
  border-radius: 9999px;
  height: 5px;
  overflow: hidden;
}

.territory-card-progress-bar {
  height: 100%;
  border-radius: 9999px;
  background: var(--primary);
  transition: width 0.3s ease;
}

/* Detail Box (Selected Distributor in Sidebar) */
.territory-detail-box {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-subtle, rgba(0,0,0,0.015));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.territory-detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.territory-detail-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.territory-detail-actions .btn {
  padding: 4px 10px;
  font-size: 0.78rem;
}

/* Local Places Box */
.territory-places-box {
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.territory-places-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
}

.territory-places-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-height: 140px;
  overflow-y: auto;
}

.territory-place-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 9999px;
  background: var(--surface-hover, rgba(0,0,0,0.04));
  border: 1px solid var(--border);
  font-size: 0.76rem;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
}

.territory-place-chip:hover {
  border-color: var(--primary);
  background: rgba(201, 101, 0, 0.08);
  color: var(--primary);
}

.territory-place-chip.poi-chip {
  background: rgba(14, 165, 233, 0.08);
  border-color: rgba(14, 165, 233, 0.25);
  color: #0284c7;
}

/* Map Pane */
.territory-map-pane {
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
  min-height: 580px;
}

.territory-map-toolbar {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  z-index: 10;
}

.territory-map-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.territory-map-legend {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.78rem;
  color: var(--muted);
  flex-wrap: wrap;
}

.legend-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 4px;
}

.legend-dot.active { background: #10b981; }
.legend-dot.review { background: #f59e0b; }
.legend-dot.inactive { background: #9ca3af; }

#territory-map-canvas {
  flex: 1;
  width: 100%;
  min-height: 540px;
  background: #f8fafc;
  z-index: 1;
}

/* Custom Leaflet Markers */
.mono-map-marker {
  display: flex;
  align-items: center;
  justify-content: center;
}

.mono-map-pin {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: #0ea5e9;
  border: 2px solid #ffffff;
  box-shadow: 0 3px 8px rgba(0,0,0,0.25);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.mono-map-pin.status-active {
  background: #10b981;
}

.mono-map-pin.status-under_review {
  background: #f59e0b;
}

.mono-map-pin.status-inactive {
  background: #6b7280;
}

.mono-map-pin.is-selected {
  background: #c96500;
  transform: rotate(-45deg) scale(1.15);
  box-shadow: 0 4px 14px rgba(201, 101, 0, 0.45);
  border-color: #fff;
}

.mono-map-pin-inner {
  transform: rotate(45deg);
  font-size: 13px;
  font-weight: 800;
  color: #ffffff;
  user-select: none;
}

/* Local Place Pin */
.mono-place-pin {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #3b82f6;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 10px;
}

/* Leaflet Popup customization */
.leaflet-popup-content-wrapper {
  border-radius: 10px;
  padding: 0;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}

.leaflet-popup-content {
  margin: 0;
  line-height: 1.4;
}

.mono-popup-card {
  padding: 14px 16px;
  min-width: 240px;
  max-width: 300px;
}

.mono-popup-firm {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text, #111827);
  margin-bottom: 2px;
}

.mono-popup-customer {
  font-size: 0.84rem;
  color: var(--muted, #6b7280);
  margin-bottom: 8px;
}

.mono-popup-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: var(--surface-hover, rgba(0,0,0,0.03));
  border-radius: 8px;
  padding: 8px 10px;
  margin: 8px 0;
  font-size: 0.78rem;
}

.mono-popup-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.mono-popup-actions .btn {
  flex: 1;
  text-align: center;
  padding: 6px 8px;
  font-size: 0.78rem;
}

