/* ─── Polices locales ───────────────────────────────────────────────────────── */

@font-face {
  font-display: swap;
  font-family: 'Barlow';
  font-style: normal;
  font-weight: 400;
  src: url('../fonts/barlow-v13-latin-regular.woff2') format('woff2');
}
@font-face {
  font-display: swap;
  font-family: 'Barlow';
  font-style: italic;
  font-weight: 400;
  src: url('../fonts/barlow-v13-latin-italic.woff2') format('woff2');
}
@font-face {
  font-display: swap;
  font-family: 'Barlow';
  font-style: normal;
  font-weight: 500;
  src: url('../fonts/barlow-v13-latin-500.woff2') format('woff2');
}
@font-face {
  font-display: swap;
  font-family: 'Barlow';
  font-style: normal;
  font-weight: 600;
  src: url('../fonts/barlow-v13-latin-600.woff2') format('woff2');
}
@font-face {
  font-display: swap;
  font-family: 'Barlow Condensed';
  font-style: normal;
  font-weight: 400;
  src: url('../fonts/barlow-condensed-v13-latin-regular.woff2') format('woff2');
}
@font-face {
  font-display: swap;
  font-family: 'Barlow Condensed';
  font-style: normal;
  font-weight: 600;
  src: url('../fonts/barlow-condensed-v13-latin-600.woff2') format('woff2');
}
@font-face {
  font-display: swap;
  font-family: 'Barlow Condensed';
  font-style: normal;
  font-weight: 700;
  src: url('../fonts/barlow-condensed-v13-latin-700.woff2') format('woff2');
}
@font-face {
  font-display: swap;
  font-family: 'Barlow Condensed';
  font-style: normal;
  font-weight: 800;
  src: url('../fonts/barlow-condensed-v13-latin-800.woff2') format('woff2');
}

/* ─── Design tokens ──────────────────────────────────────────────────────────
   --co-green / --co-green-dark / --co-gold sont injectés par Django via un
   bloc inline dans base.html (couleurs du club configurables par env var).
   Le reste vit ici : le mode sombre ne fait que redéfinir ces variables. */

:root {
  /* Palette de marque */
  --co-forest:     #0d3320;
  --co-light:      #f4f7f4;
  --co-grey:       #6c757d;
  --co-warn:       #dc3545;
  --co-success:    #1a6b3c;
  --co-accent:     #b3121d;  /* accent « départ » (page horaire, erreurs) */
  --co-accent-2:   #d51f2f;
  --font-display:  'Barlow Condensed', sans-serif;
  --font-body:     'Barlow', sans-serif;

  /* Surfaces */
  --co-bg:         var(--co-light);  /* fond de page */
  --co-surface:    #ffffff;          /* cartes, cellules */
  --co-surface-2:  #f0f7f2;          /* survol, bande alternée teintée */
  --co-surface-3:  #f8f9fa;          /* panneaux subtils */

  /* Texte */
  --co-text:         #1a1a1a;
  --co-text-muted:   var(--co-grey);
  --co-text-deep:    var(--co-forest);  /* texte « vert profond » (titres de poste…) */
  --co-text-accent:  var(--co-green);   /* texte d'accent lisible (temps, liens…) */

  /* Traits */
  --co-border:       #dee2e6;
  --co-border-soft:  #ececec;
  --co-split-border: #d4e8d8;

  /* Ombres */
  --co-shadow:        0 2px 12px rgba(0,0,0,.08);
  --co-shadow-hover:  0 6px 20px rgba(0,0,0,.12);

  /* Rayons */
  --co-radius-sm: 4px;
  --co-radius-md: 8px;
  --co-radius-lg: 12px;

  /* États / sémantique */
  --co-highlight-bg:     #fffbe6;  /* onglet actif, meilleur tronçon */
  --co-highlight-border: #f0c040;
  --co-highlight-text:    #9a6700;
  --co-ok-bg:            #e8f5ed;  /* départ / arrivée, cartes « ok » */
  --co-ok-border:        #a8d8b8;
  --co-ok-text:          #155c30;
  --co-info-bg:          #e8f0fe;  /* podium tronçon */
  --co-info-border:      #b3cff5;
  --co-danger-soft:      #fff8f8;  /* lignes en écart */
  --co-danger-text:      #c0392b;
  --co-track-bg:         rgba(0,0,0,.09); /* piste de progression live */

  /* Médailles */
  --co-medal-gold:   #c9940a;
  --co-medal-silver: #7a8c99;
  --co-medal-bronze: #9c5a27;
}

html[data-theme="dark"] {
  --co-forest:     #0a2010;
  --co-light:      #141a14;
  --co-grey:       #9aabb5;
  --co-success:    #5cc98a;
  --co-accent:     #ff6b74;
  --co-accent-2:   #ff8a90;

  --co-bg:         #141a14;
  --co-surface:    #192118;
  --co-surface-2:  #223022;
  --co-surface-3:  #151d14;

  --co-text:         #dde8dd;
  --co-text-muted:   #9aabb5;
  --co-text-deep:    #8fcfa0;
  --co-text-accent:  #6fcf8f;

  --co-border:       rgba(255,255,255,.1);
  --co-border-soft:  rgba(255,255,255,.06);
  --co-split-border: rgba(255,255,255,.12);

  --co-shadow:        0 2px 12px rgba(0,0,0,.35);
  --co-shadow-hover:  0 6px 20px rgba(0,0,0,.5);

  --co-highlight-bg:     #2a2510;
  --co-highlight-border: var(--co-gold);
  --co-highlight-text:    #f5d76e;
  --co-ok-bg:            #1a2e22;
  --co-ok-border:        #2e5c3a;
  --co-ok-text:          #8fcfa0;
  --co-info-bg:          #1a2440;
  --co-info-border:      #2e4a7a;
  --co-danger-soft:      #241518;
  --co-danger-text:      #e57373;
  --co-track-bg:         rgba(255,255,255,.14);

  --co-medal-gold:   #e8b93a;
  --co-medal-silver: #aebbc5;
  --co-medal-bronze: #d08a4e;
}

/* ─── Base ──────────────────────────────────────────────────────────────────── */

body {
  font-family: var(--font-body);
  background: var(--co-bg);
  color: var(--co-text);
}
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  color: inherit;
}
h1, h2 { font-weight: 800; }
h3 { font-weight: 700; }
h4, h5, h6 { font-weight: 600; }
table { font-variant-numeric: tabular-nums; }

/* Anneau de focus aux couleurs du club (remplace le bleu par défaut) */
.form-control:focus,
.form-select:focus,
.form-control:focus-visible {
  border-color: var(--co-green);
  box-shadow: 0 0 0 .25rem color-mix(in srgb, var(--co-green) 25%, transparent);
}

/* ─── Navbar ────────────────────────────────────────────────────────────────── */

.co-navbar {
  background: var(--co-forest);
  border-bottom: 3px solid var(--co-gold);
  padding: .35rem 0;
}
.co-navbar .navbar-brand {
  font-family: var(--font-display); font-weight: 800;
  font-size: clamp(1.25rem, 1.1rem + .6vw, 1.5rem);
  letter-spacing: 0.03em; color: #fff !important;
}
.co-navbar .navbar-brand img { height: 32px; width: auto; }
.co-navbar .brand-accent { color: var(--co-gold); }
.co-navbar .nav-link {
  color: rgba(255,255,255,.75) !important;
  font-weight: 500; border-radius: var(--co-radius-md);
  padding: .5rem .7rem;
  transition: color .2s, background .2s;
}
.co-navbar .nav-link:hover,
.co-navbar .nav-link.active { color: var(--co-gold) !important; }
.co-navbar .nav-link:hover { background: rgba(255,255,255,.07); }

/* ─── Sélecteur de langue (menu déroulant, à côté du titre du site) ───────── */

.co-lang-switch {
  display: inline-flex;
  align-items: center;
  margin-left: .35rem;
  padding-left: .7rem;
  border-left: 1px solid rgba(255,255,255,.18);
}
/* Déclencheur replié : drapeau de la langue courante + chevron Bootstrap */
.co-lang-switch .co-lang-toggle {
  display: inline-flex;
  align-items: center;
  padding: 3px 6px;
  background: transparent;
  border: 2px solid transparent;
  border-radius: 5px;
  line-height: 1;
  cursor: pointer;
  opacity: .85;
  transition: opacity .15s, border-color .15s, transform .15s;
}
.co-lang-switch .co-lang-toggle img {
  width: 24px; height: 16px;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0,0,0,.3);
}
.co-lang-switch .co-lang-toggle:hover { opacity: 1; transform: translateY(-1px); }
.co-lang-switch .co-lang-toggle:focus-visible {
  opacity: 1;
  outline: 2px solid var(--co-gold);
  outline-offset: 2px;
}
/* Menu ouvert : liseré or autour du déclencheur (comme l'ancien drapeau actif) */
.co-lang-switch .co-lang-toggle.show {
  opacity: 1;
  border-color: var(--co-gold);
}
/* Menu : reprend le thème des dropdowns de la navbar (.co-dropdown) */
.co-lang-switch .co-lang-menu { padding: .4rem 0; min-width: 11.5rem; }
.co-lang-menu .co-lang {
  display: flex;
  align-items: center;
  gap: .65rem;
  width: 100%;
  padding: .45rem 1rem;
  background: transparent;
  border: 0;
  text-align: left;
}
.co-lang-menu .co-lang img {
  width: 24px; height: 16px;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0,0,0,.3);
  flex: none;
}
.co-lang-menu .co-lang span { flex: 1; }
.co-lang-menu .co-lang.active i { color: var(--co-gold); opacity: 1; }

/* ─── Navbar dropdown ───────────────────────────────────────────────────────── */

.co-navbar .dropdown-toggle::after { border-color: rgba(255,255,255,.6); }
.co-navbar .dropdown-toggle:hover::after { border-color: var(--co-gold); }
.co-dropdown {
  background: var(--co-forest); border: 1px solid rgba(255,255,255,.1);
  border-top: 2px solid var(--co-gold); border-radius: 0 0 var(--co-radius-md) var(--co-radius-md);
  padding: .35rem 0; min-width: 13.5rem;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
.co-dropdown .dropdown-item {
  color: rgba(255,255,255,.8); font-weight: 500; font-size: .9rem;
  padding: .55rem 1.1rem; transition: background .15s, color .15s;
}
.co-dropdown .dropdown-item:hover,
.co-dropdown .dropdown-item:focus { background: rgba(255,255,255,.08); color: var(--co-gold); }
.co-dropdown .dropdown-item.active {
  background: rgba(255,255,255,.1); color: var(--co-gold);
}
.co-dropdown .dropdown-item .bi { opacity: .75; }
.co-dropdown .dropdown-divider { border-color: rgba(255,255,255,.1); margin: .25rem 0; }

/* ─── Hero banner ───────────────────────────────────────────────────────────── */

.co-hero {
  background: linear-gradient(135deg, var(--co-forest) 0%, var(--co-green) 100%);
  color: #fff; position: relative; overflow: hidden;
  padding: clamp(2rem, 5vw, 3rem) 0 clamp(1.75rem, 4vw, 2.5rem);
}
.co-hero::before {
  content: ''; position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.co-hero .hero-title {
  font-family: var(--font-display); font-weight: 800;
  font-size: clamp(1.8rem, 4vw, 2.8rem); letter-spacing: 0.02em;
  text-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.co-hero .hero-sub { font-size: clamp(.95rem, .9rem + .3vw, 1rem); opacity: .85; font-weight: 500; line-height: 1.5; }
.co-hero .hero-badge {
  display: inline-block; background: var(--co-gold); color: var(--co-forest);
  font-family: var(--font-display); font-weight: 700; font-size: .8rem;
  letter-spacing: .08em; text-transform: uppercase; padding: .25rem .65rem; border-radius: var(--co-radius-sm);
}

/* ─── Page header ───────────────────────────────────────────────────────────── */

.co-page-header {
  background: var(--co-green); color: #fff;
  padding: clamp(1.1rem, 3vw, 1.5rem) 0 clamp(.9rem, 2.5vw, 1.25rem);
  border-bottom: 3px solid var(--co-gold);
}
.co-page-header h1 {
  font-weight: 800; margin: 0;
  font-size: clamp(1.35rem, 1rem + 1.4vw, 1.75rem);
}
/* Pictogramme du titre : doré comme l'accent de l'en-tête (sinon hérite du #fff) */
.co-page-header h1 > i { color: var(--co-gold); }
.co-page-header .org-logo { height: 1.7rem; }
.co-breadcrumb .breadcrumb-item a { color: rgba(255,255,255,.7); }
.co-breadcrumb .breadcrumb-item a:hover { color: var(--co-gold); }
.co-breadcrumb .breadcrumb-item.active { color: rgba(255,255,255,.95); }
.co-breadcrumb .breadcrumb-item + .breadcrumb-item::before { color: rgba(255,255,255,.4); }

/* ─── Cards ─────────────────────────────────────────────────────────────────── */

.co-card {
  background: var(--co-surface);
  border-radius: var(--co-radius-lg);
  box-shadow: var(--co-shadow);
  border: 1px solid var(--co-border);
  overflow: hidden; transition: transform .2s, box-shadow .2s;
}
.co-card:hover { transform: translateY(-2px); box-shadow: var(--co-shadow-hover); }
@media (hover: none) {
  .co-card:hover { transform: none; box-shadow: var(--co-shadow); }
}
.co-card-header {
  background: var(--co-green); color: #fff; padding: .8rem 1.25rem;
  font-family: var(--font-display); font-weight: 700; font-size: 1rem;
  letter-spacing: .04em; text-transform: uppercase; border-radius: 0 !important;
}
.co-card-header .bi { opacity: .85; }

/* Logo d'organisation sur le badge de course (accueil) :
   pastille claire pour rester lisible sur le bandeau vert (logo rouge) */
.org-logo {
  flex: none; display: block; width: auto; height: 1.45rem;
  background: #fff; border: 1px solid rgba(255, 255, 255, .55);
  border-radius: var(--co-radius-sm); padding: .1rem .3rem;
}
html[data-theme="dark"] .org-logo { border-color: rgba(0, 0, 0, .25); }

/* Carte de course cliquable (accueil) : lien tendu sur toute la carte,
   les liens internes (site de l'organisateur, horaire) passent au-dessus */
.co-card-linked { position: relative; }
.co-card-linked a:not(.stretched-link) { position: relative; z-index: 2; }

/* Lien « site de l'organisateur » : souligné en permanence + icône ↗
   (nouvel onglet) pour qu'il ne passe pas pour du texte brut */
.org-site-link {
  color: var(--co-text-accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}
.org-site-link:hover { text-decoration-thickness: 2px; }
.org-site-link:focus-visible { outline: 2px solid var(--co-gold); outline-offset: 2px; }
.org-site-link .bi-box-arrow-up-right { font-size: .85em; opacity: .75; }
.org-site-link:hover .bi-box-arrow-up-right { opacity: 1; }

/* Sur le bandeau vert (page compétition) le texte est blanc :
   survol doré, comme les fil d'Ariane */
.co-page-header .org-site-link { color: #fff; text-decoration-color: rgba(255, 255, 255, .6); }
.co-page-header .org-site-link:hover { color: var(--co-gold); text-decoration-color: var(--co-gold); }

/* ─── Results table ─────────────────────────────────────────────────────────── */

.results-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .925rem; }
.results-table thead th {
  background: var(--co-forest); color: #fff; font-family: var(--font-display);
  font-weight: 700; font-size: .8rem; letter-spacing: .07em; text-transform: uppercase;
  padding: .65rem 1rem; border: none; position: sticky; top: 0; z-index: 10;
}
.results-table thead th:first-child { border-radius: 0; }
.results-table tbody tr {
  border-bottom: 1px solid var(--co-border-soft);
  transition: background .15s;
}
.results-table tbody tr:hover { background: var(--co-surface-2); }
.results-table tbody tr:last-child { border-bottom: none; }
.results-table tbody td { padding: .55rem 1rem; vertical-align: middle; }

/* Rank medals */
.rank-1 { font-family: var(--font-display); font-weight: 800; font-size: 1.1rem; color: var(--co-medal-gold); }
.rank-2 { font-family: var(--font-display); font-weight: 800; color: var(--co-medal-silver); }
.rank-3 { font-family: var(--font-display); font-weight: 800; color: var(--co-medal-bronze); }
.rank-n { color: var(--co-text-muted); font-weight: 600; }
.time-col { font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; }
.behind-col { color: var(--co-text-muted); font-size: .85rem; }
.runner-name a { color: var(--co-text); text-decoration: none; font-weight: 600; }
.runner-name a:hover { color: var(--co-text-accent); text-decoration: underline; }
.club-name { color: var(--co-text-muted); font-size: .875rem; }

/* ─── Page Live — lignes 3 colonnes (classement | coureur + postes | temps + progression) ── */

#liveTable thead { display: none; }
#liveTable tbody tr.live-runner {
  display: grid;
  /* Largeur fixe pour la colonne classement : chaque ligne étant une grille
     indépendante, une colonne « auto » casserait l'alignement des noms. */
  grid-template-columns: 2rem minmax(0, 1fr) max-content;
  gap: .1rem .75rem;
  padding: .5rem .75rem;
}
#liveTable tbody tr.live-runner > td { padding: 0; }
.live-cell-rank { align-self: start; }
.live-cell-main { min-width: 0; }
.live-cell-side {
  display: flex; flex-direction: column; align-items: flex-end;
  gap: .15rem; text-align: right;
}
.live-runner-line {
  display: flex; flex-wrap: wrap; align-items: baseline;
  column-gap: .35rem; min-width: 0;
}
.live-runner-line .club-name { white-space: nowrap; font-size: .8rem; }
.live-time-line { line-height: 1.25; }
.live-time-value {
  font-family: var(--font-display); font-weight: 700; font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}

/* Couples poste/temps : grille à piste fixe. Les largeurs --lp-badge-w /
   --lp-time-w sont mesurées en JS (live.js syncPunchWidths) d'après le plus
   long libellé réel : étiquettes et temps partagent donc leur largeur et les
   poinçons s'alignent verticalement d'une ligne sur l'autre. */
.live-punches {
  display: grid;
  grid-template-columns: repeat(auto-fill,
    calc(var(--lp-badge-w, 2.4rem) + .2rem + var(--lp-time-w, 3.6rem)));
  gap: .2rem .5rem;
  margin-top: .15rem;
  max-width: 100%;
}
.live-punch {
  display: inline-grid;
  grid-template-columns: var(--lp-badge-w, 2.4rem) var(--lp-time-w, 3.6rem);
  column-gap: .2rem;
}
.live-punch .badge {
  justify-self: stretch; min-width: 0; white-space: nowrap;
  text-align: center; overflow: hidden; text-overflow: ellipsis;
}
.live-punch-time {
  font-family: var(--font-display); font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right; white-space: nowrap;
}
.live-punch-time.live-punch-prestart {
  /* Poinçon antérieur au départ (temps négatif) : signalé visuellement. */
  color: var(--bs-danger, #dc3545);
}
.live-ago {
  /* Ticker « il y a X s » : posé sous la grille des couples (colonne 1 étant
     occupée par le premier couple, il passe systématiquement à la ligne),
     hors géométrie étiquette/temps — span 2 pour respirer. */
  grid-column: 1 / span 2;
  color: var(--co-text-muted); font-size: .76rem; white-space: nowrap;
}

/* Progression compacte */
.live-progress { display: inline-flex; align-items: center; gap: .35rem; }
.live-progress-count {
  font-size: .76rem; font-weight: 700; color: var(--co-text-muted);
  font-variant-numeric: tabular-nums;
}
.live-progress-track {
  width: 4rem; height: .45rem; border-radius: 999px;
  background: var(--co-track-bg); overflow: hidden;
}
.live-progress-bar { display: block; height: 100%; border-radius: 999px; background: var(--co-green); }
.live-progress-done { font-weight: 700; }

/* Styles live (déplacés depuis live_results.html) */
.live-dot { display:inline-block; width:.6rem; height:.6rem; border-radius:50%;
            background:currentColor; margin-right:.4rem; animation:livePulse 1.5s infinite; }
@keyframes livePulse { 0%,100% { opacity:1; } 50% { opacity:.3; } }
.live-group-row { background: var(--co-forest) !important; }
.live-group-row td { color: #fff !important; padding: .45rem 1rem !important; }
.live-running { animation: liveFlash 2s infinite; }
@keyframes liveFlash { 0%,100% { background: transparent; } 50% { background: rgba(25,135,84,.08); } }
.live-time { font-variant-numeric: tabular-nums; }
.live-clock { font-variant-numeric: tabular-nums; letter-spacing: .05em; }

/* ─── Stat cards ─────────────────────────────────────────────────────────────── */

.stat-card {
  background: var(--co-surface);
  border-radius: var(--co-radius-lg);
  box-shadow: var(--co-shadow);
  border: 1px solid var(--co-border);
  border-left: 4px solid var(--co-green);
  padding: 1rem 1.25rem;
}
.stat-card .stat-value {
  font-family: var(--font-display); font-weight: 800; font-size: 2rem;
  color: var(--co-text-accent); line-height: 1;
}
.stat-card .stat-label {
  font-size: .8rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--co-text-muted); font-weight: 600;
}

/* ─── Class grid ─────────────────────────────────────────────────────────────── */

.class-card {
  background: var(--co-surface);
  border-radius: var(--co-radius-lg);
  box-shadow: var(--co-shadow);
  border: 1px solid var(--co-border);
  padding: 1.1rem 1.25rem;
  text-decoration: none; color: inherit; display: block; transition: all .2s;
}
.class-card:hover {
  border-color: var(--co-green); transform: translateY(-2px);
  box-shadow: var(--co-shadow-hover); color: inherit;
}
@media (hover: none) {
  .class-card:hover { transform: none; }
}
.class-card .class-name { font-family: var(--font-display); font-weight: 800; font-size: 1.35rem; color: var(--co-text-accent); }
.class-card .class-meta { font-size: .8rem; color: var(--co-text-muted); }
.class-card .class-finishers { font-family: var(--font-display); font-size: .95rem; font-weight: 700; color: var(--co-text-deep); }

/* ─── Checker rule card header statuses ─────────────────────────────────────── */

.co-card-header.rule-header-ok { background: var(--co-green); }
.co-card-header.rule-header-error { background: #a71d2a; }
.co-card-header.rule-header-warning { background: #795c00; }

/* ─── Checker violation rows ────────────────────────────────────────────────── */

.rule-violation-btn {
  background: var(--co-danger-soft);
  border: none;
}
.rule-violation-text {
  background: var(--co-danger-soft);
}

/* ─── Checker stat card variants ────────────────────────────────────────────── */

.stat-card-warning { border-left-color: var(--co-gold); }
.stat-card-secondary { border-left-color: var(--co-grey); }

.stat-card-status-error { border-left-color: var(--co-warn); }
.stat-card-status-error .stat-value { color: var(--co-warn); font-size: 1.4rem; }
.stat-card-status-warning { border-left-color: var(--co-gold); }
.stat-card-status-warning .stat-value { color: var(--co-gold); font-size: 1.4rem; }
.stat-card-status-ok { border-left-color: var(--co-green); }
.stat-card-status-ok .stat-value { color: var(--co-text-accent); font-size: 1.4rem; }

/* ─── Badge overrides ───────────────────────────────────────────────────────── */

.badge-co-ok  { background: var(--co-green); color: #fff; }
.badge-co-dns { background: var(--co-grey); color: #fff; }
.badge-co-bad { background: var(--co-warn); color: #fff; }

/* ─── Footer ─────────────────────────────────────────────────────────────────── */

footer {
  background: var(--co-forest); color: rgba(255,255,255,.6);
  font-size: .85rem; padding: 1.5rem 0; margin-top: 3rem;
}
footer a { color: var(--co-gold); }

/* ─── Split times (page détail concurrent) ──────────────────────────────────── */

.split-row td:first-child { font-weight: 700; color: var(--co-text-muted); width: 2rem; }
.split-abs { font-family: var(--font-display); font-weight: 700; }
.split-leg { color: var(--co-text-muted); font-size: .875rem; }

/* ─── Grille splits partagée (class_results + relay_results) ────────────────── */

.splits-grid {
  display: flex; flex-wrap: wrap; gap: 2px; width: 100%;
}
.split-cell {
  display: flex; flex-direction: column; align-items: center;
  flex: 1 1 4.5rem; max-width: 6.5rem; padding: .3rem .35rem;
  border: 1px solid var(--co-split-border); border-radius: var(--co-radius-sm);
  background: var(--co-surface);
  font-size: .78rem; box-sizing: border-box;
}
.split-ctrl-name {
  font-family: var(--font-display); font-weight: 700; font-size: .8rem;
  color: var(--co-text-deep); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; max-width: 100%;
}
.split-time-abs {
  font-family: var(--font-display); font-weight: 700; font-size: .88rem;
  color: var(--co-text-accent); margin-top: .1rem;
}
.split-time-leg { font-size: .74rem; color: var(--co-text-muted); margin-top: .05rem; }
.split-start { background: var(--co-ok-bg); border-color: var(--co-ok-border); }
.split-start .split-time-abs { color: var(--co-ok-text); }
.split-finish { background: var(--co-ok-bg); border-color: var(--co-ok-border); }
.split-finish .split-time-abs { font-size: .96rem; color: var(--co-text-deep); }

/* Classement dans les intermédiaires */
.split-rank {
  font-size: .65rem; font-weight: 700; font-family: var(--font-display);
  color: var(--co-text-muted); opacity: .85;
}
.split-rank::before { content: '('; }
.split-rank::after  { content: ')'; }
.split-rank-leg { color: var(--co-text-accent); }

/* Temps négatif (boîtier mal synchronisé ou carte SI non effacée) */
.split-neg { color: var(--co-warn); font-weight: 700; }
.split-mark-warn { color: var(--co-warn); font-weight: 800; }
.badge.neg-badge { background: var(--co-warn); color: #fff; font-size: .68rem; }
tr.neg-row > td { background: rgba(220, 53, 69, .05); }
tr.neg-row:hover > td { background: rgba(220, 53, 69, .1); }

/* Bannière d'avertissement temps négatifs */
.neg-time-warning {
  display: flex; flex-direction: column; gap: .5rem;
  padding: .6rem 1rem;
  border: 1px solid rgba(220, 53, 69, .35);
  border-left: 4px solid var(--co-warn);
  border-radius: var(--co-radius-md);
  background: color-mix(in srgb, var(--co-warn) 8%, transparent);
  color: var(--co-warn);
  font-weight: 600;
}
.neg-time-warning-header { display: flex; align-items: center; }
.neg-time-warning-header .bi { flex: none; }

/* Postes suspectés (boîtier) */
.neg-box-controls { font-weight: 500; font-size: .92rem; }
.neg-box-controls-label { color: var(--co-warn); font-weight: 700; }
.neg-box-control { font-weight: 700; color: var(--co-text-deep); }
.neg-box-count { font-weight: 500; color: var(--co-warn); }
.neg-box-sep { color: var(--co-text-muted); }

/* Tableau des coureurs à temps négatif */
.neg-runners-table {
  width: 100%;
  border-collapse: collapse;
  font-weight: 500; font-size: .92rem;
}
.neg-runners-table th {
  text-align: left; padding: .3rem .5rem;
  border-bottom: 2px solid rgba(220, 53, 69, .4);
  font-size: .78rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--co-warn); white-space: nowrap;
}
.neg-runners-table td {
  padding: .3rem .5rem;
  border-bottom: 1px solid rgba(220, 53, 69, .18);
  vertical-align: top;
}
.neg-runners-table tr:last-child td { border-bottom: none; }
.neg-table-rank { color: var(--co-text-muted); font-variant-numeric: tabular-nums; }
.neg-runners-table a { color: var(--co-warn); text-decoration: underline; }
.neg-runners-table a:hover { color: var(--co-text-deep); }
.neg-table-cls { color: var(--co-text-muted); white-space: nowrap; }
.neg-table-ctrls { font-style: italic; color: var(--co-text-deep); }
.neg-ctrl-box { font-style: normal; color: var(--co-warn); text-decoration: underline dotted; }

/* Meilleur tronçon */
.split-best { background: var(--co-highlight-bg); border-color: var(--co-highlight-border); }
.split-leg-best { font-weight: 800; color: var(--co-highlight-text); }
.split-best .split-ctrl-name::after { content: ' ★'; color: var(--co-gold); font-size: .7rem; }

/* Podium tronçon (2e/3e) */
.split-podium { background: var(--co-info-bg); border-color: var(--co-info-border); }

/* Détail splits (résultats) */
.splits-td { padding: 0 !important; }
.splits-detail {
  background: var(--co-surface-2);
  border-top: 1px solid var(--co-ok-border);
  border-bottom: 2px solid var(--co-ok-border);
  padding: .5rem .75rem .65rem;
}
.split-error-flag {
  background: color-mix(in srgb, var(--co-warn) 10%, var(--co-surface)) !important;
  border-color: color-mix(in srgb, var(--co-warn) 40%, transparent) !important;
}
.split-error-flag .split-ctrl-name { color: var(--co-danger-text); }
.split-error { font-size: .68rem; color: var(--co-danger-text); font-weight: 700; margin-top: .1rem; text-align: center; }
.time-col-splits { cursor: pointer; user-select: none; }
.time-col-splits:hover { background: var(--co-surface-2); }
.time-with-toggle { display: inline-flex; align-items: center; white-space: nowrap; }
.split-toggle { border: none; background: transparent; vertical-align: middle; }
.split-toggle .bi { transition: transform .2s; display: inline-block; }
.split-toggle.open .bi { transform: rotate(180deg); }

/* ─── Barre d'onglets analyses ───────────────────────────────────────────────── */

.analysis-tabs-bar {
  background: var(--co-surface);
  border-bottom: 1px solid var(--co-border);
  box-shadow: 0 2px 6px rgba(0,0,0,.06);
  padding: .4rem 0;
}
.analysis-tabs {
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  gap: .4rem;
}
.analysis-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .65rem 1.1rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: .82rem;
  letter-spacing: .03em;
  color: var(--co-text-muted);
  text-decoration: none;
  border: 1px solid var(--co-border);
  border-radius: var(--co-radius-md);
  background: linear-gradient(180deg, var(--co-surface-2), var(--co-surface));
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
  white-space: nowrap;
  transition: color .15s, border-color .15s, background .15s,
              box-shadow .15s, transform .15s;
  cursor: pointer;
}
.analysis-tab:hover:not(.disabled):not(.active) {
  color: var(--co-text-accent);
  background: var(--co-surface-3);
  border-color: color-mix(in srgb, var(--co-green) 35%, var(--co-border));
  box-shadow: 0 3px 8px rgba(0,0,0,.12);
  transform: translateY(-1px);
}
@media (hover: none) {
  .analysis-tab:hover:not(.disabled):not(.active) {
    transform: none;
    box-shadow: 0 1px 2px rgba(0,0,0,.08);
  }
}
.analysis-tab.active {
  color: var(--co-text-accent);
  border-color: var(--co-gold);
  background: var(--co-highlight-bg);
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
  font-weight: 700;
}
.analysis-tab:focus-visible {
  outline: 2px solid var(--co-gold);
  outline-offset: 2px;
}
.analysis-tab.active .bi { color: var(--co-gold); }
.analysis-tab.disabled { color: var(--co-text-muted); opacity: .5; cursor: not-allowed; pointer-events: none; }
.analysis-tab .bi { font-size: .95rem; }

/* ─── Navigation catégories (bas de page + modale) ──────────────────────────── */

.cat-nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  padding: .45rem .95rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: .85rem;
  letter-spacing: .02em;
  color: var(--co-text);
  text-decoration: none;
  border: 1px solid var(--co-border);
  border-radius: 999px;
  background: linear-gradient(180deg, var(--co-surface-2), var(--co-surface));
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s,
              box-shadow .15s, transform .15s;
}
.cat-nav-btn:hover:not(:disabled):not(.is-disabled) {
  color: var(--co-text-accent);
  border-color: color-mix(in srgb, var(--co-green) 35%, var(--co-border));
  box-shadow: 0 3px 8px rgba(0,0,0,.12);
  transform: translateY(-1px);
}
@media (hover: none) {
  .cat-nav-btn:hover:not(:disabled):not(.is-disabled) {
    transform: none;
    box-shadow: 0 1px 2px rgba(0,0,0,.08);
  }
}
.cat-nav-btn:focus-visible {
  outline: 2px solid var(--co-gold);
  outline-offset: 2px;
}
.cat-nav-btn.is-disabled,
.cat-nav-btn:disabled {
  opacity: .5;
  pointer-events: none;
}
.cat-nav-btn-main {
  color: var(--co-text-accent);
  border-color: color-mix(in srgb, var(--co-green) 45%, var(--co-border));
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--co-green) 10%, var(--co-surface)),
    color-mix(in srgb, var(--co-green) 4%, var(--co-surface)));
  font-weight: 700;
}
.cat-nav-btn-main:hover:not(:disabled) {
  border-color: var(--co-green);
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--co-green) 16%, var(--co-surface)),
    color-mix(in srgb, var(--co-green) 8%, var(--co-surface)));
}

/* Barre de navigation catégories : flottante en bas d'écran pendant le
   défilement (sticky), puis se repose au-dessus du footer en fin de page. */
.cat-nav-bar {
  position: sticky;
  bottom: calc(.75rem + env(safe-area-inset-bottom, 0px));
  z-index: 20; /* > en-têtes de tableaux collants (10), < modale (1050) */
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  justify-content: center;
  width: fit-content;
  max-width: calc(100% - 1rem);
  margin: 1.5rem auto .5rem;
  padding: .55rem .7rem;
  border: 1px solid var(--co-border);
  border-radius: var(--co-radius-lg);
  background: color-mix(in srgb, var(--co-surface) 92%, transparent);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(0,0,0,.18), 0 2px 6px rgba(0,0,0,.1);
}
/* Le bouton « retour en haut » ne doit pas chevaucher la barre flottante */
body:has(.cat-nav-bar) #backToTop { bottom: 4.5rem; }

/* Modale « Choisir une catégorie » */
.category-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr));
  gap: .5rem;
}
.category-picker-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: .55rem .75rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: .88rem;
  color: var(--co-text);
  text-align: center;
  text-decoration: none;
  border: 1px solid var(--co-border);
  border-radius: var(--co-radius-md);
  background: linear-gradient(180deg, var(--co-surface-2), var(--co-surface));
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
  transition: color .15s, border-color .15s, background .15s,
              box-shadow .15s, transform .15s;
}
.category-picker-btn:hover {
  color: var(--co-text-accent);
  border-color: color-mix(in srgb, var(--co-green) 35%, var(--co-border));
  box-shadow: 0 3px 8px rgba(0,0,0,.12);
  transform: translateY(-1px);
}
@media (hover: none) {
  .category-picker-btn:hover {
    transform: none;
    box-shadow: 0 1px 2px rgba(0,0,0,.08);
  }
}
.category-picker-btn:focus-visible {
  outline: 2px solid var(--co-gold);
  outline-offset: 2px;
}
.category-picker-btn.active {
  color: var(--co-text-accent);
  border-color: var(--co-gold);
  background: var(--co-highlight-bg);
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
  font-weight: 700;
}

/* ─── Légende graphique (analysis_base) ─────────────────────────────────────── */

#legendBox { display: flex; flex-wrap: wrap; gap: .4rem .75rem; padding: .5rem 0 0; }
.legend-item {
  display: flex; align-items: center; gap: .35rem; cursor: pointer;
  font-size: .8rem; padding: .2rem .5rem; border-radius: var(--co-radius-sm);
  border: 1px solid transparent; transition: background .15s; user-select: none;
}
.legend-item:hover { background: var(--co-surface-3); }
.legend-item.hidden { opacity: .35; }
.legend-color { width: 18px; height: 3px; border-radius: 2px; flex-shrink: 0; }

/* ─── Bouton dark-mode toggle ────────────────────────────────────────────────── */

#darkModeToggle {
  background: none;
  border: 1px solid rgba(255,255,255,.3);
  color: rgba(255,255,255,.75);
  border-radius: var(--co-radius-md);
  padding: .3rem .6rem;
  font-size: .9rem;
  cursor: pointer;
  transition: border-color .2s, color .2s;
  line-height: 1.5;
}
#darkModeToggle:hover { border-color: var(--co-gold); color: var(--co-gold); }
#darkModeToggle:focus-visible {
  outline: 2px solid var(--co-gold);
  outline-offset: 2px;
}

/* ─── Bouton retour en haut ──────────────────────────────────────────────────── */

#backToTop {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  background: var(--co-green);
  color: #fff;
  border: none;
  cursor: pointer;
  /* Caché par défaut : opacité 0 + légèrement décalé vers le bas */
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .25s ease, transform .25s ease;
  /* Toujours au-dessus du contenu et des modales Bootstrap (z-index 1050) */
  z-index: 1060;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .2);
  /* Empêche les interactions quand le bouton est invisible */
  pointer-events: none;
}
#backToTop.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
/* Masqué pendant l'ouverture d'une modale (z-index 1060 > 1055) */
body.modal-open #backToTop { display: none; }
#backToTop:hover {
  background: var(--co-green-dark);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
}
#backToTop:focus-visible {
  outline: 2px solid var(--co-gold);
  outline-offset: 3px;
}

/* ─── Responsive ─────────────────────────────────────────────────────────────── */

/* Cibles tactiles : menu replié + barre d'onglets scrollable (≤ lg) */
@media (max-width: 991.98px) {
  .co-navbar .nav-link { min-height: 2.75rem; display: flex; align-items: center; }
  .co-dropdown .dropdown-item { padding: .7rem 1.1rem; }
  #darkModeToggle { min-height: 2.5rem; min-width: 2.5rem; }
  .navbar-toggler {
    min-height: 2.75rem; min-width: 2.75rem;
    display: flex; align-items: center; justify-content: center;
  }

  /* Sélecteur de langue : compact (replié = toujours visible, à côté du titre) */
  .co-lang-switch { margin-left: .15rem; padding-left: .45rem; }
  .co-lang-switch .co-lang-toggle { padding: 2px 4px; }
  .co-lang-switch .co-lang-toggle img { width: 21px; height: 14px; }
  /* Très petits écrans : le titre du site passe sur une ligne et le
     sélecteur de langue reste aligné sans écraser le bouton de menu */
  .co-navbar .navbar-brand span { white-space: nowrap; }
  .navbar-brand-group { flex-wrap: wrap; row-gap: .25rem; }

  /* Onglets analyses : plusieurs rangs quand la largeur ne suffit pas
     (flex-wrap) — plus de défilement horizontal caché.
     Même rendu qu'au grand écran, sans agrandissement (pas de min-height,
     pas d'icône surdimensionnée) : de petits tampons compacts. */
  .analysis-tabs {
    flex-wrap: wrap;
    overflow-x: visible;
    row-gap: .4rem;
  }
  .analysis-tab {
    flex: 0 0 auto;
    padding: .5rem .8rem;
    line-height: 1.2;
  }
  .analysis-tab .bi { line-height: 1; }
}

@media (max-width: 768px) {
  .results-table { font-size: .85rem; }
  .results-table tbody td { padding: .45rem .65rem; }
  .results-table thead th { padding: .5rem .65rem; }
  .analysis-tab { padding: .45rem .7rem; font-size: .77rem; letter-spacing: 0; }

  /* Cibles tactiles : au moins 44px sur tout ce qui se clique / saisit */
  .btn:not(.btn-close),
  .form-control,
  .form-select {
    min-height: 2.75rem;
  }
  .btn:not(.btn-sm):not(.btn-xs) { padding-top: .6rem; padding-bottom: .6rem; }

  /* Sur mobile : un peu plus petit et moins près du bord */
  #backToTop { width: 2.5rem; height: 2.5rem; font-size: 1.25rem; bottom: 1.25rem; right: 1.25rem; }
  body:has(.cat-nav-bar) #backToTop { bottom: 4rem; }

  /* Récapitulatif : cacher club + catégorie, colonnes plus étroites */
  .col-club,
  .col-category { display: none !important; }
  #recapTable [data-sticky="0"] { width: 2rem !important; min-width: 2rem !important; left: 0 !important; }
  #recapTable [data-sticky="1"] { width: 5rem !important; min-width: 5rem !important; left: 2rem !important; }
  #recapTable [data-sticky="2"] { width: 5rem !important; min-width: 5rem !important; left: 7rem !important; }
  #recapTable tbody td { padding: .35rem .5rem; }
  #recapTable .time-col { font-size: .85rem; }
  #recapTable .split-rank { font-size: .55rem; }
}
@media (max-width: 576px) {
  /* Barre de navigation catégories : pleine largeur, boutons compacts */
  .cat-nav-bar { width: calc(100% - 1rem); margin-bottom: .75rem; }
  .cat-nav-bar .cat-nav-btn { padding: .5rem .8rem; font-size: .82rem; }

  /* Récapitulatif : encore plus compact */
  #recapTable [data-sticky="0"] { width: 1.6rem !important; min-width: 1.6rem !important; }
  #recapTable [data-sticky="1"] { width: 4rem !important; min-width: 4rem !important; left: 1.6rem !important; }
  #recapTable [data-sticky="2"] { width: 4rem !important; min-width: 4rem !important; left: 5.6rem !important; }
  #recapTable tbody td { padding: .25rem .35rem; font-size: .75rem; }
  #recapTable .time-col { font-size: .78rem; }
  #recapTable .split-rank { font-size: .48rem; }
  #recapWrap { max-height: calc(100vh - 180px); }

  .co-breadcrumb .breadcrumb { flex-wrap: nowrap; overflow: hidden; }
  .co-breadcrumb .breadcrumb-item { max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .co-breadcrumb .breadcrumb-item.active { max-width: none; }

  #liveTable tbody tr.live-runner { padding: .45rem .6rem; gap: .05rem .5rem; }
  .live-time-value { font-size: 1rem; }
  .live-progress-track { width: 3.2rem; }
  .live-punches { gap: .15rem .35rem; }
}
@media (max-width: 380px) {
  .analysis-tab { padding: .45rem .6rem; }
  .live-punches { gap: .15rem .25rem; }
}
