/* ════════════════════════════════════════════
   MAP MODAL & PAGE STYLES — responsive
════════════════════════════════════════════ */

/* ─── MAP MODAL ──────────────────────────── */
.map-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex !important;
  align-items: flex-end;
  justify-content: center;
  z-index: 1000;
  animation: mapSlideUp 0.3s ease-out;
}

@keyframes mapSlideUp {
  from { opacity: 0; transform: translateY(100%); }
  to   { opacity: 1; transform: translateY(0); }
}

.map-modal-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: -1;
}

.map-modal-content {
  width: 100%;
  height: 88vh;
  max-height: 88vh;
  background: var(--bg-dark, #0a0f1e);
  border-radius: 20px 20px 0 0;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.25);
}

.map-modal-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-dark, #0a0f1e);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  flex-shrink: 0;
  gap: 8px;
  overflow: hidden;
}

/* ─── MAP PAGE ───────────────────────────── */
#page-map {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  background: var(--bg-dark);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  flex-shrink: 0;
  gap: 6px;
  overflow: hidden;
}

.topbar-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-1);
  flex: 1;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* topbar-btn défini dans core.css — pas redéfini ici */
.map-icon {
  width: 20px; height: 20px; flex-shrink: 0;
}

/* ─── FILTER BAR ─────────────────────────── */
.filter-bar {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  overflow-x: auto; scrollbar-width: none;
  background: var(--bg-dark);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.filter-bar::-webkit-scrollbar { display: none; }

.map-filter-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-card2);
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  font-size: 13px; font-weight: 500;
  flex-shrink: 0;
}
.map-filter-btn:active { transform: scale(0.95); }
.map-filter-btn.active {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
}

/* ─── MAP CONTAINER ──────────────────────── */
#map-container {
  flex: 1;
  background: linear-gradient(135deg, #0a1424 0%, #060d1a 100%);
  position: relative;
  min-height: 300px;
}

/* ─── TECH MAP SECTION ───────────────────── */
.tech-map-section {
  min-height: 300px;
  height: 310px;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.tech-map-container {
  width: 100%; height: 100%;
  z-index: 1;
}

/* Contrôles flottants */
.tech-map-controls {
  position: absolute;
  top: 12px; right: 12px;
  display: flex; flex-direction: column;
  gap: 8px; z-index: 20;
}

.tech-map-btn {
  width: 42px; height: 42px; min-width: 42px;
  border-radius: 14px; border: none;
  background: rgba(0, 0, 0, 0.78);
  color: white;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease;
  flex-shrink: 0;
}
.tech-map-btn:hover  { background: rgba(0, 0, 0, 0.92); }
.tech-map-btn:active { transform: scale(0.94); }

/* Barre de filtres sur la carte */
.tech-map-filter-bar {
  position: absolute;
  left: 10px; right: 10px; bottom: 10px;
  display: flex; align-items: center; gap: 8px;
  overflow-x: auto; scrollbar-width: none;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.72);
  color: white;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  z-index: 20;
}
.tech-map-filter-bar::-webkit-scrollbar { display: none; }
/* Fond fixe (indépendant du thème clair/sombre) — sans ça, en thème clair
   --bg-card2 (hérité de .chip) devient presque blanc et le texte "color:white"
   forcé devient illisible dessus. */
.tech-map-filter-bar .chip {
  color: white;
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.2);
}
.tech-map-filter-bar .chip.active {
  background: rgba(59,130,246,0.45);
  border-color: rgba(96,165,250,0.7);
  color: white;
}

/* Bouton "ma position" */
#map-locate-btn.locating svg { animation: spin 1s linear infinite; }

/* ─── SERVICE CARDS ──────────────────────── */
.map-service-cards {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  max-height: 40vh; overflow-y: auto;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px;
}

.service-card {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border-radius: 12px;
  background: var(--bg-card2);
  cursor: pointer; transition: all 0.2s;
  border: 1px solid var(--border);
  overflow: hidden;
}
.service-card:active { background: var(--bg-hover); transform: scale(0.98); }
.service-card.focused { border-color: var(--blue); background: var(--bg-hover); }

.service-card-avatar {
  font-size: 26px;
  width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px; background: var(--bg-card);
  flex-shrink: 0;
}
.service-card-body  { flex: 1; min-width: 0; }
.service-card-name  { font-weight: 600; font-size: 14px; color: var(--text-1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.service-card-distance { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.service-card-rating   { font-size: 12px; color: var(--orange); margin-top: 2px; }
.service-card-arrow    { font-size: 18px; color: var(--text-3); flex-shrink: 0; }

/* ─── Leaflet overrides ──────────────────── */
#map-container .leaflet-control-attribution { display: none; }
#map-container .leaflet-marker-shadow       { display: none; }

.tech-map-container .leaflet-control-layers {
  border: none;
  background: rgba(10,15,30,0.92);
  backdrop-filter: blur(10px);
  border-radius: var(--r-md);
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
}
.tech-map-container .leaflet-control-zoom { border: none; }
.tech-map-container .leaflet-control-zoom a {
  background: rgba(10,15,30,0.88);
  backdrop-filter: blur(10px);
  color: var(--text-1, #f1f5f9);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  width: 30px; height: 30px; margin-bottom: 2px;
}
.tech-map-container .leaflet-popup-content-wrapper {
  border-radius: var(--r-md);
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
  border: 1px solid var(--border);
  background: var(--bg-card, #0e1628);
  color: var(--text-1, #f1f5f9);
}
.tech-map-container .leaflet-popup-tip { background: var(--bg-card, #0e1628); }

/* ─── Popup contenu (marqueur technicien) ──── */
.tm-popup { min-width: 190px; }
.tm-popup-header { display: flex; align-items: flex-start; gap: 10px; }
.tm-popup-av {
  width: 38px; height: 38px; flex-shrink: 0;
  border-radius: 50%; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: white;
}
.tm-popup-name { font-size: 14px; font-weight: 700; color: var(--text-1, #f1f5f9); display: flex; align-items: center; gap: 4px; }
.tm-popup-cat  { font-size: 12px; color: var(--text-2, #94a3b8); display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.tm-popup-dist { font-size: 12px; color: var(--text-2, #94a3b8); display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.tm-popup-stars { margin-top: 8px; font-size: 13px; color: var(--orange, #f59e0b); display: flex; align-items: center; gap: 4px; }
.tm-popup-btns { display: flex; gap: 8px; margin-top: 10px; }

/* ─── Markers ────────────────────────────── */
.tm-marker-wrap {
  display: flex; flex-direction: column; align-items: center;
  cursor: pointer;
  transform-origin: bottom center;
  transition: transform 0.15s ease;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.4));
}
.tm-marker-wrap:active { transform: scale(0.94); }
.tm-marker-wrap.tm-marker-me .tm-marker-bubble {
  box-shadow: 0 0 0 3px #3b82f6, 0 0 0 5px rgba(59,130,246,0.3);
}
.tm-marker-bubble {
  width: 46px; height: 46px;
  border-radius: 50%;
  overflow: hidden; /* sans ça, la photo (image carrée en 100%/100%) déborde du cercle */
  border: 3px solid rgba(255,255,255,0.9);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: white;
  position: relative;
}
.tm-marker-bubble::after {
  content: '';
  position: absolute; bottom: -10px; left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
}
.tm-marker-label {
  margin-top: 13px;
  padding: 3px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 700; color: white;
  white-space: nowrap;
}
/* Marqueur livreur grisé quand la position n'a pas été rafraîchie depuis
   un moment (demande explicite "marqueur grisé quand la position est
   ancienne") — jamais présenter une ancienne position comme si elle
   était actuelle. */
.tm-marker-wrap.tm-marker-stale {
  filter: grayscale(1) drop-shadow(0 4px 10px rgba(0,0,0,0.4));
  opacity: 0.6;
}

/* Couleurs markers par catégorie */
.tm-cat-electricien   { background: #f59e0b; }
.tm-cat-electricien::after   { border-top: 10px solid #f59e0b; }
.tm-cat-plombier      { background: #06b6d4; }
.tm-cat-plombier::after      { border-top: 10px solid #06b6d4; }
.tm-cat-informaticien { background: #7c3aed; }
.tm-cat-informaticien::after { border-top: 10px solid #7c3aed; }
.tm-cat-mecanicien    { background: #10b981; }
.tm-cat-mecanicien::after    { border-top: 10px solid #10b981; }
.tm-cat-climaticien   { background: #60a5fa; }
.tm-cat-climaticien::after   { border-top: 10px solid #60a5fa; }
.tm-cat-immo          { background: #ec4899; }
.tm-cat-immo::after          { border-top: 10px solid #ec4899; }
.tm-cat-default       { background: #6366f1; }
.tm-cat-default::after       { border-top: 10px solid #6366f1; }

.custom-stickman-marker { border: none !important; background: none !important; }

/* ─── Empty state ────────────────────────── */
.empty {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 40px 20px; text-align: center; gap: 10px;
}
.empty-icon  { font-size: 44px; margin-bottom: 6px; }
.empty-title { font-size: 16px; font-weight: 600; color: var(--text-2); }

/* ─── Responsive Map ─────────────────────── */

@media (max-width: 480px) {
  .topbar { padding: 0 8px; gap: 4px; }
  .topbar-title { font-size: 15px; }

  .filter-bar { padding: 8px 12px; gap: 6px; }
  .map-filter-btn { padding: 6px 12px; font-size: 12px; }

  .tech-map-section { height: 270px; min-height: 270px; }
  .tech-map-btn     { width: 38px; height: 38px; border-radius: 11px; }
  .tech-map-controls { top: 10px; right: 10px; gap: 7px; }
  .tech-map-filter-bar { left: 8px; right: 8px; bottom: 8px; padding: 7px 10px; gap: 6px; }

  .map-service-cards { padding: 10px 12px; gap: 6px; }
  .service-card { padding: 10px; gap: 10px; }
  .service-card-avatar { width: 38px; height: 38px; font-size: 22px; }
  .service-card-name { font-size: 13px; }

  .tm-marker-bubble { width: 40px; height: 40px; font-size: 12px; }
  .tm-marker-label  { font-size: 10px; padding: 2px 7px; }
}

@media (max-width: 360px) {
  .filter-bar { padding: 6px 10px; gap: 5px; }
  .map-filter-btn { padding: 5px 10px; font-size: 11px; }

  .tech-map-section  { height: 240px; min-height: 240px; }
  .tech-map-btn      { width: 36px; height: 36px; border-radius: 10px; }
  .tech-map-controls { top: 8px; right: 8px; gap: 6px; }
  .tech-map-filter-bar { left: 6px; right: 6px; bottom: 6px; padding: 6px 8px; border-radius: 12px; }

  .map-modal-content { height: 92vh; max-height: 92vh; }
  .map-modal-topbar  { padding: 10px 12px; }

  .service-card      { padding: 9px; gap: 8px; }
  .service-card-avatar { width: 34px; height: 34px; font-size: 18px; }
  .service-card-name   { font-size: 12px; }
  .service-card-distance, .service-card-rating { font-size: 11px; }

  .tm-marker-bubble { width: 36px; height: 36px; font-size: 11px; border-width: 2px; }
  .tm-marker-label  { font-size: 9px; margin-top: 10px; }
}
.map-fab-btn.locating {
  animation: spin 1s linear infinite;
  opacity: 0.7;
}

/* Picture-in-Picture Android pendant une livraison (PipService) — dans la
   mini-fenêtre flottante, Android désactive toute interaction tactile sauf
   ses propres contrôles système : les boutons/textes ne servent à rien et
   ne font que gêner la lecture de la carte, donc masqués plutôt
   qu'affichés inutilement. La navbar aussi (elle reste cliquable mais
   invisible dans une fenêtre de cette taille). */
body.pip-active #app-navbar,
body.pip-active .pip-hide {
  display: none !important;
}
/* PiP : la carte de livraison remplit TOUTE la mini-fenêtre. Avant, elle
   gardait sa hauteur fixe (280px suivi client / 220px retrait livreur)
   sous l'en-tête de la page — dans une fenêtre de ~200px de haut, on ne
   voyait quasiment que l'en-tête ("le PiP ne fonctionne pas"). */
body.pip-active #order-tracking-map,
body.pip-active #courier-pickup-map {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  margin: 0 !important;
  border-radius: 0 !important;
  z-index: 2147483000 !important;
}
body.pip-active #order-tracking-map .leaflet-control-container,
body.pip-active #courier-pickup-map .leaflet-control-container {
  display: none !important;
}
