/* css/map.css — Geospatial Customer Map Integration */

#page-map {
  margin: 0;
  padding: 0;
  width: 100%;
  height: calc(100vh - 64px);
  min-height: 600px;
  position: relative;
  overflow: hidden;
}

.map-layout-container {
  display: flex;
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  background: var(--bg-primary);
}

/* ============================================================
   Directory Sidebar
   ============================================================ */
.map-sidebar {
  width: 360px;
  min-width: 320px;
  height: 100%;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 500;
  transition: transform 0.3s ease, margin-left 0.3s ease;
  position: relative;
}

.map-sidebar.collapsed {
  margin-left: -360px;
}

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

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

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

.map-search-input {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 8px 12px 8px 32px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

.map-search-input:focus {
  border-color: var(--accent);
}

.map-filter-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.map-route-select {
  flex: 1;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  outline: none;
}

.map-route-select:focus {
  border-color: var(--accent);
}

/* GPS Accuracy Sub-district Toggle */
.map-accuracy-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  font-size: 12px;
  transition: all 0.2s ease;
}

.map-accuracy-toggle-row:hover {
  border-color: var(--accent);
}

.map-toggle-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.map-toggle-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px dashed #f59e0b;
  background: transparent;
  transition: all 0.2s ease;
}

.map-accuracy-toggle-row input[type="checkbox"]:checked ~ .map-toggle-left .map-toggle-indicator {
  background: #f59e0b;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.5);
}

.map-accuracy-toggle-row input[type="checkbox"] {
  display: none;
}

.map-stat-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11.5px;
  color: var(--text-secondary);
  padding: 0 2px;
}

.map-stat-bar strong {
  color: var(--text-primary);
  font-family: var(--mono);
}

/* Customer List Directory */
.map-customer-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.map-shop-card {
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.map-shop-card:hover {
  border-color: var(--accent);
  background: var(--bg-card-hover);
  transform: translateY(-1px);
}

.map-shop-card.active {
  border-color: var(--accent);
  background: var(--bg-card-hover);
  box-shadow: 0 0 0 1px var(--accent);
}

.map-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.map-card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.map-card-id {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  background: var(--badge-bg);
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
}

.map-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--text-secondary);
}

.map-route-badge {
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 12px;
  border: 1px solid transparent;
  text-transform: capitalize;
}

.gps-badge-approx {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border: 1px dashed #f59e0b;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
}

/* ============================================================
   Map Canvas & Controls
   ============================================================ */
.map-canvas-wrap {
  flex: 1;
  height: 100%;
  position: relative;
  background: var(--bg-primary);
}

#leaflet-map {
  width: 100%;
  height: 100%;
  z-index: 10;
}

.map-floating-toggle {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 500;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: 0 4px 12px var(--shadow-base);
  transition: all 0.2s;
}

.map-floating-toggle:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}

/* ============================================================
   Slide-in Detail Drawer
   ============================================================ */
.map-drawer {
  position: absolute;
  top: 0;
  right: 0;
  width: 390px;
  max-width: 90vw;
  height: 100%;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  box-shadow: -6px 0 24px var(--shadow-base);
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

.map-drawer.open {
  transform: translateX(0);
}

.map-drawer-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  background: var(--bg-card);
}

.map-drawer-close-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: all 0.15s;
}

.map-drawer-close-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}

.map-drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.map-drawer-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.map-drawer-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.map-drawer-val {
  font-size: 13.5px;
  color: var(--text-primary);
  line-height: 1.4;
}

.map-drawer-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.map-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
}

.map-action-btn.primary {
  background: var(--accent);
  color: var(--accent-text);
}

.map-action-btn.primary:hover {
  filter: brightness(1.08);
}

.map-action-btn.secondary {
  background: var(--bg-input);
  color: var(--text-primary);
  border-color: var(--border);
}

.map-action-btn.secondary:hover {
  border-color: var(--accent);
  background: var(--bg-card-hover);
}

.map-action-btn.accent-outline {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}

.map-action-btn.accent-outline:hover {
  background: rgba(232, 168, 32, 0.1);
}

/* ============================================================
   Cluster & Tooltip Leaflet Styling
   ============================================================ */
.chz-cluster {
  background-color: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(8px);
  border: 2px solid var(--accent);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  color: #f8fafc;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 12px;
  transition: transform 0.2s ease, border-color 0.2s;
}

.chz-cluster:hover {
  transform: scale(1.1);
}

.leaflet-tooltip.chz-tooltip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 8px;
  box-shadow: 0 4px 16px var(--shadow-base);
  padding: 8px 12px;
  font-family: var(--font);
}

.leaflet-tooltip.chz-tooltip::before {
  border-top-color: var(--border);
}

.custom-pin {
  display: flex;
  align-items: center;
  justify-content: center;
}

.pin-pulse {
  position: relative;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pin-pulse::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: inherit;
  opacity: 0.6;
  animation: pin-wave 1.6s ease-out infinite;
}

@keyframes pin-wave {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(2.4); opacity: 0; }
}

/* Light Theme Overrides for Map Elements */
[data-theme="light"] .chz-cluster {
  background-color: rgba(255, 255, 255, 0.92);
  color: #0f172a;
  border-color: #d97706;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

@media (max-width: 768px) {
  .map-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 600;
    box-shadow: 4px 0 16px var(--shadow-base);
  }
  .map-sidebar.collapsed {
    margin-left: -280px;
  }
  .map-drawer {
    width: 100%;
    max-width: 100%;
  }
}
