:root {
  --bg: #0f1419;
  --bg-card: #1a2129;
  --bg-card2: #212b36;
  --border: #2d3a47;
  --text: #e8edf2;
  --text-dim: #8fa1b3;
  --accent: #ff6b35;
  --accent2: #4ecdc4;
  --ok: #06d6a0;
  --danger: #ef476f;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hidden { display: none !important; }

#sos-banner {
  background: var(--danger);
  color: #fff;
  text-align: center;
  padding: 10px;
  font-weight: 700;
  animation: pulse 1.2s infinite;
}
@keyframes pulse { 50% { opacity: 0.7; } }

/* Arrêt prolongé : informatif, pas une alerte — pas de rouge, pas de pulse. */
#stop-banner {
  background: #16323a;
  border-bottom: 1px solid #2a5f6b;
  color: var(--accent2);
  text-align: center;
  padding: 8px 10px;
  font-size: 0.88rem;
  font-weight: 600;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.title { display: flex; align-items: center; gap: 12px; }
.title .moto { font-size: 2rem; }
h1 { font-size: 1.15rem; }
.subtitle { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; color: var(--text-dim); }
.badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  letter-spacing: 0.5px;
  white-space: nowrap; /* sur un écran étroit, il se coupait en deux lignes */
}
.badge.on { background: var(--ok); color: #04302a; animation: pulse 2s infinite; }
.badge.off { background: var(--border); color: var(--text-dim); }
/* Voyage terminé : un état, pas une alerte — ni clignotement ni rouge. */
.badge.done { background: var(--accent2); color: #05312d; }
.header-actions a {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.header-actions a:hover { color: var(--text); border-color: var(--accent); }

main { display: flex; flex: 1; min-height: 0; }

#map-wrap { flex: 1; position: relative; min-width: 0; }
#map { height: 100%; width: 100%; background: #0a0e12; }

#map-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ctl {
  width: 42px; height: 42px;
  font-size: 1.2rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.ctl.active { border-color: var(--accent); background: #2a1f18; }

#replay-info {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.9rem;
  box-shadow: 0 2px 12px rgba(0,0,0,0.5);
  white-space: nowrap;
}

#panel {
  width: 380px;
  overflow-y: auto;
  background: var(--bg);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-shrink: 0;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}
.card h2 { font-size: 0.95rem; margin-bottom: 10px; }
.hint { font-size: 0.78rem; color: var(--text-dim); margin-bottom: 8px; }

/* Phases du voyage */
.phase-track { display: flex; align-items: center; padding: 4px 6px 0; }
.phase-step { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.p-dot {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--bg-card2);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: all 0.4s;
}
.p-lbl { font-size: 0.7rem; color: var(--text-dim); white-space: nowrap; }
.p-line { flex: 1; height: 3px; background: var(--border); margin: 0 6px 20px; border-radius: 2px; transition: background 0.4s; }
.phase-step.done .p-dot { background: var(--accent2); border-color: var(--accent2); color: #05312d; }
.phase-step.active .p-dot { border-color: var(--accent); background: #2a1f18; font-size: 17px; animation: pulse 2s infinite; }
.phase-step.active .p-lbl, .phase-step.done .p-lbl { color: var(--text); }
.p-line.done { background: var(--accent2); }
.progress-text { text-align: center; font-size: 0.8rem; color: var(--text-dim); margin-top: 10px; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { display: flex; align-items: center; gap: 8px; background: var(--bg-card2); border-radius: 10px; padding: 8px 10px; }
.stat-icon { font-size: 1.3rem; }
.stat-val { font-size: 1.05rem; font-weight: 700; }
.stat-label { font-size: 0.68rem; color: var(--text-dim); }
.countries { margin-top: 10px; font-size: 1.3rem; letter-spacing: 4px; text-align: center; }
/* Le curseur « help » annonce l'infobulle ; le padding donne une cible
   confortable au doigt, l'appui remplaçant le survol sur mobile. */
.countries span { cursor: help; padding: 2px 3px; border-radius: 4px; }
.countries span:hover, .countries span.on { background: var(--bg-card2); }
/* Hauteur réservée : la légende apparaît et disparaît au fil du survol,
   sans faire sauter la carte de statistiques. */
.country-label {
  min-height: 1.2em;
  margin-top: 6px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* Météo */
#weather { display: flex; align-items: center; gap: 14px; font-size: 0.9rem; }
#weather .w-icon { font-size: 2.2rem; }
#weather .w-temp { font-size: 1.5rem; font-weight: 700; }
#weather .w-detail { color: var(--text-dim); font-size: 0.78rem; }
#rain-alert {
  margin-top: 10px;
  background: #2a2418;
  border: 1px solid #6b5a2e;
  color: #ffd166;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.82rem;
}

/* Autonomie essence */
.fuel-gauge { height: 10px; border-radius: 5px; background: var(--bg-card2); overflow: hidden; margin-bottom: 10px; }
.fuel-gauge-fill { height: 100%; border-radius: 5px; background: #4caf50; transition: width 0.4s; }
.fuel-gauge-fill.low { background: #e5533d; }
.fuel-range { font-size: 1.05rem; font-weight: 700; }
.fuel-detail { color: var(--text-dim); font-size: 0.78rem; margin-top: 2px; }
.fuel-warning {
  margin-top: 8px;
  background: #2a1818;
  border: 1px solid #6b2e2e;
  color: #ff8a80;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.82rem;
}

/* Météo multi-jours */
.w-daily { display: flex; gap: 6px; margin-top: 12px; overflow-x: auto; }
.w-day { flex: 1 0 56px; text-align: center; background: var(--bg-card2); border-radius: 8px; padding: 6px 4px; font-size: 0.72rem; }
.w-day .wd-label { color: var(--text-dim); text-transform: capitalize; }
.w-day .wd-icon { font-size: 1.3rem; margin: 2px 0; }
.w-day .wd-temp { font-weight: 600; }
.w-day .wd-min { color: var(--text-dim); font-weight: 400; }
.w-day .wd-rain { color: #7ec8ff; font-size: 0.65rem; }

/* Hauteur figée (cf. ALT_H dans app.js) : sans elle, la hauteur affichée
   découle des attributs width/height du canvas, que le dessin recalcule en
   pixels physiques — le graphe changeait donc de proportions selon la densité
   de l'écran. display:block supprime en prime l'espace de descente de ligne
   sous le canvas. */
#alt-chart { display: block; width: 100%; height: 90px; }

/* Étapes */
.days-list { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; }
.day-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card2);
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  border-left: 4px solid transparent;
}
.day-row:hover { background: #28343f; }
.day-row .d-date { font-weight: 600; }
.day-row .d-info { color: var(--text-dim); font-size: 0.75rem; }
.day-row .d-km { font-weight: 700; color: var(--accent2); }

/* Feed */
.feed { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }
.feed-item { background: var(--bg-card2); border-radius: 10px; padding: 8px 10px; font-size: 0.85rem; }
.feed-item .f-head { display: flex; justify-content: space-between; color: var(--text-dim); font-size: 0.72rem; margin-bottom: 3px; }
.feed-item.sos { border: 1px solid var(--danger); }
.feed-item.border { border: 1px solid var(--accent2); }

/* Photos 📸 */
.f-photo {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 8px;
  margin: 4px 0 6px;
  cursor: zoom-in;
}
.popup-photo {
  width: 220px;
  max-width: 100%;
  border-radius: 8px;
  margin: 6px 0;
  cursor: zoom-in;
}
#lightbox {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
#lightbox img {
  max-width: 94vw;
  max-height: 94vh;
  border-radius: 10px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.8);
}

footer { text-align: center; color: var(--text-dim); font-size: 0.72rem; padding: 8px 0 16px; }

/* Marqueur moto */
.moto-marker { font-size: 26px; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.6)); position: relative; }
.moto-marker .pulse {
  position: absolute;
  top: 50%; left: 50%;
  width: 14px; height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: var(--ok);
  animation: ripple 1.8s infinite;
  z-index: -1;
}
@keyframes ripple {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(4); opacity: 0; }
}
.checkin-marker { font-size: 20px; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.6)); }

/* Arrivée : le marqueur de fin de voyage, sans le halo « en direct ». */
.finish-marker { font-size: 26px; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.6)); }

/* Marqueur combiné : plusieurs check-ins trop proches pour être distingués */
.checkin-cluster {
  display: flex;
  align-items: center;
  gap: 1px;
  height: 26px;
  padding: 0 5px;
  border-radius: 13px;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  font-size: 15px;
  line-height: 1;
  white-space: nowrap;
}
.checkin-cluster-more {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  margin-left: 2px;
}

.leaflet-popup-content-wrapper { background: var(--bg-card); color: var(--text); border-radius: 10px; }
.leaflet-popup-tip { background: var(--bg-card); }

/* Mobile */
@media (max-width: 800px) {
  body { overflow: auto; }
  main { flex-direction: column; }
  #map-wrap { height: 55dvh; flex: none; }
  #panel { width: 100%; flex: 1; }
}
