:root {
  --hour-height: 60px;
  --grid-hours: 24;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: Arial, Helvetica, sans-serif;
  background: #f4f4f4;
  color: #181818;
}

/* ============================================================
   EN-TETE
   ============================================================ */

.page-header {
  background: #fff;
  padding: 14px 24px;
  border-bottom: 1px solid #d5d5d5;

  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  display: block;
  width: auto;
  height: 62px;
  object-fit: contain;
}

h1 {
  margin: 0;
  font-size: 27px;
}

.page-header p {
  margin: 4px 0 0;
  color: #666;
  font-size: 13px;
}

button {
  border: 0;
  border-radius: 6px;
  padding: 11px 17px;
  cursor: pointer;
  font-weight: 700;
}

/* ============================================================
   GRILLE
   ============================================================ */

main {
  padding: 18px;
  overflow-x: auto;
}

#status {
  text-align: center;
  padding: 30px;
}

.schedule {
  display: flex;
  min-width: 1050px;

  background: white;
  border: 1px solid #aaa;
}

.time-column {
  width: 62px;
  flex: 0 0 62px;
  border-right: 1px solid #aaa;
}

.day-header,
.day-title {
  height: 42px;
  border-bottom: 1px solid #aaa;
}

.day-title {
  display: flex;
  align-items: center;
  justify-content: center;

  text-transform: uppercase;
  font-size: 12px;
  font-weight: 700;

  background: #fafafa;
}

.hour {
  height: var(--hour-height);
  border-bottom: 1px solid #ddd;

  padding: 3px 5px;
  text-align: right;

  color: #555;
  font-size: 10px;
}

.days {
  flex: 1;

  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.day {
  border-right: 1px solid #bbb;
  min-width: 0;
}

.day:last-child {
  border-right: none;
}

.day-body {
  position: relative;
  height: calc(var(--grid-hours) * var(--hour-height));
}

.hour-line {
  height: var(--hour-height);
  border-bottom: 1px solid #ddd;
}

/* ============================================================
   EMISSIONS
   ============================================================ */

.show {
  position: absolute;

  left: 3px;
  right: 3px;

  border-radius: 4px;
  border: 1px solid rgba(0,0,0,.25);

  padding: 4px 6px;

  overflow: hidden;

  font-size: 10px;
  line-height: 1.15;

  /* couleur de secours */
  background: #dedede;

  /* essentiel pour Chrome/Firefox impression */
  print-color-adjust: exact;
  -webkit-print-color-adjust: exact;
}

.show strong {
  display: block;

  font-size: 11px;
  font-weight: 700;

  white-space: normal;
}

.show-time {
  display: block;
  margin-top: 2px;

  font-size: 9px;
  opacity: .8;
}

footer {
  padding: 8px 20px 14px;
  text-align: center;

  font-size: 10px;
  color: #777;
}

/* ============================================================
   IMPRESSION
   ============================================================ */

/* ============================================================
   IMPRESSION - A4 PAYSAGE
   ============================================================ */

@page {
  size: A4 landscape;
  margin: 4mm;
}

@media print {

  :root {
    --hour-height: 6.7mm;
  }

  html,
  body {
    width: 100%;
    height: auto;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff;

    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  /* En-tête compact */
  .page-header {
    height: 14mm;
    padding: 1mm 1.5mm 1.5mm;
    border-bottom: 0.3mm solid #777;
  }

  .brand {
    gap: 3mm;
  }

  .logo {
    height: 11mm;
    width: auto;
    max-width: 34mm;
    object-fit: contain;
  }

  h1 {
    font-size: 12pt;
    line-height: 1;
  }

  .page-header p {
    margin-top: 1mm;
    font-size: 5.5pt;
    line-height: 1;
  }

  /* Cache le bouton d'impression */
  .actions {
    display: none !important;
  }

  main {
    margin: 0 !important;
    padding: 1.5mm 0 0 !important;
    overflow: visible;
  }

  /* Grille */
  .schedule {
    width: 100%;
    min-width: 0;
    margin: 0;

    page-break-inside: avoid;
    break-inside: avoid-page;

    border-width: 0.25mm;
  }

  .time-column {
    width: 9mm;
    flex: 0 0 9mm;
  }

  .day-header,
  .day-title {
    height: 7mm;
  }

  .day-title {
    font-size: 5.8pt;
  }

  .hour {
    height: var(--hour-height);
    padding: 0.5mm 0.7mm;
    font-size: 4.7pt;
    line-height: 1;
  }

  .hour-line {
    height: var(--hour-height);
  }

  /* Blocs des émissions */
  .show {
    left: 0.6mm;
    right: 0.6mm;
    padding: 0.7mm;
    border-radius: 0.7mm;
    font-size: 5pt;
    line-height: 1.05;

    print-color-adjust: exact !important;
    -webkit-print-color-adjust: exact !important;
  }

  .show strong {
    font-size: 5.5pt;
    line-height: 1.05;
  }

  .show-time {
    margin-top: 0.4mm;
    font-size: 4.3pt;
    line-height: 1;
  }

  /* Date de génération directement sous la grille */
  footer {
    margin: 0 !important;
    padding: 1.5mm 0 0 !important;
    height: auto !important;
    min-height: 0 !important;

    text-align: center;
    font-size: 4.5pt;
    line-height: 1;
    color: #666;
  }
}

/* --- Correctifs vue publique --- */

.show {
  cursor: pointer !important;
  pointer-events: auto !important;
  z-index: 10 !important;
}

.show:hover {
  filter: brightness(0.92);
  transform: scale(1.01);
}

.modal[hidden] {
  display: none !important;
}

.modal:not([hidden]) {
  display: block !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 99999;
}

.modal-card {
  position: relative;
  z-index: 100001;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  z-index: 100000;
}

/* ============================================================
   MODALE ÉMISSION - VERSION PROPRE
   ============================================================ */

body.modal-open {
  overflow: hidden;
}

.modal[hidden] {
  display: none !important;
}

.modal:not([hidden]) {
  display: flex !important;
  align-items: center;
  justify-content: center;
}

.modal {
  position: fixed !important;
  inset: 0 !important;

  width: 100vw !important;
  height: 100vh !important;

  z-index: 999999 !important;

  padding: 20px;
  box-sizing: border-box;
}

/* Fond sombre derrière la fiche */
.modal-backdrop {
  position: absolute !important;
  inset: 0 !important;

  width: 100% !important;
  height: 100% !important;

  background: rgba(0, 0, 0, 0.65) !important;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);

  z-index: 1 !important;
}

/* Carte blanche */
.modal-card {
  position: relative !important;

  z-index: 2 !important;

  width: min(560px, 92vw) !important;
  max-height: 85vh !important;

  margin: 0 !important;
  padding: 28px !important;

  overflow-y: auto;

  box-sizing: border-box;

  background: #ffffff !important;
  color: #181818 !important;

  border: 0 !important;
  border-radius: 14px !important;

  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.35) !important;
}

/* Bouton fermer */
.modal-close {
  position: absolute !important;

  top: 12px !important;
  right: 12px !important;

  width: 36px;
  height: 36px;

  display: flex;
  align-items: center;
  justify-content: center;

  padding: 0;

  border: 0 !important;
  border-radius: 50% !important;

  background: #f1f1f1 !important;
  color: #222 !important;

  font-size: 24px !important;
  line-height: 1 !important;

  cursor: pointer;
}

.modal-close:hover {
  background: #dedede !important;
}

/* Image de l'émission */
.modal-image {
  display: block;

  width: 100% !important;
  max-height: 260px !important;

  margin: 0 0 20px 0 !important;

  object-fit: cover;

  border-radius: 9px;
}

.modal-image[hidden] {
  display: none !important;
}

/* Nom émission */
.modal-card h2 {
  margin: 0 45px 8px 0 !important;

  font-size: 26px !important;
  line-height: 1.15 !important;

  color: #181818 !important;
}

/* Horaire */
.modal-time {
  margin: 0 0 20px 0 !important;

  font-size: 14px !important;
  font-weight: 600 !important;

  color: #666 !important;
}

/* Description */
#modal-description {
  margin: 0 !important;

  font-size: 16px !important;
  line-height: 1.6 !important;

  color: #333 !important;

  white-space: pre-line;
}

/* Lien */
.modal-link {
  display: inline-flex !important;

  align-items: center;

  margin-top: 22px !important;
  padding: 10px 16px !important;

  background: #222 !important;
  color: #fff !important;

  border-radius: 7px !important;

  font-size: 14px !important;
  font-weight: 600 !important;

  text-decoration: none !important;
}

.modal-link:hover {
  background: #444 !important;
}

.modal-link[hidden] {
  display: none !important;
}

/* Téléphone */
@media (max-width: 600px) {

  .modal {
    padding: 12px;
  }

  .modal-card {
    width: 100% !important;
    max-height: 90vh !important;

    padding: 22px !important;

    border-radius: 12px !important;
  }

  .modal-card h2 {
    font-size: 22px !important;
  }

  #modal-description {
    font-size: 15px !important;
  }
}


.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  justify-content: center;
  align-items: center;
  padding: 10px 16px 4px;
  font-size: 11px;
}

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

.legend-item span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 18px;
  padding: 0 5px;
  border: 1px solid rgba(0,0,0,.18);
  border-radius: 4px;
  font-size: 9px;
  font-weight: 700;
}


/* ============================================================
   CAMPUS FLOW - LEGENDE HORIZONTALE V3
   ============================================================ */

.legend {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;

  align-items: center;
  justify-content: center;

  gap: 10px;

  width: 100%;
  padding: 10px 6px 5px;

  overflow-x: auto;
  overflow-y: hidden;

  white-space: nowrap;

  font-size: 10px;
}

.legend-item {
  display: inline-flex !important;
  flex-direction: row !important;
  flex: 0 0 auto;

  align-items: center;

  gap: 5px;

  white-space: nowrap;
}

.legend-color {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  flex: 0 0 auto;

  width: 26px;
  height: 18px;

  border: 1px solid rgba(0,0,0,.18);
  border-radius: 4px;

  font-size: 8px;
  font-weight: 700;
}


/* ============================================================
   LOGOS DES EMISSIONS
   ============================================================ */

.show {
  position: absolute;
}

.show-logo {
  position: absolute;

  top: 5px;
  right: 5px;

  width: 28px;
  height: 28px;

  object-fit: contain;

  padding: 2px;

  background: rgba(255,255,255,.92);

  border-radius: 5px;

  box-shadow: 0 1px 3px rgba(0,0,0,.15);

  pointer-events: none;

  z-index: 3;
}

.show:has(.show-logo) strong {
  padding-right: 34px;
}


/* Image principale dans la popup */

.modal-image {
  width: auto !important;
  max-width: 100% !important;

  height: auto !important;
  max-height: 220px !important;

  margin:
    0
    auto
    20px
    auto !important;

  object-fit: contain !important;

  background: #f7f7f7;

  border-radius: 10px;
}

/* Logos émissions - taille augmentée */
.show-logo {
  width: 40px !important;
  height: 40px !important;

  top: 6px !important;
  right: 6px !important;

  padding: 2px !important;

  object-fit: contain !important;

  background: rgba(255,255,255,.94) !important;

  border-radius: 6px !important;

  box-shadow: 0 1px 4px rgba(0,0,0,.18) !important;
}

.show:has(.show-logo) strong {
  padding-right: 48px !important;
}
