/* KPI Tracker - Custom Styles */

/* ==================== LEAFLET MAP Z-INDEX FIX ==================== */
/* SOLUTION RADICALE: Empêche la carte de passer au-dessus du menu mobile */
/* Menu overlay = z-40, Menu sidebar = z-50 */
/* TOUT élément de la carte doit être < z-30 */

/* Container parent - crée un nouveau contexte de stacking isolé */
.geolocation-section,
#geolocation-map,
#geolocation-map > * {
  position: relative !important;
  z-index: 1 !important;
  isolation: isolate !important;
  contain: layout style !important;
}

/* Leaflet container - BLOQUER le z-index élevé */
#geolocation-map .leaflet-container {
  z-index: 1 !important;
  position: relative !important;
}

/* FORCER tous les panes Leaflet - OVERRIDE styles inline */
#geolocation-map .leaflet-pane,
#geolocation-map .leaflet-map-pane,
#geolocation-map .leaflet-tile-pane,
#geolocation-map .leaflet-overlay-pane,
#geolocation-map .leaflet-shadow-pane,
#geolocation-map .leaflet-marker-pane,
#geolocation-map .leaflet-tooltip-pane,
#geolocation-map .leaflet-popup-pane {
  z-index: 10 !important;
}

/* Contrôles Leaflet */
#geolocation-map .leaflet-control-container,
#geolocation-map .leaflet-top,
#geolocation-map .leaflet-bottom,
#geolocation-map .leaflet-left,
#geolocation-map .leaflet-right,
#geolocation-map .leaflet-control {
  z-index: 15 !important;
}

/* Popups et tooltips */
#geolocation-map .leaflet-popup,
#geolocation-map .leaflet-tooltip {
  z-index: 20 !important;
}

/* Marqueurs */
#geolocation-map .leaflet-marker-icon,
#geolocation-map .leaflet-marker-shadow {
  z-index: 12 !important;
}

/* FAILSAFE: Catch-all pour tout élément Leaflet */
[class*="leaflet-"] {
  z-index: auto;
}

#geolocation-map [class*="leaflet-"] {
  z-index: inherit !important;
}

/* ==================== END LEAFLET FIX ==================== */

/* Smooth transitions */
* {
  transition: all 0.2s ease-in-out;
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* Status badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.875rem;
  font-weight: 600;
}

/* KPI Card */
.kpi-card {
  border-radius: 0.5rem;
  padding: 1.5rem;
  background: white;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  transition: transform 0.2s, box-shadow 0.2s;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* Chart container */
.chart-container {
  position: relative;
  height: 300px;
  margin: 1rem 0;
}

/* Loading spinner */
.spinner {
  border: 3px solid #f3f4f6;
  border-top: 3px solid #4f46e5;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.fade-in {
  animation: fadeIn 0.3s ease-in;
}

/* Table styles */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  background-color: #f9fafb;
  padding: 0.75rem;
  text-align: left;
  font-weight: 600;
  color: #374151;
  border-bottom: 2px solid #e5e7eb;
}

.data-table td {
  padding: 0.75rem;
  border-bottom: 1px solid #e5e7eb;
}

.data-table tr:hover {
  background-color: #f9fafb;
}

/* Alert styles */
.alert {
  padding: 1rem;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
}

.alert-success {
  background-color: #d1fae5;
  color: #065f46;
  border-left: 4px solid #10b981;
}

.alert-warning {
  background-color: #fef3c7;
  color: #92400e;
  border-left: 4px solid #f59e0b;
}

.alert-error {
  background-color: #fee2e2;
  color: #991b1b;
  border-left: 4px solid #ef4444;
}

.alert-info {
  background-color: #dbeafe;
  color: #1e40af;
  border-left: 4px solid #3b82f6;
}

/* ==================== RESPONSIVE DESIGN ==================== */

/* Mobile-first responsive tables */
@media (max-width: 768px) {
  /* Tables: scroll horizontally on mobile */
  .responsive-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Reduce table padding on mobile */
  table th, table td {
    padding: 0.5rem 0.25rem !important;
    font-size: 0.75rem !important;
  }
  
  /* Hide less important columns on mobile */
  .hide-mobile {
    display: none !important;
  }
  
  /* Stack form elements vertically */
  .form-row {
    flex-direction: column !important;
  }
  
  /* Full width buttons on mobile */
  .btn-mobile-full {
    width: 100% !important;
  }
  
  /* Reduce card padding */
  .card-mobile {
    padding: 0.75rem !important;
  }
  
  /* Stack grid columns */
  .grid-mobile-stack {
    grid-template-columns: 1fr !important;
  }
  
  /* Smaller headings */
  h1, .text-3xl {
    font-size: 1.5rem !important;
  }
  
  h2, .text-2xl {
    font-size: 1.25rem !important;
  }
  
  /* Sidebar: hidden by default on mobile */
  .sidebar-mobile {
    transform: translateX(-100%);
    position: fixed;
    z-index: 50;
    transition: transform 0.3s ease;
  }
  
  .sidebar-mobile.open {
    transform: translateX(0);
  }
  
  /* Main content full width on mobile */
  .main-content-mobile {
    margin-left: 0 !important;
    width: 100% !important;
  }
  
  /* Modal responsive */
  .modal-content {
    width: 95% !important;
    max-width: 95% !important;
    margin: 1rem auto !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
  }
  
  /* Stats cards: 2 columns on mobile */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  /* Navigation tabs: horizontal scroll */
  .nav-tabs-mobile {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    padding-bottom: 0.5rem;
  }
  
  .nav-tabs-mobile::-webkit-scrollbar {
    display: none;
  }
  
  /* Badges smaller */
  .badge {
    font-size: 0.65rem !important;
    padding: 0.125rem 0.375rem !important;
  }
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
  table th, table td {
    padding: 0.5rem !important;
    font-size: 0.8rem !important;
  }
  
  .stats-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }
}

/* Touch-friendly elements */
@media (pointer: coarse) {
  /* Larger touch targets */
  button, a, input, select {
    min-height: 44px;
  }
  
  /* More spacing for touch */
  .touch-spacing {
    padding: 0.75rem !important;
  }
}

/* Print styles */
@media print {
  .no-print {
    display: none !important;
  }
  
  .print-full-width {
    width: 100% !important;
  }
}

/* Safe area for notched devices */
@supports (padding: env(safe-area-inset-bottom)) {
  .safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* Prevent text overflow */
.text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Responsive text */
.text-responsive {
  font-size: clamp(0.75rem, 2vw, 1rem);
}

/* Responsive containers */
.container-responsive {
  width: 100%;
  padding-left: 1rem;
  padding-right: 1rem;
}

@media (min-width: 640px) {
  .container-responsive {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }
}

@media (min-width: 1024px) {
  .container-responsive {
    padding-left: 2rem;
    padding-right: 2rem;
  }
}
