/* === CSS mis à jour pour affichage responsive du calendrier === */
.calM {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: #ccc;
  margin: 1rem;
  overflow-x: auto;
}
.calM .weekday {
  background: #4285f4;
  color: #fff;
  text-align: center;
  padding: 0.5rem;
  font-weight: bold;
}
.calendar-day,
.calendar-day.empty-day {
  background: #fff;
  padding: 0.25rem;
  position: relative;
  min-height: 4rem;
}
.day-number {
  font-weight: bold;
  margin-bottom: 0.25rem;
}
.event,
.detail-link {
  background: #d2e3fc;
  padding: 0.25rem;
  margin: 0.2rem 0;
  border-radius: 0.2rem;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: normal !important;
  word-break: keep-all;
  overflow-wrap: break-word;
  overflow: visible !important;
  text-overflow: clip !important;
  display: block;
  text-decoration: none;
  color: #1a1a1a;
  transition: background 0.2s;
}
.event:hover,
.detail-link:hover {
  background: #aecbfa;
}

/* ========== TOOLTIPS AMÉLIORÉS (au-dessus des cases) ========== */
.event[data-tooltip] {
  position: relative;
}
/* Masquer le tooltip par défaut */
.event[data-tooltip]::before,
.event[data-tooltip]::after {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  pointer-events: none;
}
/* Contenu du tooltip (au-dessus) */
.event[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(-100% - 12px); /* Positionnement au-dessus */
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 16px;
  background: #f8f9fa; /* Fond clair */
  color: #212529; /* Texte noir */
  border-radius: 8px;
  white-space: pre-line;
  font-size: 13px;
  line-height: 1.5;
  z-index: 1000;
  min-width: 200px;
  max-width: 300px; /* Largeur maximale augmentée */
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  text-align: left;
  border: 1px solid #dee2e6; /* Bordure légère */
}
/* Flèche du tooltip (vers le bas) */
.event[data-tooltip]::before {
  content: '';
  position: absolute;
  top: calc(-100% - 4px); /* Positionnement au-dessus */
  left: 50%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: #f8f9fa; /* Couleur de la flèche */
  z-index: 1001;
}
/* Afficher au survol */
.event[data-tooltip]:hover::before,
.event[data-tooltip]:hover::after {
  opacity: 1;
  visibility: visible;
}
/* Tooltip en BAS pour les événements en bas du calendrier (si nécessaire) */
.calM > .event[data-tooltip]:nth-last-child(-n+7)::after {
  top: auto;
  bottom: calc(100% + 12px);
}
.calM > .event[data-tooltip]:nth-last-child(-n+7)::before {
  top: auto;
  bottom: calc(100% + 4px);
  border-top-color: transparent;
  border-bottom-color: #f8f9fa;
}
/* Ajustement pour les événements à gauche */
.calendar-day:nth-child(7n+1) .event[data-tooltip]::after {
  left: 10px;
  transform: none;
}
/* Ajustement pour les événements à droite */
.calendar-day:nth-child(7n) .event[data-tooltip]::after {
  left: auto;
  right: 10px;
  transform: none;
}
/* Support tactile (mobile) */
.event.touch-active[data-tooltip]::before,
.event.touch-active[data-tooltip]::after {
  opacity: 1;
  visibility: visible;
}
.calendar-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
/* Responsive portrait: rétrécit les cellules mais conserve les 7 jours */
@media screen and (max-width: 768px) and (orientation: portrait) {
  .calM {
    grid-template-columns: repeat(7, minmax(50px, 1fr));
    margin: 0.5rem;
  }
  .calendar-day {
    min-width: 50px;
    font-size: 0.8em;
    min-height: 3.5rem;
  }
  .calendar-day .event {
    font-size: 0.7em;
    line-height: 1.3;
    padding: 0.2rem;
  }
  /* Tooltips plus petits sur mobile */
  .event[data-tooltip]::after {
    font-size: 11px;
    padding: 8px 12px;
    min-width: 150px;
    max-width: 200px;
  }
}
/* Responsive très petit écran : scroll horizontal */
@media screen and (max-width: 480px) {
  .calM {
    grid-template-columns: repeat(7, minmax(60px, 1fr));
    margin: 0.25rem;
  }
  .calendar-day .event {
    font-size: 0.65em;
  }
  .event[data-tooltip]::after {
    font-size: 10px;
    padding: 6px 10px;
    min-width: 120px;
  }
}
/* Modal / Overlay styles */
#modalOverlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
}
#detailModal {
  display: none;
  background: #fff;
  max-width: 90vw;
  margin: 10vh auto;
  padding: 1rem;
  border-radius: 8px;
  position: relative;
  box-shadow: 0 2px 10px rgba(0,0,0,0.3);
  z-index: 1001;
}
#modalClose {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  cursor: pointer;
  font-size: 1.5rem;
  background: none;
  border: none;
  color: #666;
}
#modalClose:hover {
  color: #000;
}
.button-action {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: #4285f4;
  color: white;
  border-radius: 5px;
  text-decoration: none;
  margin-top: 0.5rem;
  text-align: center;
  border: none;
  cursor: pointer;
}
.button-action:hover {
  background: #3367d6;
}
