/* ===================================
   VARIABLES CSS
   =================================== */
:root {
  --calendar-transition-duration: 0.3s;
  --calendar-grid-gap: 5px;
  --calendar-day-min-height: 120px;
  --event-badge-height: 24px;
  --calendar-day-bg: #213046;
  --calendar-day-hover: #2b3e5a;
  --calendar-header-bg: var(--primary-color-darker, #1a2332);
}

/* ===================================
   ANIMATIONS DE TRANSITION
   =================================== */

/* Fade in lors du chargement AJAX */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%,
  100% {
    outline-opacity: 1;
  }
  50% {
    outline-opacity: 0.6;
  }
}

@keyframes dotPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

/* Animation du conteneur lors du chargement */
#calendarAjaxRoot {
  transition: opacity var(--calendar-transition-duration) ease;
}

#calendarAjaxRoot[data-loading="true"] {
  opacity: 0.6;
  pointer-events: none;
}

/* Animation des éléments nouvellement chargés */
.calendar-card,
.event-card {
  animation: fadeIn var(--calendar-transition-duration) ease;
}

/* ===================================
   GRILLE CALENDRIER
   =================================== */

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--calendar-grid-gap);
  overflow: hidden;
  align-items: stretch;
}

/* En-têtes jours */
.calendar-header {
  background: var(--calendar-header-bg);
  padding: 0.75rem 0.5rem;
  color: white;
  text-align: center;
  font-weight: 700;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  user-select: none;
  border-radius: 0.5rem;
}

/* ==========================================
   CALENDAR DAYS
   ========================================== */

/* Cases jours */
.calendar-day {
  background: var(--calendar-day-bg);
  height: var(--calendar-day-min-height);
  overflow: hidden;
  padding: 0.5rem;
  display: flex;
  border-radius: 0.5rem;
  flex-direction: column;
  gap: 0.25rem;
  position: relative;
  transition:
    background-color 0.2s ease,
    transform 0.15s ease;
}

.calendar-day:hover {
  background: var(--calendar-day-hover);
  transform: translateY(-1px);
}

/* Jours d'autres mois */
.calendar-day.other-month {
  background: #161f2e;
  color: #9ca3af;
  opacity: 0.7;
}

/* Jour actuel */
.calendar-day.today {
  outline: 2px solid var(--important-color, #f59e0b);
  outline-offset: -2px;

  background: linear-gradient(
    135deg,
    var(--bs-primary-bg-subtle) 0%,
    var(--bs-body-bg) 100%
  );
}

/* Numéro du jour */
.day-number {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 0.875rem;
  line-height: 1;
  margin-bottom: 0.25rem;
}

.day-events {
  flex: 1 1 auto;
  min-height: 0; /* crucial pour que le scroll marche */
  overflow: hidden; /* ou auto si tu veux scroll */
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

/* Si tu veux scroll uniquement quand ça dépasse */
.day-events {
  overflow-y: auto;
}

/* Pill "Aujourd'hui" */
.today-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bs-primary);
  color: white;
  padding: 0.2rem 0.5rem;
  border-radius: 1rem;
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
}

/* ===================================
   BADGES ÉVÉNEMENTS (dans la grille)
   =================================== */

.event-badge {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.5rem;
  background: var(--bs-secondary-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
  height: var(--event-badge-height);
  text-align: left;
  width: 100%;
}

/* Background image (lazy loaded) */
.event-badge::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--event-bg, none) center/cover;
  opacity: 0.15;
  transition: opacity 0.2s ease;
}

/* Overlay dégradé */
.event-badge::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0.35));
  z-index: 0;
}

/* Contenu au-dessus */
.event-badge > * {
  position: relative;
  z-index: 1;
  min-width: 0;
}

.event-badge span:last-child {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* États */
.event-badge:hover,
.event-badge:focus {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.event-badge:hover::before {
  opacity: 0.25;
}

.event-badge:active {
  transform: translateY(0);
}

/* Statut colors */
.event-badge.status-active {
  border-left: 3px solid #10b981;
}

.event-badge.status-upcoming {
  border-left: 3px solid #6366f1;
}

.event-badge.status-ended {
  border-left: 3px solid #ef4444;
  opacity: 0.7;
}

/* Dot indicateur */
.event-badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.event-badge.status-active .dot {
  background: #10b981;
  animation: dotPulse 2s ease-in-out infinite;
}

.event-badge.status-upcoming .dot {
  background: #6366f1;
}

.event-badge.status-ended .dot {
  background: #ef4444;
}

/* Texte tronqué */
.event-badge span:last-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
  z-index: 1;
}

/* ===================================
   CARTES ÉVÉNEMENTS (liste)
   =================================== */

.event-card {
  background: var(--bs-body-bg);
  border: 1px solid var(--detail-color, #374151);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border-radius: 0.5rem;
  overflow: hidden;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.event-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.event-card img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  display: block;
}

.event-card > div:last-child {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.event-card button {
  margin-top: auto;
}

/* Badges de statut */
.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}

.badge-active {
  background: #10b98120;
  color: #10b981;
  border: 1px solid #10b98140;
}

.badge-upcoming {
  background: #6366f120;
  color: #6366f1;
  border: 1px solid #6366f140;
}

.badge-ended {
  background: #ef444420;
  color: #ef4444;
  border: 1px solid #ef444440;
}

/* ===================================
   FILTRES
   =================================== */
.form-check-input:checked {
  background-color: var(--detail-color) !important;
  border-color: var(--detail-color) !important;
}

.form-check-label {
  cursor: pointer;
  user-select: none;
}

/* ===================================
   MODAL
   =================================== */
.modal-header {
  background: linear-gradient(
    135deg,
    var(--primary-color) 0%,
    var(--primary-color-dark, var(--primary-color)) 100%
  );
  border-bottom: none;
}

.modal-title {
  color: white;
}

/* ===================================
   LOADING STATE
   =================================== */
.calendar-loading {
  position: relative;
}

.calendar-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
  z-index: 1000;
}

/* ===================================
   BOUTONS NAVIGATION
   =================================== */
.js-calendar-nav {
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.js-calendar-nav:hover:not(:disabled) {
  transform: scale(1.05);
}

.js-calendar-nav:active:not(:disabled) {
  transform: scale(0.95);
}

.js-calendar-nav:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Bouton "Aujourd'hui" special highlight */
.js-calendar-today {
  background: var(--important-color);
}

.js-calendar-today:hover:not(:disabled) {
  background: #72bf8c;
  color: white;
}

/* ===================================
   RESPONSIVE
   =================================== */

/* Tablettes */
@media (max-width: 992px) {
  /* Supprimer le aujourd'hui */
  .today-pill span {
    display: none;
  }
}

/* Tablettes */
@media (max-width: 768px) {
  :root {
    --calendar-gap: 5px;
    --calendar-day-min-height: 90px;
  }

  .calendar-header {
    font-size: 0.7rem;
    padding: 0.5rem 0.3rem;
  }

  .calendar-day {
    height: var(--calendar-day-min-height);
    padding: 0.35rem;
  }

  .day-number {
    font-size: 0.75rem;
    margin-bottom: 0.35rem;
  }

  .today-pill span {
    display: none;
  }

  .event-badge {
    gap: 0.25rem;
  }

  .event-badge .dot {
    width: 6px;
    height: 6px;
  }

  /* Scroll horizontal si nécessaire */
  .calendar-grid {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
  }

  /* Largeur minimale pour éviter le squeeze */
  .calendar-day {
    min-width: 100px;
  }

  /* Event cards plus grandes sur mobile */
  .event-card img {
    height: 150px;
  }
}

/* Mobile */
@media (max-width: 576px) {
  .calendar-day .event-badge {
    padding: 6px 8px;
    min-height: 28px;
    justify-content: center;

    font-size: 0.65rem;
    padding: 0.15rem 0.25rem;
    height: 18px;
    gap: 0.2rem;
  }

  .calendar-grid {
    gap: 5;
  }

  .calendar-day {
    min-height: 60px;
    padding: 0.25rem;
  }

  .today-pill {
    font-size: 0.5rem;
    padding: 0.1rem 0.375rem;
  }

  .calendar-header {
    padding: 0.5rem 0.25rem;
    font-size: 0.75rem;
  }
}

/* Très petits écrans */
@media (max-width: 480px) {
  :root {
    --calendar-day-min-height: 75px;
  }

  .calendar-day {
    min-width: 90px;
    padding: 0.25rem;
  }

  .event-badge {
    font-size: 0.6rem;
    padding: 0.15rem 0.3rem;
  }

  .day-number {
    font-size: 0.75rem;
  }
}

/* Réduction des animations si préféré */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
