/* ============================================
   IMPORTATIONS & VARIABLES
   ============================================ */

@import url(https://fonts.googleapis.com/css?family=Roboto);

:root {
  /* Couleurs primaires - Bleu sombre */
  --background: #0d1117;
  --text-primary: #f5f5f5;
  --text-secondary: #b0b0b0;

  /* Surfaces avec transparence */
  --surface: rgba(255, 255, 255, 0.04);
  --surface-hover: rgba(255, 255, 255, 0.08);

  /* Accent rouge CROUS */
  --accent-color: #d32f2f;
  --accent-color-hover: #b71c1c;
  --accent-color-light: rgba(211, 47, 47, 0.1);

  /* Ombres subtiles */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* ============================================
   RÉINITIALISATION & BASE
   ============================================ */

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

html {
  scroll-behavior: smooth;
}

body {
  background-color: var(--background);
  color: var(--text-primary);
  font: 14px Roboto, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

main {
  flex: 1;
}

a {
  color: var(--accent-color);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--accent-color-hover);
  text-decoration: underline;
}

/* ============================================
   HERO SECTION
   ============================================ */

#hero {
  background: linear-gradient(135deg, #0d1117 0%, #1a1f2e 100%);
  padding: 80px 20px;
  text-align: center;
  border-bottom: 1px solid rgba(211, 47, 47, 0.2);
}

.hero-content {
  max-width: 800px;
  margin: 0 auto;
}

#hero h1 {
  font-size: 3.5em;
  font-weight: 300;
  letter-spacing: 0.02em;
  margin-bottom: 15px;
  background: linear-gradient(135deg, #f5f5f5 0%, #d32f2f 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#hero p {
  font-size: 1.3em;
  color: var(--text-secondary);
  margin-bottom: 40px;
}

#bloc-recherche {
  display: flex;
  gap: 12px;
  margin-top: 30px;
}

#bloc-recherche > input[type="text"],
#bloc-recherche > button {
  font-family: inherit;
  font-size: 1em;
  padding: 14px 20px;
  border: none;
  background-color: var(--surface);
  color: var(--text-primary);
  transition: all 0.3s ease;
  cursor: default;
  border-radius: 8px;
}

#bloc-recherche > input[type="text"] {
  flex: 1;
  background-color: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(211, 47, 47, 0.2);
}

#bloc-recherche > input[type="text"]:focus {
  outline: none;
  background-color: rgba(255, 255, 255, 0.08);
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px var(--accent-color-light);
}

#bloc-recherche > input[type="text"]::placeholder {
  color: var(--text-secondary);
}

#bloc-recherche > button {
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--accent-color);
  border: 1px solid var(--accent-color);
  color: #ffffff;
  cursor: pointer;
  box-shadow: var(--shadow-md);
}

#bloc-recherche > button:hover {
  background-color: var(--accent-color-hover);
  border-color: var(--accent-color-hover);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

#bloc-recherche > button:active {
  background-color: #b71c1c;
  transform: translateY(0);
}

#bloc-recherche > button svg {
  display: block;
}

/* ============================================
   MAIN CONTENT LAYOUT
   ============================================ */

   #conteneur {
    display: block; 
    max-width: 1200px;
    margin: 50px auto;
    padding: 0 20px;
  }

/* ============================================
   SECTION RÉSULTATS
   ============================================ */

#section-resultats {
  grid-column: 1;
  margin-top: 40px;
}

/* Titre de section (favoris, résultats...) */
#section-favoris h2,
#section-resultats > p {
  margin-bottom: 16px;
  font-size: 1.1em;
  color: var(--text-secondary);
}

#bloc-gif-attente {
  display: none;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

#bloc-gif-attente.visible {
  display: block;
}

#bloc-resultats {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  margin-top: 20px;
  width: 100%;
}

/* Chaque item (région ou wrapper de CROUS) fait au minimum 160px et s'étire pour remplir la ligne */
#bloc-resultats > * {
  flex: 1 1 160px;
  min-width: 0;
}

/* Wrapper CROUS : flex colonne pour que p.res remplisse toute la hauteur */
.res-wrapper {
  position: relative;
  flex: 1 1 160px;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Les <a> des régions deviennent aussi des containers flex pour le même effet */
#bloc-resultats a {
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
}

/* La carte elle-même - même forme pour régions et CROUS */
#bloc-resultats p.res {
  margin: 0;
  flex: 1; /* remplace height: 100% - s'étire pour remplir son parent flex */
  min-height: 90px; /* hauteur minimale pour une forme cohérente */
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: linear-gradient(145deg, var(--surface), rgba(255,255,255,0.02));
  border: 1px solid rgba(211, 47, 47, 0.3);
  border-radius: 12px;
  padding: 25px;
  font-weight: bold;
  font-size: 1.1em;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}

#bloc-resultats p.res:hover {
  transform: translateY(-5px) scale(1.02);
  border-color: var(--accent-color);
  box-shadow: 0 8px 20px rgba(211, 47, 47, 0.2);
  background: linear-gradient(145deg, var(--surface-hover), rgba(211,47,47,0.05));
}

/* ============================================
   MODALE MENU DU JOUR
   ============================================ */

/* Fond semi-transparent qui couvre toute la page */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  /* cachée par défaut */
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* La carte centrale */
.modal-contenu {
  background: var(--background);
  border: 1px solid rgba(211, 47, 47, 0.35);
  border-radius: 16px;
  width: 100%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 28px;
  transform: scale(0.95);
  transition: transform 0.25s ease;
}

.modal-overlay.active .modal-contenu {
  transform: scale(1);
}

/* En-tête : titre + bouton fermer côte à côte */
.modal-entete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(211, 47, 47, 0.2);
}

.modal-entete h2 {
  margin: 0;
  font-size: 1.3em;
  font-weight: 500;
}

/* Bouton ✕ */
.modal-btn-fermer {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.3em;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 6px;
  line-height: 1;
  transition: background-color 0.2s ease, color 0.2s ease;
  flex-shrink: 0;
}

.modal-btn-fermer:hover {
  background-color: var(--surface-hover);
  color: var(--text-primary);
}

/* Contenu du menu dans la modale */
#modal-corps .repas_jour {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--surface-hover);
}

#modal-corps .repas_jour:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

/* Sur les cartes CROUS (dans un wrapper), on compense pour l'étoile en haut */
.res-wrapper p.res {
  padding-top: 36px;
}

/* Étoile positionnée en haut à droite de la carte */
#bloc-resultats .btn-favoris {
  position: absolute;
  top: 8px;
  right: 8px;
  background-color: var(--accent-color);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  padding: 5px;
  line-height: 0;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

/* L'icône devient blanche sur le fond rouge */
#bloc-resultats .btn-favoris img {
  filter: brightness(0) invert(1);
  display: block;
}

#bloc-resultats .btn-favoris:hover {
  background-color: var(--accent-color-hover);
  transform: scale(1.15);
}

/* On vire la petite flèche "→" qui fait trop liste */
#bloc-resultats p.res::before {
  content: none;
}

#bloc-resultats p.info-vide {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
  font-style: italic;
}

/* ============================================
   SECTION FAVORIS (SIDEBAR COLLAPSIBLE)
   ============================================ */

#section-favoris {
  grid-column: 2;
  grid-row: 1;
  height: fit-content;
  position: sticky;
  top: 20px;
}

.toggle-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background-color: var(--surface);
  border: 1px solid rgba(211, 47, 47, 0.2);
  color: var(--text-primary);
  font-size: 1em;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-bottom: 12px;
}

.toggle-btn:hover {
  background-color: var(--surface-hover);
  border-color: var(--accent-color);
}

.toggle-btn:active {
  background-color: rgba(211, 47, 47, 0.15);
}

.toggle-icon {
  display: inline-block;
  transition: transform 0.3s ease;
  color: var(--accent-color);
  font-weight: bold;
  font-size: 0.8em;
}

.toggle-btn[aria-expanded="true"] .toggle-icon {
  transform: rotate(-180deg);
}

.favoris-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.favoris-content.open {
  max-height: 1000px;
}

#liste-favoris {
  list-style: none;
  margin-bottom: 20px;
}

#liste-favoris li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  margin-bottom: 10px;
  background-color: var(--surface);
  border-radius: 6px;
  transition: all 0.2s ease;
}

/* Transformation des favoris en menu déroulant */
.favoris-dropdown {
  position: relative;
}

.favoris-dropdown .toggle-btn {
  height: 100%;
  margin: 0;
  white-space: nowrap;
}

.favoris-dropdown .favoris-content {
  position: absolute;
  top: 110%;
  right: 0;
  width: 250px;
  background: var(--background);
  border: 1px solid rgba(211, 47, 47, 0.4);
  border-radius: 8px;
  z-index: 100;
  box-shadow: var(--shadow-lg);
  text-align: left;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s ease;
}

.favoris-dropdown .favoris-content.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

#liste-favoris li:hover {
  background-color: var(--surface-hover);
  box-shadow: var(--shadow-sm);
  transform: translateX(2px);
}

#liste-favoris li span {
  flex: 1;
  color: var(--text-primary);
  cursor: pointer;
  transition: color 0.2s ease;
  font-size: 0.95em;
}

#liste-favoris li span:hover {
  color: var(--accent-color);
}

#liste-favoris button.btn-supprimer-favori {
  background: none;
  border: none;
  padding: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  flex-shrink: 0;
}

#liste-favoris button.btn-supprimer-favori:hover {
  color: var(--accent-color);
  background-color: rgba(211, 47, 47, 0.1);
}

#liste-favoris button.btn-supprimer-favori:focus {
  outline: none;
}

#section-favoris p.info-vide {
  font-size: 0.9em;
  color: var(--text-secondary);
  text-align: center;
  padding: 30px 15px;
  margin: 0;
  font-style: italic;
}

/* ============================================
   FOOTER
   ============================================ */

#footer {
  background-color: rgba(255, 255, 255, 0.02);
  border-top: 1px solid rgba(211, 47, 47, 0.2);
  padding: 40px 20px;
  margin-top: 60px;
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  text-align: center;
}

#footer p {
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-size: 0.95em;
}

#footer p:last-child {
  margin-bottom: 0;
}

#footer a {
  color: var(--accent-color);
  font-weight: 500;
  transition: color 0.2s ease;
}

#footer a:hover {
  color: var(--accent-color-hover);
}

.footer-secondary {
  font-size: 0.85em;
  color: #888888;
  margin-top: 12px;
}

/* ============================================
   ACCESSIBILITÉ & FOCUS VISIBLE
   ============================================ */

button:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

input:focus-visible {
  outline: none;
}

.favoris-dropdown {
  position: relative;
  margin-left: 20px; 
}

/* (styles des cartes définis plus haut dans SECTION RÉSULTATS) */


h3{
  color: var(--accent-color);
}

h3 *{
  color: var(--text-primary);
}

/* ============================================
   RESPONSIVE MOBILE
   ============================================ */

@media (max-width: 768px) {
  /* Le bloc de recherche passe en colonne sur mobile pour éviter les débordements */
  #bloc-recherche {
    flex-wrap: wrap;
  }

  #bloc-recherche > input[type="text"] {
    flex: 1 1 100%;
  }

  /* La section favoris n'est plus sticky sur mobile - ça bouffait tout l'écran */
  #section-favoris {
    position: static;
  }

  /* Sur mobile, 2 colonnes max pour éviter les cartes trop petites */
  #bloc-resultats > * {
    flex: 1 1 calc(50% - 10px);
    max-width: calc(50% - 10px);
  }
}
