/* ---------- Layout global (allégé) ---------- */

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  margin: 0;
  padding: 2rem;
  min-height: 100vh;
  background: radial-gradient(circle at top, #1d4ed8 0, #020617 45%, #020617 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Conteneur principal */
.app {
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  background: #ffffff;
  border-radius: 18px;
  padding: 1.8rem 2.2rem 2rem;
  box-shadow:
    0 10px 24px rgba(15, 23, 42, 0.22),
    0 0 0 1px rgba(15, 23, 42, 0.04);
  animation: cardIn 0.25s ease-out both;
}

/* ---------- Header / Hero ---------- */

.hero {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.3rem;
}

.hero-icon {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 30% 20%, #f97316, #c026d3);
  font-size: 1.6rem;
  color: #f9fafb;
  box-shadow: 0 8px 18px rgba(148, 27, 186, 0.3);
}

h1 {
  margin: 0 0 0.2rem;
  font-size: 1.6rem;
  letter-spacing: 0.02em;
  color: #020617;
}

.hero-subtitle {
  margin: 0;
  font-size: 0.95rem;
  color: #4b5563;
}

/* ---------- Formulaire ---------- */

.search-form {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
  flex-wrap: wrap; /* Permet de passer à la ligne sur mobile */
  align-items: center; /* Aligne verticalement tous les éléments */
}

/* Le conteneur du champ principal (Numéro ou Gare) doit prendre l'espace restant */
.search-group {
  flex: 1;
  min-width: 200px; /* Évite qu'il ne s'écrase trop */
  display: flex; /* Assure que son contenu (inputs-group) s'étire */
}

/* Groupe pour coller les inputs ensemble si besoin */
.inputs-group {
  display: flex;
  gap: 0.6rem;
  flex: 1;
  width: 100%; /* S'assure de remplir le search-group */
}

/* Styles communs pour tous les champs de saisie */
input[type="text"],
input[type="date"],
input[type="time"],
select {
  padding: 0.7rem 0.9rem;
  font-size: 1rem;
  border-radius: 10px;
  border: 1px solid #d1d5db;
  background: #f9fafb;
  font-family: inherit;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    background 0.15s ease;
  height: 48px; /* Force une hauteur identique pour tous */
  box-sizing: border-box; /* Important pour inclure padding/border dans la hauteur */
}

/* Spécificités par type d'input */
input[type="text"] {
  flex: 1; /* Prend tout l'espace dans son groupe */
  width: 100%;
}

input[type="date"] {
  flex: 0 0 auto;
  width: 150px;
  color: #374151;
}

input[type="time"] {
  flex: 0 0 auto;
  width: 110px;
  color: #374151;
}

select {
  flex: 0 0 auto;
  width: auto;
  min-width: 110px;
  cursor: pointer;
}

input:focus,
select:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
  background: #ffffff;
}

/* Groupe spécifique pour la date et le bouton */
.common-inputs {
  /* margin-top supprimé pour corriger le désalignement vertical */
  margin-top: 0; 
  justify-content: flex-end;
  flex: 0 0 auto; /* Ne prend que la place nécessaire (Date + Btn) */
  min-width: auto;
  width: auto; /* Écrase le width: 100% du .inputs-group générique */
}

button {
  padding: 0.7rem 1.4rem;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.4);
  transition:
    transform 0.1s ease,
    box-shadow 0.1s ease,
    filter 0.1s ease;
  height: 48px; /* Hauteur alignée avec les inputs */
  box-sizing: border-box;
}

button span::after {
  content: "↵";
  font-size: 0.85em;
  opacity: 0.8;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 11px 22px rgba(37, 99, 235, 0.45);
  filter: brightness(1.03);
}

button:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 7px 14px rgba(37, 99, 235, 0.38);
}

button:disabled {
  opacity: 0.65;
  cursor: default;
  box-shadow: none;
}

/* ---------- Status / erreurs ---------- */

.status {
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  min-height: 1.1em;
  color: #4b5563;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.status--loading::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid #2563eb;
  border-right-color: transparent;
  animation: spin 0.6s linear infinite;
}

.status--error {
  color: #b91c1c;
}

.status--error::before {
  content: "⚠️";
}

/* ---------- Résultat global ---------- */

.text-delayed {
  color: #dc2626;
  font-weight: 700;
}

.result {
  margin-top: 0.25rem;
}

.train-info {
  border-top: 1px solid #e5e7eb;
  padding-top: 1rem;
  margin-top: 0.5rem;
}

.train-info--enter {
  animation: fadeInUp 0.5s ease-out both;
}

.tag {
  display: inline-block;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  background: #e5f0ff;
  color: #1d4ed8;
  margin-right: 0.35rem;
  margin-bottom: 0.25rem;
  font-weight: 500;
}

.empty-state {
  margin-top: 0.6rem;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  background: #f9fafb;
  border: 1px dashed #e5e7eb;
  font-size: 0.9rem;
  color: #4b5563;
}

/* ---------- Tableau des gares ---------- */

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.75rem;
  font-size: 0.9rem;
  border-radius: 10px;
  overflow: hidden;
}

th,
td {
  padding: 0.45rem 0.4rem;
  border-bottom: 1px solid #e5e7eb;
  text-align: left;
}

th {
  font-weight: 600;
  background: #f9fafb;
}

tbody tr:nth-child(even) {
  background: #f9fafb;
}

tbody tr:hover {
  background: #eef2ff;
}

/* ---------- Carte + timeline ---------- */

.visualizations {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.map-container {
  flex: 1 1 320px;
  min-width: 280px;
}

.timeline-container {
  flex: 1 1 320px;
  min-width: 280px;
}

.map-container h3,
.timeline-container h3 {
  margin-top: 0;
}

.map {
  width: 100%;
  height: 320px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.02);
}

.map--empty {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1.5rem;
  color: #6b7280;
  background: #f9fafb;
  border: 1px dashed #d1d5db;
}

.map--empty p {
  margin: 0;
}

/* ---------- Timeline horizontale ---------- */

:root {
  --dot-size: 22px;
  --line-height: 6px;
}

/* Conteneur global */
.timeline {
  margin: 2rem 0 0;
  overflow-x: auto;
  padding-bottom: 1rem;
}

/* Ligne + stations */
.timeline-inner {
  position: relative;
  display: flex;
  align-items: flex-start;
  min-width: max-content;
  padding: 2rem 0 0.5rem;
}

/* Une station */
.timeline-stop {
  position: relative;
  flex: 1 1 0;
  text-align: center;
  padding: 0 2.2rem;
  z-index: 1;
}

/* Ligne gauche */
.timeline-stop::before {
  content: "";
  position: absolute;
  top: calc(var(--dot-size) / 2 - var(--line-height) / 2);
  left: 0;
  right: 50%;
  height: var(--line-height);
  background: #6b21a8;
  z-index: -1;
}

/* Ligne droite */
.timeline-stop::after {
  content: "";
  position: absolute;
  top: calc(var(--dot-size) / 2 - var(--line-height) / 2);
  left: 50%;
  right: 0;
  height: var(--line-height);
  background: #6b21a8;
  z-index: -1;
}

/* On coupe avant/après */
.timeline-stop:first-child::before {
  content: none;
}
.timeline-stop:last-child::after {
  content: none;
}

/* Pastille */
.timeline-stop-dot {
  width: var(--dot-size);
  height: var(--dot-size);
  margin: 0 auto 0.75rem;
  border-radius: 50%;
  background: #ffffff;
  border: 4px solid #6b21a8;
}

/* Départ / Arrivée */
.timeline-stop--start .timeline-stop-dot,
.timeline-stop--end .timeline-stop-dot {
  border-color: #dc2626;
}

/* Nom de la gare */
.timeline-stop-name {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

/* Horaires */
.timeline-stop-time {
  font-size: 0.75rem;
  color: #4b5563;
  line-height: 1.2;
}

/* ---------- Historique ---------- */

.search-history {
  margin-bottom: 0.6rem;
}

.history-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6b7280;
  margin-bottom: 0.2rem;
}

.history-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.history-item {
  border: none;
  border-radius: 999px;
  box-shadow: none;
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
  background: #eef2ff;
  color: #4338ca;
  cursor: pointer;
  transition:
    background 0.12s ease,
    transform 0.08s ease;
}

.history-item:hover {
  background: #e0e7ff;
  transform: translateY(-1px);
}

.history-item:active {
  transform: translateY(0);
}

/* --- Navigation --- */

.tabs {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  border-bottom: 2px solid #e5e7eb;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 0.5rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  color: #6b7280;
  cursor: pointer;
  box-shadow: none;
  border-radius: 0;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: #2563eb;
  transform: none;
  box-shadow: none;
}

.tab-btn.active {
  color: #2563eb;
  border-bottom-color: #2563eb;
}

/* --- Autocomplétion Gare --- */
.autocomplete-wrapper {
  position: relative;
  flex: 2;
  /* flex: 2 pour qu'il prenne plus de place que le select/heure */
}

.suggestions-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid #d1d5db;
  border-radius: 0 0 10px 10px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 10;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  display: none;
}

.suggestion-item {
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  font-size: 0.95rem;
  border-bottom: 1px solid #f3f4f6;
}

.suggestion-item:hover {
  background: #f3f4f6;
}

/* --- Tableau des résultats (Board) --- */
.board-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

.board-table th {
  background: #f1f5f9;
  text-align: left;
  padding: 0.8rem;
  font-size: 0.9rem;
}

.board-table td {
  padding: 0.8rem;
  border-bottom: 1px solid #e2e8f0;
  font-size: 0.95rem;
}

.board-row {
  cursor: pointer;
  transition: background 0.1s;
}

.board-row:hover {
  background-color: #eff6ff;
}

.time-cell {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: #1e293b;
}

.delay-badge {
  background: #fee2e2;
  color: #991b1b;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  margin-left: 0.5rem;
  font-weight: bold;
}

.mode-badge {
  background: #e0e7ff;
  color: #3730a3;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
}

.type-badge {
  background: #fddddd;
  color: #c90404;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
}

.station-link{
  cursor: pointer;
  transition: background 0.1s;
}

.station-link:hover {
  background-color: #eff6ff;
}

/* ---------- Responsif ---------- */

@media (max-width: 640px) {
  body {
    padding: 1rem;
  }

  .app {
    padding: 1.3rem 1.1rem 1.4rem;
    border-radius: 14px;
  }

  .hero {
    align-items: flex-start;
  }

  h1 {
    font-size: 1.35rem;
  }

  .search-form {
    align-items: stretch; /* Sur mobile, on étire tout */
  }

  .inputs-group {
    flex-wrap: wrap;
  }

  .search-group {
    min-width: 100%;
  }
  
  /* Sur mobile, on remet tout en pleine largeur */
  input[type="text"],
  input[type="date"],
  input[type="time"],
  select {
    width: 100%;
    flex: 1 1 100%;
  }

  .common-inputs {
    width: 100%;
    justify-content: space-between; /* Bouton et date séparés */
    margin-top: 0.6rem; /* On remet la marge sur mobile uniquement */
  }

  button {
    width: 100%;
    justify-content: center;
  }
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}