/* ========== RESET & BASE ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: system-ui, sans-serif;
  background-color: #f9f9f9;
  color: #333;
  line-height: 1.6;
  padding: 1rem;
}

a {
  color: #0077cc;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ========== TITRES ========== */
h1 {
  font-size: 2rem;
  margin-bottom: 1rem;
  text-align: center;
}

h2 {
  margin-top: 2rem;
  font-size: 1.5rem;
}

/* ========== FILTRES & TRI ========== */
.filters,
.sorts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 1rem 0;
  justify-content: center;
}

.filters button {
  padding: 0.6rem 1.2rem;
  border: none;
  background-color: #ddd;
  border-radius: 20px;
  cursor: pointer;
  transition: background-color 0.3s;
  font-size: 1rem;
}

.filters button:hover {
  background-color: #bbb;
}

.sorts label {
  margin-right: 0.5rem;
}

#sort-select {
  padding: 0.4rem;
  border-radius: 4px;
  border: 1px solid #ccc;
}

/* ========== LISTE DES SORTIES ========== */
#post-list {
  list-style: none;
  display: grid;
  gap: 1rem;
  padding: 0;
  margin: 2rem auto;
  max-width: 900px;
}

.post-item {
  background: white;
  padding: 1rem;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  transition: transform 0.2s;
}

.post-item:hover {
  transform: translateY(-3px);
}

.post-item a {
  font-weight: bold;
  display: block;
  margin-bottom: 0.5rem;
}

/* ========== PAGE DE DÉTAIL (post) ========== */
#map {
  width: 100%;
  height: 400px;
  margin-top: 1rem;
  border-radius: 8px;
  box-shadow: 0 1px 5px rgba(0,0,0,0.1);
}

#elevation-div {
  margin-top: 1rem;
  border-radius: 8px;
  overflow: hidden;
}

/* Infos post */
body > p {
  margin-bottom: 0.6rem;
}

/* Contenu du post */
div > img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}

/* Galerie photos */
div.photos,
div > .photos {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

img {
  max-width: 100%;
  border-radius: 6px;
}

/* ========== FOOTER OU LIENS ========== */
footer, .back-link {
  text-align: center;
  margin-top: 2rem;
  font-size: 0.9rem;
  color: #777;
}

/* Cartes de sortie */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-top: 2rem;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
  padding: 0 1rem;
  justify-content: center;
}

.card {
  display: flex;
  flex-direction: column;
  background: white;
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  border-left: 6px solid #0077cc;
  max-width: 350px;
  margin: 0 auto;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.card-cover {
  width: 100%;
  height: 200px;
  object-fit: cover;
  display: block;
}

.card-content {
  padding: 1rem;
}

.card-content h2 {
  font-size: 1.1rem;
  margin-bottom: 0.3rem;
}

.card-content p {
  font-size: 0.95rem;
  margin: 0.3rem 0;
}

/* Couleurs de bordures selon sport */
.card[data-sport="trail"] {
  border-left-color: #e07a5f;
}
.card[data-sport="rando"] {
  border-left-color: #81b29a;
}
.card[data-sport="vtt"] {
  border-left-color: #3d405b;
}
.card[data-sport="route"] {
  border-left-color: #f2cc8f;
}
.card[data-sport="gravel"] {
  border-left-color: #3696bd;
}
.card[data-sport="co"] {
  border-left-color: #9c6644;
}

.card,
.card:hover,
.card h2,
.card:hover h2 {
  text-decoration: none;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin: 1.5rem 0;
}

.filters button {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 20px;
  background-color: #eee;
  cursor: pointer;
  font-size: 0.95rem;
  transition: background-color 0.2s ease;
}

.filters button:hover,
.filters button.active {
  background-color: #0077cc;
  color: white;
}

.post-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem;
}

.post-header h1 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  text-align: center;
}

.post-meta {
  text-align: center;
  color: #666;
  margin-bottom: 1.5rem;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.8rem;
  margin: 1rem 0 2rem;
  padding: 0;
  list-style: none;
}

.info-grid li {
  background: #fff;
  padding: 0.8rem 1rem;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  font-size: 0.95rem;
}

.post-map #map {
  width: 100%;
  height: 400px;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  margin-bottom: 1rem;
}

#elevation-div {
  height: 200px;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.post-content {
  line-height: 1.7;
  font-size: 1rem;
  margin-bottom: 2rem;
  text-align: justify;
  text-justify: inter-word;
}

.post-photos h2 {
  font-size: 1.4rem;
  margin-bottom: 1rem;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.photo-grid img {
  width: 100%;
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 1px 6px rgba(0,0,0,0.1);
}

.back-link {
  text-align: center;
  margin-top: 2rem;
}

.post-top-nav {
  max-width: 900px;
  margin: 1rem auto 0;
  padding: 0 1rem;
  text-align: left;
}

.home-link {
  display: inline-block;
  color: #0077cc;
  text-decoration: none;
  font-size: 0.95rem;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  transition: background-color 0.2s ease;
}

.home-link:hover {
  background-color: #e6f0fa;
}

.search-bar {
  max-width: 500px;
  margin: 1.5rem auto;
  text-align: center;
}

#search-input {
  width: 100%;
  padding: 0.6rem 1rem;
  font-size: 1rem;
  border: 1px solid #ccc;
  border-radius: 25px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  outline: none;
  transition: border-color 0.2s ease;
}

#search-input:focus {
  border-color: #0077cc;
}

.post-item {
  transition: all 0.2s ease;
}

/* ========== RESPONSIVE AMÉLIORÉ ========== */
@media (max-width: 900px) {
  .cards {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  }

  .card {
    max-width: 100%;
  }

  #map {
    height: 300px;
  }
}

@media (max-width: 600px) {
  h1 {
    font-size: 1.5rem;
  }

  .filters,
  .sorts {
    flex-direction: column;
    align-items: center;
  }

  .filters button {
    width: 100%;
    max-width: 250px;
  }

  #post-list {
    padding: 0;
    margin: 1rem;
  }

  #map,
  #elevation-div {
    height: 250px;
  }

  .card-cover {
    height: 160px;
  }

  .photo-grid {
    grid-template-columns: 1fr;
  }
}

/* ========== MODE SOMBRE ========== */
@media (prefers-color-scheme: dark) {
  body {
    background-color: #121212;
    color: #eee;
  }

  a {
    color: #4dabf7;
  }

  a:hover {
    color: #82cfff;
  }

  .filters button {
    background-color: #2a2a2a;
    color: #eee;
  }

  .filters button:hover,
  .filters button.active {
    background-color: #4dabf7;
    color: #fff;
  }

  .sorts label {
    color: #ccc;
  }

  #sort-select {
    background-color: #1e1e1e;
    color: #eee;
    border: 1px solid #444;
  }

  .post-item {
    background: #1e1e1e;
    color: #eee;
    box-shadow: 0 1px 4px rgba(255,255,255,0.05);
  }

  .card {
    background: #1e1e1e;
    color: #eee;
    border-left-color: #4dabf7; /* couleur neutre si sport non défini */
    box-shadow: 0 2px 6px rgba(0,0,0,0.6);
  }

  .card-content h2 {
    color: #fff;
  }

  .info-grid li {
    background: #1e1e1e;
    color: #ddd;
    box-shadow: 0 1px 4px rgba(255,255,255,0.05);
  }

  .post-meta {
    color: #aaa;
  }

  .home-link {
    color: #4dabf7;
  }

  .home-link:hover {
    background-color: #1a3a5f;
  }

  #search-input {
    background-color: #1e1e1e;
    color: #eee;
    border: 1px solid #444;
  }

  #search-input:focus {
    border-color: #4dabf7;
  }

  #map {
    border: 2px solid #333;
  }

  #elevation-div {
    background: #1a1a1a;
  }

  footer, .back-link {
    color: #888;
  }
}


.difficulty {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.3rem;
}

.difficulty .leg-icon {
  color: #e07a5f; /* couleur par défaut (ex: orange) */
}

/* option : varier la couleur selon difficulté */
.card[data-difficulte="1"] .leg-icon { color: #81b29a; } /* vert facile */
.card[data-difficulte="2"] .leg-icon { color: #f2cc8f; } /* jaune moyen */
.card[data-difficulte="3"] .leg-icon { color: #e07a5f; } /* orange dur */
.card[data-difficulte="4"] .leg-icon { color: #d62828; } /* rouge très dur */


/* ======= MOBILE FIRST OPTIMISATIONS ======= */

/* Boutons filtres scrollables sur mobile */
@media (max-width: 768px) {
  .filters {
    display: flex;
    overflow-x: auto;
    gap: 0.6rem;
    padding: 0.5rem 0;
    scrollbar-width: none; /* Firefox */
  }
  .filters::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
  }
  .filters button {
    flex: 0 0 auto;
    padding: 0.6rem 1rem;
    font-size: 0.95rem;
  }
}

/* Cards plus compactes sur petits écrans */
@media (max-width: 768px) {
  .cards {
    grid-template-columns: 1fr; /* 1 carte par ligne */
    gap: 1rem;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;   /* centre horizontalement */
  }

  .card-cover {
    height: 160px; /* moins haut que desktop */
    object-fit: cover;
  }

  .card-content h2 {
    font-size: 1rem;
  }

  .card-content p {
    font-size: 0.9rem;
  }

  .card {
    width: 100%;
    max-width: 300px;      /* largeur max fixe */
  }
}

/* Carte Leaflet plus adaptée au mobile */
@media (max-width: 768px) {
  #map {
    height: 60vh; /* prend une partie de l'écran */
  }
  #elevation-div {
    height: 180px;
  }
}

/* Titre et texte */
@media (max-width: 480px) {
  h1 {
    font-size: 1.4rem;
  }
  .post-header h1 {
    font-size: 1.6rem;
  }
  body {
    font-size: 0.95rem;
    padding: 0.5rem;
  }
}


/* Bouton retour en haut */
#back-to-top {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background-color: #0077cc;
  color: white;
  border: none;
  border-radius: 50%;
  width: 45px;
  height: 45px;
  font-size: 1.2rem;
  cursor: pointer;
  display: none; /* caché par défaut */
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  transition: opacity 0.3s ease, transform 0.2s ease;
  z-index: 999;
}

#back-to-top:hover {
  background-color: #005fa3;
  transform: translateY(-3px);
}

/* Mode sombre */
body.dark-mode #back-to-top {
  background-color: #444;
}

body.dark-mode #back-to-top:hover {
  background-color: #222;
}