:root {
  --fond: #f4f6fa;
  --carte: #ffffff;
  --texte: #1c2333;
  --texte-doux: #5a6478;
  --accent: #2b6cb0;
  --bordure: #e2e7f0;
  --zebre: #f8fafd;
}

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

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--fond);
  color: var(--texte);
  line-height: 1.5;
}

.container {
  max-width: 1024px;
  margin: 0 auto;
  padding: 2rem 1rem 1rem;
}

h1 {
  font-size: 1.8rem;
  margin-bottom: 0.25rem;
}

.subtitle {
  color: var(--texte-doux);
  margin-bottom: 1.5rem;
}

.carte {
  background: var(--carte);
  border: 1px solid var(--bordure);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 1px 3px rgba(15, 30, 70, 0.06);
}

.carte h2 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
  color: var(--accent);
}

/* Moyenne de groupe */
.groupe-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1rem;
}

.stat {
  background: var(--zebre);
  border: 1px solid var(--bordure);
  border-radius: 8px;
  padding: 0.75rem;
  text-align: center;
}

.stat .libelle {
  display: block;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--texte-doux);
  margin-bottom: 0.25rem;
}

.stat .valeur {
  font-size: 1.5rem;
  font-weight: 700;
}

.stat .ecart {
  display: block;
  font-size: 0.72rem;
  color: var(--texte-doux);
  margin-top: 0.15rem;
}

.stat.gagnant .ecart {
  color: #1e6f3c;
}

/* Tableau */
.tableau-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th, td {
  padding: 0.6rem 0.75rem;
  text-align: right;
  border-bottom: 1px solid var(--bordure);
  white-space: nowrap;
}

th:first-child, td:first-child {
  text-align: left;
}

#tableau th:nth-child(2), #tableau td:nth-child(2) {
  text-align: left;
}

thead th {
  background: var(--zebre);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

thead th:hover {
  color: var(--accent);
}

tbody tr:nth-child(even) {
  background: var(--zebre);
}

/* Barres dans les cellules */
td .barre {
  display: inline-block;
  vertical-align: middle;
  height: 8px;
  border-radius: 4px;
  background: var(--accent);
  margin-right: 0.5rem;
}

/* Participation incohérente (somme des partis ≠ participation) */
td.incoherent {
  background: #fdecea;
  color: #9c2b22;
  font-weight: 700;
}

/* Mise en évidence du parti gagnant */
td.gagnant {
  background: #e6f4ea;
  font-weight: 700;
  color: #1e6f3c;
}

td.gagnant .barre {
  background: #2f9e5b;
}

.stat.gagnant {
  background: #e6f4ea;
  border-color: #2f9e5b;
  color: #1e6f3c;
}

.stat.gagnant .valeur {
  color: #1e6f3c;
}

.stat.gagnant .libelle {
  color: #1e6f3c;
}

.badge {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #ffffff;
  background: #2f9e5b;
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  margin-bottom: 0.35rem;
}

.erreur {
  background: #fdecea;
  border: 1px solid #f5c6c0;
  color: #9c2b22;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
}

.hidden {
  display: none;
}

/* Bouton résultats — bas droite */
.btn-resultats {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  background: var(--accent);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(15, 30, 70, 0.25);
  user-select: none;
  z-index: 10;
}

.btn-resultats:hover {
  filter: brightness(1.1);
}

/* Modale */
.modale-fond {
  position: fixed;
  inset: 0;
  background: rgba(20, 28, 45, 0.55);
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 1rem;
}

.modale-fond:not(.hidden) {
  display: flex;
}

.modale {
  background: var(--carte);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 560px;
  width: 100%;
  box-shadow: 0 8px 30px rgba(15, 30, 70, 0.3);
}

.modale h2 {
  font-size: 1.1rem;
  margin-bottom: 0.25rem;
}

.modale-note {
  color: var(--texte-doux);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.champs-resultats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.champs-resultats label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.champs-resultats input {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--bordure);
  border-radius: 6px;
  font: inherit;
}

.modale-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn {
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--bordure);
  border-radius: 8px;
  background: var(--zebre);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn-primaire {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Section résultats */
.prophete {
  margin-bottom: 1rem;
  font-size: 1.05rem;
}

.somme-ecarts {
  color: var(--texte-doux);
  font-size: 0.85rem;
}

.detail-ecarts {
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: var(--texte-doux);
}

/* Pied de page — méthode */
.pied-page {
  max-width: 1024px;
  margin: 0.5rem auto 0;
  padding: 0.5rem 1rem 1rem;
  border-top: 1px solid var(--bordure);
  color: var(--texte-doux);
  font-size: 0.85rem;
}

.pied-page h3 {
  font-size: 0.95rem;
  color: var(--texte);
  margin-bottom: 0.5rem;
}

.pied-page ol {
  margin: 0.5rem 0 0 1.25rem;
}

.pied-page li {
  margin-bottom: 0.3rem;
}

.note-ecarts {
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--texte-doux);
  font-style: italic;
}

/* Écarts dans le tableau principal */
td .ecart {
  display: block;
  font-size: 0.72rem;
  color: var(--texte-doux);
  margin-top: 0.1rem;
}

td.plus-proche {
  box-shadow: inset 0 0 0 2px #2f9e5b;
  border-radius: 4px;
}

td.plus-proche .ecart {
  color: #1e6f3c;
  font-weight: 700;
}

td.somme-ecarts-cell {
  font-weight: 700;
}

td.somme-ecarts-cell.gagnant {
  background: #e6f4ea;
  color: #1e6f3c;
}

td.numero-position {
  font-weight: 700;
  color: var(--texte-doux);
  text-align: right;
  width: 2rem;
}

tr.prophete td:first-child {
  font-weight: 700;
}

.etoile {
  color: #d4a017;
  font-size: 0.9rem;
}

.ecart-groupe {
  margin-top: 1rem;
  color: var(--texte-doux);
}

/* Tableau des résultats réels */
.tableau-resultats {
  margin-top: 1rem;
}

.tableau-resultats td {
  font-weight: 700;
  font-size: 1.05rem;
}

.tableau-resultats td.gagnant {
  background: #e6f4ea;
  color: #1e6f3c;
}
