:root {
  --gold: #c9a227;
  --gold-deep: #8a6d0f;
  --gold-soft: #f3e3a8;
  --gold-tint: #fdf8e7;
  --ink: #111113;
  --ink-soft: #3f3f46;
  --muted: #71717a;
  --faint: #a1a1aa;
  --line: #e6e6e3;
  --line-soft: #f1f1ee;
  --surface: #fff;
  --ground: #fafaf8;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(17, 17, 19, .05);
  --shadow: 0 1px 3px rgba(17, 17, 19, .06), 0 8px 24px -8px rgba(17, 17, 19, .10);
  --shadow-lg: 0 24px 64px -16px rgba(17, 17, 19, .28);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 400 16px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; }
::selection { background: var(--gold-soft); }

:where(a, button, input, select, [tabindex]):focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- Header ---------- */
/* Fond plein plutôt que flouté : le flou se recalcule à chaque défilement et
   sollicite fortement la carte graphique sur les ordinateurs modestes. */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.header-inner {
  max-width: 1400px; margin: 0 auto;
  padding: 0 24px;
  display: flex; align-items: center; gap: 36px;
  height: 62px;
}
.logo { display: flex; align-items: center; text-decoration: none; }
.logo img {
  height: 32px; width: auto; display: block;
}
.nav { display: flex; gap: 28px; flex: 1; height: 100%; }
.nav a {
  display: flex; align-items: center;
  text-decoration: none;
  color: var(--muted);
  font-size: 14.5px; font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color .15s;
}
.nav a:hover { color: var(--ink); }
.nav a[aria-current="page"] { color: var(--gold-deep); border-bottom-color: var(--gold); }

/* ---------- Layout ---------- */
.page { max-width: 1400px; margin: 0 auto; padding: 36px 24px 72px; }
.page-head {
  display: flex; align-items: center; gap: 14px;
  flex-wrap: wrap; margin-bottom: 24px;
}
h1 {
  font-size: 30px; font-weight: 700;
  letter-spacing: -.028em; line-height: 1.2;
  margin: 0;
}

.search { margin-left: auto; position: relative; }
.search input {
  width: 320px; max-width: 100%;
  padding: 10px 14px 10px 38px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font: inherit; font-size: 14.5px;
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.search input::placeholder { color: var(--faint); }
.search input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-tint);
}
.search::before {
  content: "";
  position: absolute; left: 13px; top: 50%;
  width: 15px; height: 15px;
  transform: translateY(-50%);
  background: currentColor; color: var(--faint);
  -webkit-mask: var(--icon-search) center/contain no-repeat;
  mask: var(--icon-search) center/contain no-repeat;
}
:root {
  --icon-search: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.5' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
}

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  font: inherit; font-size: 14px; font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: background .15s, border-color .15s, transform .08s;
}
.btn:hover { background: var(--ground); border-color: #d8d8d4; }
.btn:active { transform: translateY(1px); }
.btn-gold {
  background: var(--gold-soft); border-color: transparent;
  color: var(--gold-deep); font-weight: 600;
}
.btn-gold:hover { background: #ecd88f; border-color: transparent; }
.btn-ghost { border-color: transparent; background: transparent; box-shadow: none; color: var(--muted); }
.btn-ghost:hover { background: var(--line-soft); color: var(--ink); }
.btn-danger { color: #b3454f; border-color: #f0d4d7; }
.btn-danger:hover { background: #fdeced; border-color: #e8bfc4; }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Onglets ---------- */
.tabs {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: #f0f0ed; border-radius: 10px;
  padding: 4px; margin-bottom: 20px;
  max-width: 460px;
}
.tabs button {
  border: 0; background: transparent;
  padding: 9px; border-radius: 7px;
  font: inherit; font-size: 14px; font-weight: 500;
  color: var(--muted); cursor: pointer;
  transition: background .15s, color .15s;
}
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] {
  background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-sm); font-weight: 600;
}

/* ---------- Tableaux ---------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left;
  font-size: 12px; font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase;
  color: var(--faint);
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  background: var(--surface);
}
td { padding: 13px 16px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
.row-main { transition: background .12s; }
.row-main:hover { background: #fcfcfa; }
.cell-name { font-weight: 550; letter-spacing: -.01em; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Ligne dépliable */
.row-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px;
  border: 0; border-radius: 7px;
  background: transparent; color: var(--faint);
  cursor: pointer;
  transition: background .15s, color .15s, transform .18s;
}
.row-toggle:hover { background: var(--line-soft); color: var(--ink); }
.row-toggle[aria-expanded="true"] { transform: rotate(90deg); color: var(--gold-deep); }
.row-detail > td { padding: 0; background: #fcfcfa; border-bottom: 1px solid var(--line); }
.detail-inner { padding: 18px 20px 22px 46px; }
.detail-title {
  font-size: 12px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--faint);
  margin: 0 0 12px;
}
/* Le nom occupe sa propre ligne, en entier ; statut, distance et action se
   rangent dessous. Toutes les cartes d'une rangée gardent la même hauteur. */
.participants {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}
.participant {
  display: flex; flex-direction: column; gap: 7px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 13.5px;
}
.participant-nom { font-weight: 550; line-height: 1.3; overflow-wrap: anywhere; }
.participant-infos { display: flex; align-items: center; gap: 6px; margin-top: auto; }
.participant-infos .btn { margin-left: auto; }

/* Dans le tableau, la bande des participants reste calée sur la largeur visible et
   défile seule, sur deux rangées : elle ne suit plus le défilement du tableau. */
.table-events .detail-inner {
  position: sticky; left: 0;
  width: var(--largeur-visible, 100%);
}
.table-events .participants {
  grid-template-columns: none;
  grid-auto-flow: column;
  grid-template-rows: repeat(2, auto);
  grid-auto-columns: 230px;
  overflow-x: auto;
  padding-bottom: 8px;
  scroll-snap-type: x proximity;
}
.table-events .participant { scroll-snap-align: start; }

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

/* ---------- Vue téléphone : une carte par course ---------- */
.cartes { display: grid; gap: 12px; }
.carte {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: grid; gap: 10px;
  min-width: 0;
}
.carte-haut, .carte-bas { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.carte-date { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.carte-nom { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -.015em; line-height: 1.25; overflow-wrap: anywhere; }
.carte-lieu { margin: -6px 0 0; font-size: 13px; color: var(--muted); }
.carte-actions { display: grid; grid-template-columns: 1fr; gap: 8px; }
.carte-actions.avec-modifier { grid-template-columns: 1fr auto; }
.carte-actions .btn { justify-content: center; }
.carte-toggle {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 10px 2px 0;
  border: 0; border-top: 1px solid var(--line-soft); background: transparent;
  font: inherit; font-size: 13.5px; font-weight: 500; color: var(--ink-soft); cursor: pointer;
}
.carte-toggle svg { transition: transform .18s; }
.carte-toggle[aria-expanded="true"] svg { transform: rotate(90deg); color: var(--gold-deep); }
.carte-parts { display: grid; gap: 6px; }
.carte-part {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; background: var(--ground); border-radius: 8px; font-size: 13.5px;
}
.carte-part-nom { flex: 1; min-width: 0; font-weight: 550; overflow-wrap: anywhere; }
.carte-part .moi { color: var(--faint); font-weight: 400; }

/* ---------- Filtres des traces ---------- */
.filtres { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 28px; margin-bottom: 18px; }
.filtre-groupe { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.filtre-titre {
  font-size: 12px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--faint);
}
.filtre-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-filtre {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink-soft);
  font: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.chip-filtre:hover:not(:disabled) { background: var(--ground); border-color: #d8d8d4; }
.chip-filtre[aria-pressed="true"] {
  background: var(--gold-soft); border-color: transparent; color: var(--gold-deep); font-weight: 600;
}
.chip-filtre:disabled { opacity: .45; cursor: default; }
.chip-n { font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.chip-filtre[aria-pressed="true"] .chip-n { color: var(--gold-deep); }

/* Libellés longs sur ordinateur, courts sur téléphone. */
.lib-court { display: none; }
@media (max-width: 719px) {
  .lib-long { display: none; }
  .lib-court { display: inline; }
  /* Les filtres restent accessibles pendant le défilement des cartes. */
  .tabs { position: sticky; top: 62px; z-index: 20; }
  .filtres { gap: 12px; }
  .filtre-groupe { width: 100%; }
  .filtre-titre { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .carte-toggle svg, .row-toggle { transition: none; }
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 12.5px; font-weight: 500;
  border: 1px solid var(--line);
  background: var(--ground);
  color: var(--ink-soft);
  white-space: nowrap;
}
.badge-type      { background: #eef1fe; border-color: #dde3fc; color: #4150b5; }
.badge-trail     { background: #e8f4ea; border-color: #cbe5d0; color: #2c6b3a; }
.badge-route     { background: #eaf1fd; border-color: #d2e1fa; color: #2f5fb3; }
.badge-autres    { background: #f4effb; border-color: #e5dbf5; color: #6b4fa8; }
.badge-offtrace  { background: #fdeced; border-color: #f8d6d9; color: #b3454f; }
.badge-officielle{ background: #e6f6f4; border-color: #cdeae6; color: #1f7a6d; }
.badge-autre     { background: #f3f0fb; border-color: #e6e0f6; color: #6b51b5; }
.badge-loop      { background: #eef4ff; border-color: #dce7fb; color: #3a63b8; }
.badge-inscrit   { background: #e8f6ed; border-color: #cfe9d9; color: #1d7a45; }
.badge-chaud     { background: #fff3e6; border-color: #fadfc4; color: #b06a16; }
.badge-peutetre  { background: #f2f2f0; border-color: #e3e3e0; color: #5c5c58; }
.badge-indispo   { background: #fdeced; border-color: #f8d6d9; color: #b3454f; }
.badge-aconfirmer{ background: var(--gold-tint); border-color: var(--gold-soft); color: var(--gold-deep); }
.badges { display: flex; gap: 5px; flex-wrap: wrap; }

/* Tout sur une seule ligne : les lignes gardent une hauteur identique et le tableau
   défile horizontalement, la colonne du nom restant figée à gauche. */
.table-events { width: max-content; min-width: 100%; }
.table-events th, .table-events td {
  white-space: nowrap;
  padding: 0 14px;
  height: 56px;
  vertical-align: middle;
}
.table-events th { height: 42px; }
.table-events .badges { gap: 4px; flex-wrap: nowrap; }
.table-events .badge { font-size: 12px; padding: 2.5px 7px; }

.col-nom {
  position: sticky; left: 0; z-index: 2;
  background: var(--surface);
  box-shadow: 1px 0 0 var(--line);
}
thead .col-nom { z-index: 3; }
.row-main:hover .col-nom { background: #fcfcfa; }

.nom-cell { display: flex; align-items: center; gap: 6px; }
.nom-cell .cell-name { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.row-toggle-vide { width: 26px; flex-shrink: 0; }

/* La ligne dépliée occupe toute la largeur, sans contrainte de hauteur. */
.row-detail > td { white-space: normal; height: auto; padding: 0; }

.counts { display: flex; gap: 9px; align-items: center; white-space: nowrap; font-variant-numeric: tabular-nums; }
.counts span { display: inline-flex; align-items: center; gap: 3px; }

/* Icônes Strava / GPX */
.icon-link {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px;
  border-radius: 8px;
  color: var(--gold); text-decoration: none;
  transition: background .15s;
}
.icon-link:hover { background: var(--gold-tint); }
.icon-link.is-off { color: #d8d8d4; cursor: not-allowed; }
.icon-link.is-off:hover { background: transparent; }

/* ---------- États ---------- */
.state { padding: 72px 20px; text-align: center; color: var(--muted); font-size: 14.5px; }
.spinner {
  width: 26px; height: 26px;
  border: 2.5px solid var(--line);
  border-top-color: var(--gold);
  border-radius: 50%;
  margin: 0 auto 14px;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-box {
  background: #fdeced; border: 1px solid #f8d6d9;
  color: #a03440; padding: 12px 15px;
  border-radius: 9px; margin-bottom: 16px; font-size: 14px;
}
.result-count { margin-top: 14px; color: var(--faint); font-size: 13.5px; }

/* ---------- Modale ---------- */
dialog {
  border: 0; border-radius: 16px; padding: 0;
  max-width: 560px; width: calc(100% - 32px);
  box-shadow: var(--shadow-lg);
  color: var(--ink);
  font: inherit;
}
dialog::backdrop { background: rgba(17, 17, 19, .5); }
.modal-head {
  padding: 22px 24px 4px;
  display: flex; align-items: flex-start; gap: 12px;
}
.modal-head h2 { margin: 0; font-size: 19px; font-weight: 650; letter-spacing: -.02em; flex: 1; }
.modal-sub { color: var(--muted); font-size: 13.5px; margin: 2px 0 0; }
.modal-body { padding: 18px 24px; max-height: 65vh; overflow-y: auto; }
.modal-foot {
  padding: 16px 24px 22px;
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  border-top: 1px solid var(--line-soft);
}
.modal-foot .spacer { margin-left: auto; }

/* Sur téléphone : Annuler / Enregistrer en haut, l'action destructrice isolée dessous. */
@media (max-width: 520px) {
  .modal-foot { padding: 14px 18px 18px; }
  .modal-foot .spacer { display: none; }
  .modal-foot .btn:not(.btn-danger) { flex: 1; justify-content: center; }
  .modal-foot .btn-danger { order: 2; flex-basis: 100%; justify-content: center; }
}

/* ---------- Formulaires ---------- */
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field label {
  display: block; font-size: 13px; font-weight: 500;
  color: var(--ink-soft); margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font: inherit; font-size: 14.5px;
  background: var(--surface);
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-tint);
}
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.hint { font-size: 12.5px; color: var(--faint); margin: 6px 0 0; }
.req { color: #b3454f; }

/* Choix de statut */
.choices { display: grid; gap: 8px; }
.choice {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 13px;
  border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; font-size: 14.5px;
  transition: border-color .15s, background .15s;
}
.choice:hover { background: var(--ground); }
.choice input { width: auto; margin: 0; accent-color: var(--gold); }
.choice:has(input:checked) { border-color: var(--gold); background: var(--gold-tint); }

/* ---------- Footer ---------- */
.footer {
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 26px 24px;
  color: var(--muted); font-size: 13.5px;
}
.footer-inner {
  max-width: 1400px; margin: 0 auto;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.footer-links { margin-left: auto; display: flex; gap: 18px; }
.footer-links a { text-decoration: none; }
.footer-links a:hover { color: var(--gold-deep); }

/* ---------- Écran de connexion ---------- */
/* Tant que la session n'est pas établie, la page est masquée sous l'écran. */
.is-locked > *:not(.gate) { display: none !important; }
.gate {
  position: fixed; inset: 0; z-index: 100;
  background: var(--ground);
  display: grid; place-items: center; padding: 24px;
  overflow-y: auto;
}
.gate-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 36px 32px;
  max-width: 400px; width: 100%;
}
.gate-logo { height: 34px; width: auto; display: block; margin-bottom: 14px; }
.gate-card > p { color: var(--muted); font-size: 14px; margin: 0 0 24px; }

.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--gold-soft);
  color: var(--gold-deep);
  display: grid; place-items: center;
  font-size: 12.5px; font-weight: 700;
  border: 0; cursor: pointer;
  flex-shrink: 0;
}
.avatar:hover { background: #ecd88f; }

.credit {
  max-width: 1400px;
  margin: 14px auto 0;
  color: #b8b8b2;
  font-size: 11.5px;
}

@media (max-width: 680px) {
  .header-inner, .page { padding-left: 16px; padding-right: 16px; }
  .header-inner { gap: 20px; }
  .nav { gap: 18px; }
  h1 { font-size: 25px; }
  .search { margin-left: 0; width: 100%; }
  .search input { width: 100%; }
  .tabs { max-width: none; }
  .field-row { flex-direction: column; gap: 0; }
}
