/* ==========================================================================
   Employee Map — Carte interactive des salaries
   ========================================================================== */

/* ---------------------------------------------------------------------------
   Map Layout : sidebar left (filters) + map right
   --------------------------------------------------------------------------- */
.emp-map {
  position: relative;
  display: flex;
  width: 100%;
  height: calc(100vh - var(--topbar-height));
  min-height: 400px;
  overflow: hidden;
}

.emp-map__canvas {
  flex: 1;
  min-width: 0;
  height: 100%;
}

/* ---------------------------------------------------------------------------
   Sidebar Filters (Desktop)
   --------------------------------------------------------------------------- */
.emp-map__sidebar {
  width: 280px;
  flex-shrink: 0;
  height: 100%;
  overflow-y: auto;
  background: var(--color-bg-primary);
  border-right: 1px solid var(--color-border);
  padding: var(--space-5) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  z-index: 2;
}

.emp-map__sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.emp-map__sidebar-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--color-text-primary);
}

.emp-map__filter-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.emp-map__filter-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-tertiary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
}

.emp-map__filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.emp-map__filter-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition-colors), border-color var(--transition-fast);
  line-height: var(--leading-normal);
}

.emp-map__filter-chip:hover {
  color: var(--color-text-primary);
  border-color: var(--color-text-tertiary);
}

.emp-map__filter-chip.is-active {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}

/* Back button */
.emp-map__back {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition-colors);
  width: 100%;
  justify-content: center;
}

.emp-map__back:hover {
  color: var(--color-text-primary);
  background: var(--color-bg-secondary);
}

/* Sidebar legend at bottom */
.emp-map__sidebar-legend {
  margin-top: auto;
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

/* ---------------------------------------------------------------------------
   Mobile FAB (filter button)
   --------------------------------------------------------------------------- */
.emp-map__fab {
  display: none;
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  z-index: 1000;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--color-text-primary);
  transition: var(--transition-colors);
}

.emp-map__fab:hover {
  background: var(--color-bg-secondary);
}

/* Mobile back button (floating) */
.emp-map__fab-back {
  display: none;
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  z-index: 1000;
  height: 36px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-full);
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  cursor: pointer;
  color: var(--color-text-primary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition: var(--transition-colors);
}

/* ---------------------------------------------------------------------------
   Bottom Sheet (Mobile filters)
   --------------------------------------------------------------------------- */
.emp-map__sheet-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1001;
  opacity: 0;
  transition: opacity var(--transition-base);
}

.emp-map__sheet-backdrop.is-visible {
  opacity: 1;
}

.emp-map__sheet {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1002;
  background: var(--color-bg-primary);
  border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
  max-height: 70vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform var(--transition-sheet);
  padding: var(--space-4) var(--space-5) var(--space-8);
}

.emp-map__sheet.is-open {
  transform: translateY(0);
}

.emp-map__sheet-handle {
  display: flex;
  justify-content: center;
  padding-bottom: var(--space-4);
}

.emp-map__sheet-handle span {
  width: 36px;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--color-border);
}

.emp-map__sheet-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--color-text-primary);
  margin-bottom: var(--space-4);
}

/* ---------------------------------------------------------------------------
   Legend (shared styles)
   --------------------------------------------------------------------------- */
.emp-map__legend-title {
  font-weight: var(--weight-semibold);
  color: var(--color-text-primary);
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
}

.emp-map__legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 2px 0;
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
}

.emp-map__legend-dot {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.emp-map__legend-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------------------------------------------------------------------------
   Custom Leaflet Markers
   --------------------------------------------------------------------------- */
.emp-map__site-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-lg);
  background: var(--color-accent);
  color: #fff;
  box-shadow: var(--shadow-md);
  border: 2px solid #fff;
  transition: transform var(--transition-fast);
}

.emp-map__site-marker:hover {
  transform: scale(1.1);
}

.emp-map__site-marker--green {
  background: #22c55e;
}

.emp-map__site-marker--orange {
  background: #f59e0b;
}

.emp-map__site-marker--red {
  background: #ef4444;
}

.emp-map__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid #9ca3af;
  background: var(--color-bg-primary);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: transform var(--transition-fast);
  cursor: pointer;
}

.emp-map__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.emp-map__avatar:hover {
  transform: scale(1.2);
  z-index: 10;
}

/* Keep dot classes for legend reference */
.emp-map__employee-dot--present {
  background: #22c55e;
}

.emp-map__employee-dot--absent {
  background: #9ca3af;
}

.emp-map__employee-dot--alert {
  background: #ef4444;
}

/* ---------------------------------------------------------------------------
   Leaflet Popup Overrides — Premium Design
   --------------------------------------------------------------------------- */
.emp-map .leaflet-popup-content-wrapper {
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15), 0 2px 8px rgba(0, 0, 0, 0.08);
  padding: 0;
  font-family: var(--font-family);
  overflow: hidden;
  border: none;
}

.emp-map .leaflet-popup-content {
  margin: 0 !important;
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  width: 100% !important;
}

.emp-map .leaflet-popup-tip-container {
  margin-top: -1px;
}

.emp-map .leaflet-popup-tip {
  box-shadow: none;
}

.emp-map .leaflet-popup-close-button {
  top: 12px;
  right: 12px;
  color: rgba(255, 255, 255, 0.8);
  font-size: 18px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(4px);
  transition: all 0.2s;
  z-index: 10;
}

.emp-map .leaflet-popup-close-button:hover {
  background: rgba(0, 0, 0, 0.3);
  color: #fff;
}

/* --- Base popup --- */
.emp-map__popup {
  min-width: 180px;
}

/* --- Popup badge (shared) --- */
.emp-map__popup-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.emp-map__popup-badge--green {
  background: linear-gradient(135deg, #dcfce7, #bbf7d0);
  color: #15803d;
}

.emp-map__popup-badge--orange {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  color: #a16207;
}

.emp-map__popup-badge--red {
  background: linear-gradient(135deg, #fee2e2, #fecaca);
  color: #b91c1c;
}

/* --- Popup CTA link --- */
.emp-map__popup-link,
.emp-map__popup-link:link,
.emp-map__popup-link:visited {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: #ffffff !important;
  text-decoration: none !important;
  cursor: pointer;
  background: #2383e2;
  border: none;
  border-radius: 10px;
  transition: all 0.2s;
  letter-spacing: 0.01em;
}

.emp-map__popup-link:hover {
  background: #1b6ec2;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(35, 131, 226, 0.35);
  color: #ffffff !important;
}

/* =====================================================
   SITE POPUP — Premium Card
   ===================================================== */
.emp-map__popup--site {
  padding: 0;
  width: 320px;
}

/* Accent banner at top */
.emp-map__popup-site-banner {
  position: relative;
  background: linear-gradient(135deg, var(--color-accent), #6366f1);
  padding: 20px 20px 16px;
  color: #fff;
}

.emp-map__popup-site-banner::after {
  content: '';
  position: absolute;
  bottom: -12px;
  left: 0;
  right: 0;
  height: 12px;
  background: var(--color-bg-primary);
  border-radius: 12px 12px 0 0;
}

.emp-map__popup-site-banner-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.emp-map__popup-site-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
}

.emp-map__popup-site-title {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 2px;
}

.emp-map__popup-site-sub {
  font-size: 12px;
  opacity: 0.8;
  font-weight: 400;
}

.emp-map__popup-site-badge {
  flex-shrink: 0;
}

/* Stats row */
.emp-map__popup-stats {
  display: flex;
  gap: 8px;
  padding: 6px 20px 12px;
}

.emp-map__popup-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 6px;
  background: var(--color-bg-secondary);
  border-radius: 10px;
  border: 1px solid var(--color-border);
}

.emp-map__popup-stat-val {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-text-primary);
  line-height: 1;
}

.emp-map__popup-stat-label {
  font-size: 9px;
  color: var(--color-text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin-top: 4px;
}

/* Section label */
.emp-map__popup-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-tertiary);
  padding: 4px 20px 6px;
}

/* Employee list */
.emp-map__popup-emplist {
  padding: 0 12px 4px;
  max-height: 220px;
  overflow-y: auto;
}

.emp-map__popup-emplist::-webkit-scrollbar {
  width: 4px;
}

.emp-map__popup-emplist::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 4px;
}

/* Employee row in site popup */
.emp-map__popup-emp {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px;
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  transition: all 0.15s;
  cursor: pointer;
}

.emp-map__popup-emp:hover {
  background: var(--color-bg-secondary);
  transform: translateX(2px);
}

.emp-map__popup-emp-avatar {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: visible;
  flex-shrink: 0;
}

.emp-map__popup-emp-avatar img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--color-bg-primary);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.emp-map__popup-emp-status {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--color-bg-primary);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05);
}

.emp-map__popup-emp-info {
  flex: 1;
  min-width: 0;
}

.emp-map__popup-emp-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.emp-map__popup-emp-role {
  font-size: 11px;
  color: var(--color-text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.emp-map__popup-emp-alert {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

.emp-map__popup-more {
  text-align: center;
  font-size: 11px;
  color: var(--color-text-tertiary);
  padding: 6px 20px 2px;
  font-weight: 500;
}

/* Site popup footer */
.emp-map__popup-site-footer {
  padding: 8px 16px 16px;
}

/* =====================================================
   EMPLOYEE POPUP — Premium Hero Card
   ===================================================== */
.emp-map__popup--emp {
  padding: 0;
  width: 260px;
  text-align: center;
  overflow: hidden;
}

/* Gradient hero banner behind photo */
.emp-map__popup-emp-banner {
  position: relative;
  height: 60px;
  background: linear-gradient(135deg, var(--color-accent), #818cf8);
}

.emp-map__popup-emp-banner::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 0;
  right: 0;
  height: 10px;
  background: var(--color-bg-primary);
  border-radius: 10px 10px 0 0;
}

.emp-map__popup-emp-hero {
  position: relative;
  width: 68px;
  height: 68px;
  margin: -34px auto 0;
  z-index: 2;
}

.emp-map__popup-emp-hero-img {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--color-bg-primary);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
}

.emp-map__popup-emp-hero .emp-map__popup-emp-status {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 3px solid var(--color-bg-primary);
}

.emp-map__popup-emp-hero-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-text-primary);
  padding: 8px 20px 0;
  line-height: 1.2;
}

.emp-map__popup-emp-hero-role {
  font-size: 12px;
  color: var(--color-text-tertiary);
  padding: 2px 20px 0;
  font-weight: 400;
}

.emp-map__popup-emp-tags {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px 0;
  flex-wrap: wrap;
}

.emp-map__popup-emp-detail {
  margin: 12px 16px 0;
  padding: 12px 0 0;
  border-top: 1px solid var(--color-border);
  text-align: left;
}

.emp-map__popup-emp-detail-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 5px 4px;
  font-size: 12px;
}

.emp-map__popup-emp-detail-row span {
  color: var(--color-text-tertiary);
  white-space: nowrap;
  font-weight: 500;
}

.emp-map__popup-emp-detail-row strong {
  color: var(--color-text-primary);
  font-weight: 600;
  text-align: right;
  word-break: break-word;
}

/* Employee popup footer */
.emp-map__popup-emp-footer {
  padding: 12px 16px 16px;
}

/* ---------------------------------------------------------------------------
   Dark Theme
   --------------------------------------------------------------------------- */
[data-theme='dark'] .emp-map__sidebar {
  background: var(--color-bg-primary);
  border-right-color: var(--color-border);
}

[data-theme='dark'] .emp-map__filter-chip {
  border-color: var(--color-border);
  color: var(--color-text-secondary);
}

[data-theme='dark'] .emp-map__filter-chip:hover {
  border-color: var(--color-text-tertiary);
  color: var(--color-text-primary);
}

[data-theme='dark'] .emp-map__filter-chip.is-active {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}

[data-theme='dark'] .emp-map__back {
  border-color: var(--color-border);
}

[data-theme='dark'] .emp-map__back:hover {
  background: rgba(255, 255, 255, 0.08);
}

[data-theme='dark'] .emp-map__fab,
[data-theme='dark'] .emp-map__fab-back {
  background: var(--color-bg-primary);
  border-color: var(--color-border);
}

[data-theme='dark'] .emp-map__sheet {
  background: var(--color-bg-primary);
}

[data-theme='dark'] .emp-map .leaflet-popup-content-wrapper {
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
}

[data-theme='dark'] .emp-map .leaflet-popup-tip {
  background: var(--color-bg-primary);
}

[data-theme='dark'] .emp-map .leaflet-popup-close-button {
  color: rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.1);
}

[data-theme='dark'] .emp-map .leaflet-popup-close-button:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

[data-theme='dark'] .emp-map__popup-badge--green {
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
}

[data-theme='dark'] .emp-map__popup-badge--orange {
  background: rgba(245, 158, 11, 0.15);
  color: #fcd34d;
}

[data-theme='dark'] .emp-map__popup-badge--red {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
}

[data-theme='dark'] .emp-map__popup-stat {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.08);
}

[data-theme='dark'] .emp-map__popup-emp:hover {
  background: rgba(255, 255, 255, 0.06);
}

[data-theme='dark'] .emp-map__popup-emp-avatar img {
  border-color: var(--color-bg-primary);
}

[data-theme='dark'] .emp-map__popup-emp-status {
  border-color: var(--color-bg-primary);
}

[data-theme='dark'] .emp-map__popup-link {
  background: var(--color-accent);
  color: #fff;
}

[data-theme='dark'] .emp-map__popup-link:hover {
  filter: brightness(1.15);
}

[data-theme='dark'] .emp-map__popup-site-banner::after,
[data-theme='dark'] .emp-map__popup-emp-banner::after {
  background: var(--color-bg-primary);
}

[data-theme='dark'] .emp-map__popup-emp-hero-img {
  border-color: var(--color-bg-primary);
}

[data-theme='dark'] .emp-map__site-marker {
  border-color: var(--color-bg-primary);
}

[data-theme='dark'] .emp-map__avatar {
  background: var(--color-bg-primary);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

/* ---------------------------------------------------------------------------
   Responsive — Tablet & Mobile
   --------------------------------------------------------------------------- */
@media (max-width: 1023px) {
  .emp-map {
    height: calc(100vh - var(--topbar-height) - var(--bottom-nav-height));
  }

  /* Hide desktop sidebar */
  .emp-map__sidebar {
    display: none;
  }

  /* Show mobile FAB + back */
  .emp-map__fab {
    display: flex;
  }

  .emp-map__fab-back {
    display: flex;
  }

  /* Show sheet elements */
  .emp-map__sheet-backdrop {
    display: block;
    pointer-events: none;
  }

  .emp-map__sheet-backdrop.is-visible {
    pointer-events: auto;
  }

  .emp-map__sheet {
    display: block;
  }
}
