/* ===== RESET & BASE ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --blue-900:    #0a1f3d;
  --blue-800:    #1a3a8a;
  --blue-600:    #2563eb;
  --orange-500:  #f97316;
  --orange-600:  #ea580c;
  --white:       #ffffff;
  --gray-50:     #f8fafc;
  --gray-100:    #f1f5f9;
  --gray-200:    #e2e8f0;
  --gray-400:    #94a3b8;
  --gray-600:    #475569;
  --gray-800:    #1e293b;
  --green-100:   #d1fae5;
  --green-800:   #065f46;
  --red-100:     #fee2e2;
  --red-700:     #b91c1c;
  --page-gradient: linear-gradient(135deg, #0a1f3d 0%, #1a3a8a 60%, #1e4d9b 100%);
  --radius-sm:   6px;
  --radius:      10px;
  --radius-lg:   16px;
  --shadow-sm:   0 1px 3px rgba(0,0,0,0.12);
  --shadow-md:   0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg:   0 10px 30px rgba(0,0,0,0.15);
  --shadow-xl:   0 20px 40px rgba(0,0,0,0.2);
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
}

/* ===== PAGES ACCUEIL & CONNEXION (fond plein écran) ===== */

/* Page d'accueil : image de fond + voile bleu pour lisibilité */
body.page-access {
  min-height: 100vh;
  background-color: var(--blue-900);                        /* fallback si image absente */
  background-image:
    linear-gradient(rgba(10, 31, 61, 0.55), rgba(26, 58, 138, 0.50)),
    url('/images/bg-accueil.jpg');
  background-size:     cover;
  background-position: center;
  background-repeat:   no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* Pages de connexion : dégradé bleu classique */
body.page-login {
  min-height: 100vh;
  background: var(--page-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.access-card,
.login-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: 42px 40px;
  width: 100%;
  max-width: 420px;
}

/* ===== BRAND HEADER (logo + titre) ===== */
.brand-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.brand-logo {
  height: 60px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}

.brand-text h1,
.brand-title {
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--blue-800);
  line-height: 1.1;
}

.brand-text p,
.brand-subtitle {
  font-size: 0.75rem;
  color: var(--gray-400);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.brand-divider {
  height: 1px;
  background: var(--gray-200);
  margin-bottom: 28px;
}

/* ===== BOUTONS D'ACCÈS (index.html) ===== */
.access-buttons {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.access-btn {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 16px 20px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
}

.access-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  filter: brightness(1.07);
}

.access-btn:active { transform: translateY(0); }

.access-btn .btn-icon {
  font-size: 1.6rem;
  line-height: 1;
  flex-shrink: 0;
}

.access-btn .btn-label {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.access-btn .btn-label strong {
  font-size: 1rem;
  font-weight: 700;
}

.access-btn .btn-label small {
  font-size: 0.78rem;
  opacity: 0.85;
}

.visitor-btn {
  background: linear-gradient(135deg, var(--orange-500), var(--orange-600));
  color: var(--white);
}

.admin-btn {
  background: linear-gradient(135deg, var(--blue-600), var(--blue-800));
  color: var(--white);
}

/* ===== PAGES DE CONNEXION ===== */

/* Compatibilité : anciens noms de classes */
.login-container {
  min-height: 100vh;
  background: var(--page-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-box {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: 42px 40px;
  width: 100%;
  max-width: 420px;
}

/* Titres dans les cards de connexion */
.login-card h1,
.login-box h2 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--blue-800);
  text-align: center;
  margin-bottom: 6px;
}

.login-subtitle {
  text-align: center;
  color: var(--gray-400);
  font-size: 0.78rem;
  margin-bottom: 26px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Messages d'erreur / succès */
.login-error,
.error-msg {
  background: var(--red-100);
  color: var(--red-700);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.85rem;
  border-left: 3px solid var(--red-700);
}

.error-msg { display: none; }

/* Labels et inputs dans les pages de connexion */
.login-label {
  display: block;
  font-weight: 600;
  font-size: 0.84rem;
  color: var(--gray-600);
  margin-bottom: 6px;
  margin-top: 18px;
}

.login-input,
.login-box .form-group input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--gray-800);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.login-input:focus,
.login-box .form-group input:focus {
  border-color: var(--blue-600);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* Boutons de soumission dans les pages de connexion */
.login-button {
  display: block;
  width: 100%;
  padding: 13px;
  margin-top: 22px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  color: var(--white);
  transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
  letter-spacing: 0.02em;
}

.login-button-visitor {
  background: linear-gradient(135deg, var(--orange-500), var(--orange-600));
}

.login-button-admin {
  background: linear-gradient(135deg, var(--blue-600), var(--blue-800));
}

.login-button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  filter: brightness(1.06);
}

.login-button:active { transform: translateY(0); }
.login-button:disabled { opacity: 0.65; cursor: not-allowed; transform: none; }

/* Liens sous le formulaire */
.login-links {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-top: 22px;
  font-size: 0.8rem;
  color: var(--gray-400);
  flex-wrap: wrap;
}

.login-links a {
  color: var(--blue-600);
  text-decoration: none;
  transition: color 0.2s;
}

.login-links a:hover {
  color: var(--orange-500);
  text-decoration: underline;
}

/* Bouton dans login-box (compatibilité admin login) */
.login-box .btn {
  display: block;
  width: 100%;
  padding: 13px;
  margin-top: 8px;
  font-size: 1rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--blue-600), var(--blue-800));
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.15s, filter 0.15s;
}

.login-box .btn:hover { filter: brightness(1.1); transform: translateY(-1px); }

.login-box .form-group label {
  font-weight: 600;
  font-size: 0.84rem;
  color: var(--gray-600);
  display: block;
  margin-bottom: 6px;
}

/* ===== PAGE CARTE ===== */
#map {
  width: 100%;
  height: 100vh;
}

.map-header {
  position: absolute;
  top: 10px;
  left: 60px;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.97);
  padding: 8px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 160px);
}

.map-header-logo {
  height: 34px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}

.map-header h1 {
  font-size: 1rem;
  color: var(--blue-800);
  font-weight: 700;
  white-space: nowrap;
}

.map-header .subtitle {
  font-size: 0.7rem;
  color: var(--gray-400);
}

/* Légende */
.legend {
  background: rgba(255, 255, 255, 0.97);
  padding: 12px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  line-height: 1.8;
  font-size: 0.85rem;
}

.legend h4 {
  margin-bottom: 6px;
  color: var(--blue-800);
  font-size: 0.9rem;
  font-weight: 700;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-color {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
  border: 2px solid rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}

/* Lien admin sur la carte */
.admin-link {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000;
}

.admin-link a {
  display: inline-block;
  background: var(--blue-800);
  color: white;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  transition: background 0.2s, transform 0.15s;
}

.admin-link a:hover {
  background: var(--orange-500);
  transform: translateY(-1px);
}

/* Modal PDF */
.pdf-modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.75);
  z-index: 2000;
  justify-content: center;
  align-items: center;
}

.pdf-modal-overlay.active { display: flex; }

.pdf-modal {
  background: white;
  width: 90%; height: 90%;
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
}

.pdf-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--blue-800);
  color: white;
}

.pdf-modal-header h3 { font-size: 1rem; }

.pdf-modal-close {
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0 6px;
  line-height: 1;
  transition: opacity 0.2s;
}

.pdf-modal-close:hover { opacity: 0.7; }

.pdf-modal iframe {
  flex: 1;
  border: none;
  width: 100%;
}

/* Popup Leaflet */
.leaflet-popup-content { min-width: 220px; }

.popup-content h3 {
  color: var(--blue-800);
  margin-bottom: 6px;
  font-size: 1rem;
}

.popup-content .popup-type {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  color: white;
  font-size: 0.75rem;
  margin-bottom: 6px;
  font-weight: 600;
}

.popup-content p {
  font-size: 0.85rem;
  color: #555;
  margin: 4px 0;
}

.popup-content .popup-coords {
  font-size: 0.75rem;
  color: var(--gray-400);
  margin-top: 4px;
}

.popup-content .btn-pdf {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 14px;
  background: var(--orange-500);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  text-decoration: none;
  font-family: inherit;
  transition: background 0.2s;
}

.popup-content .btn-pdf:hover { background: var(--orange-600); }

/* ===== PAGE ADMINISTRATION ===== */
.admin-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding: 14px 20px;
  background: linear-gradient(135deg, var(--blue-800), var(--blue-900));
  border-radius: var(--radius);
  color: white;
  box-shadow: var(--shadow-md);
}

.admin-header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.admin-header-logo {
  height: 40px;
  width: auto;
  object-fit: contain;
}

.admin-header h1 {
  color: white;
  font-size: 1.25rem;
}

.admin-header .header-actions {
  display: flex;
  gap: 10px;
}

/* Formulaire */
.form-card {
  background: white;
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}

.form-card h2 {
  color: var(--blue-800);
  margin-bottom: 16px;
  font-size: 1.1rem;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--orange-500);
  display: inline-block;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
}

.form-group.full-width { grid-column: 1 / -1; }

.form-group label {
  font-weight: 600;
  margin-bottom: 5px;
  font-size: 0.84rem;
  color: var(--gray-600);
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: 10px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--blue-600);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group textarea {
  resize: vertical;
  min-height: 70px;
}

/* Boutons */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  transition: transform 0.15s, filter 0.15s;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: linear-gradient(135deg, var(--blue-600), var(--blue-800));
  color: white;
}

.btn-primary:hover { filter: brightness(1.1); }

.btn-danger {
  background: #ef4444;
  color: white;
}

.btn-danger:hover { background: #dc2626; }

.btn-secondary {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.btn-secondary:hover { background: rgba(255, 255, 255, 0.25); }

.btn-sm {
  padding: 5px 12px;
  font-size: 0.78rem;
}

/* Tableau */
.table-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table-card h2 {
  padding: 16px 24px;
  color: var(--blue-800);
  font-size: 1.1rem;
  border-bottom: 1px solid var(--gray-100);
}

.affaires-table {
  width: 100%;
  border-collapse: collapse;
}

.affaires-table th {
  background: var(--gray-50);
  padding: 12px 16px;
  text-align: left;
  font-size: 0.78rem;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.affaires-table td {
  padding: 12px 16px;
  border-top: 1px solid var(--gray-100);
  font-size: 0.85rem;
}

.affaires-table tr:hover td { background: var(--gray-50); }

.type-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
}

.success-msg {
  background: var(--green-100);
  color: var(--green-800);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  display: none;
  font-size: 0.9rem;
  border-left: 3px solid var(--green-800);
}

.no-data {
  text-align: center;
  color: var(--gray-400);
  padding: 40px;
  font-size: 0.9rem;
}

/* ===== LÉGENDE AVEC TOGGLE ===== */
.legend-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.legend-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--gray-400);
  font-size: 0.75rem;
  padding: 2px 4px;
  line-height: 1;
  border-radius: 3px;
  transition: color 0.2s, background 0.2s;
  flex-shrink: 0;
}

.legend-toggle:hover {
  color: var(--blue-800);
  background: var(--gray-100);
}

.legend-body {
  overflow: hidden;
  transition: max-height 0.25s ease;
}

/* ===== BOUTON GÉOLOCALISATION ===== */
.geoloc-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: white;
  border: 2px solid rgba(0, 0, 0, 0.2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-600);
  box-shadow: var(--shadow-sm);
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  padding: 0;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.geoloc-btn:hover {
  background: var(--gray-50);
  border-color: var(--blue-600);
  color: var(--blue-600);
}

.geoloc-btn.tracking {
  background: var(--orange-500);
  border-color: var(--orange-600);
  color: white;
}

.geoloc-btn.tracking svg {
  animation: spin-pulse 2s linear infinite;
}

@keyframes spin-pulse {
  0%   { opacity: 1;   transform: rotate(0deg); }
  50%  { opacity: 0.7; transform: rotate(180deg); }
  100% { opacity: 1;   transform: rotate(360deg); }
}

/* Marqueur position utilisateur (pulsation) */
.user-pos-marker {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #f97316;
  border: 3px solid white;
  box-shadow: 0 0 0 2px #f97316;
  position: relative;
}

.user-pos-marker::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(249, 115, 22, 0.25);
  animation: position-pulse 1.8s ease-out infinite;
}

@keyframes position-pulse {
  0%   { width: 18px; height: 18px; opacity: 0.8; }
  100% { width: 52px; height: 52px; opacity: 0; }
}

/* Toast notification */
.geo-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: var(--gray-800);
  color: white;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  z-index: 3000;
  box-shadow: var(--shadow-lg);
  max-width: 90vw;
  text-align: center;
  animation: toast-in 0.3s ease forwards;
  pointer-events: none;
}

.geo-toast.error {
  background: #b91c1c;
}

@keyframes toast-in {
  from { transform: translateX(-50%) translateY(16px); opacity: 0; }
  to   { transform: translateX(-50%) translateY(0);    opacity: 1; }
}

/* Tableau admin scrollable sur mobile */
#tableContainer {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ===== RESPONSIVE GÉNÉRAL ===== */
@media (max-width: 600px) {
  .access-card,
  .login-card,
  .login-box {
    padding: 28px 20px;
  }

  .brand-logo { height: 46px; }

  .brand-text h1,
  .brand-title { font-size: 1.3rem; }

  .admin-header {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  .form-grid { grid-template-columns: 1fr; }
  .form-group.full-width { grid-column: 1; }

  /* Carte : header compact sur mobile */
  .map-header {
    left: 10px;
    max-width: calc(100vw - 80px);
    padding: 6px 12px;
    gap: 8px;
  }

  .map-header-logo { height: 26px; }
  .map-header h1   { font-size: 0.85rem; }
  .map-header .subtitle { display: none; }

  /* Bouton accueil compact */
  .admin-link a {
    padding: 6px 10px;
    font-size: 0.78rem;
  }

  /* Légende réduite */
  .legend {
    font-size: 0.78rem;
    padding: 8px 12px;
    line-height: 1.6;
  }

  .legend h4,
  .legend-header h4 {
    font-size: 0.8rem;
  }

  .legend-color {
    width: 12px;
    height: 12px;
  }
}
