/* === Variables === */
:root {
  --blue: #003189;
  --blue-light: #ddf4ff;
  --yellow: #ffcc00;
  --text: #1f2328;
  --text-muted: #57606a;
  --bg: #f6f8fa;
  --bg-card: #ffffff;
  --border: #d0d7de;
  --green: #1a7f37;
  --red: #d1242f;
  --gold: #d4ac0d;
  --orange: #cf6c0a;
  --rank-bg: #f6f8fa;
  --shadow: 0 1px 3px rgba(0,0,0,.05);
  --font-mono: 'Courier New', monospace;
}

/* === Reset & base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.4; }
button { cursor: pointer; border: none; background: none; font: inherit; }

/* === Header === */
.header {
  background: var(--blue);
  color: #fff;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.header-logo { background: var(--yellow); color: var(--blue); font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 3px; white-space: nowrap; }
.header-title { font-size: 14px; font-weight: 700; white-space: nowrap; }
.header-compet { color: rgba(255,255,255,.6); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* === Statut WS === */
.ws-status { display: flex; align-items: center; gap: 5px; font-size: 11px; color: rgba(255,255,255,.8); }
.ws-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.ws-dot.connected { background: #3fb950; }
.ws-dot.reconnecting { background: #f0883e; animation: pulse 1s infinite; }
.ws-dot.lost { background: #f85149; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* === Boutons header === */
.btn-header {
  background: rgba(255,255,255,.15);
  color: #fff;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 4px;
  transition: background .15s;
}
.btn-header:hover { background: rgba(255,255,255,.25); }
.btn-header:focus-visible { outline: 2px solid rgba(255,255,255,.5); outline-offset: 2px; }

/* === Onglets catégories === */
.tabs-categories {
  background: var(--bg-card);
  border-bottom: 2px solid var(--border);
  padding: 0 16px;
  display: flex;
  gap: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs-categories::-webkit-scrollbar { display: none; }
.tab-cat {
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.tab-cat.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }
.tab-cat:hover:not(.active) { color: var(--text); }

/* === Barre manches + favoris === */
.tabs-runs {
  background: var(--bg);
  padding: 6px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  gap: 8px;
  flex-wrap: wrap;
}
.tabs-runs-left { display: flex; gap: 4px; }
.tab-run {
  padding: 3px 12px;
  font-size: 11px;
  border-radius: 10px;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: background .15s, color .15s;
}
.tab-run.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.tab-run:hover:not(.active) { background: var(--border); }
.tab-run:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.btn-favorites {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 12px;
  font-size: 11px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  transition: background .15s, border-color .15s, color .15s;
}
.btn-favorites.active {
  background: #fff8c5;
  border-color: var(--gold);
  color: #9a6700;
  font-weight: 600;
}
.btn-favorites:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* === Layout principal === */
.main-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 12px 16px;
}

/* === Colonne gauche === */
.col-left { display: flex; flex-direction: column; gap: 10px; }

/* === Section label === */
.ranking-label { margin-bottom: 6px; }
.section-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: .8px;
  text-transform: uppercase;
}

/* === Card athlète en cours === */
.card-current {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}
.card-current-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.bib-badge {
  background: var(--blue-light);
  color: var(--blue);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 10px;
}
.card-current-top-right { display: flex; align-items: center; gap: 8px; }
.cat-badge {
  background: #fff8c5;
  color: #9a6700;
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 10px;
}
.athlete-name { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 2px; overflow-wrap: break-word; }
.athlete-club { font-size: 11px; color: var(--text-muted); margin-bottom: 12px; }
.chrono-box {
  background: var(--bg);
  border-radius: 6px;
  padding: 10px;
  text-align: center;
  margin-bottom: 10px;
}
.chrono { font-size: 32px; font-weight: 700; color: var(--blue); letter-spacing: 3px; font-family: var(--font-mono); }
.chrono-penalties { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.chrono-penalties .pen-zero { color: var(--green); font-weight: 700; }
.chrono-penalties .pen-pos { color: var(--red); font-weight: 700; }
.card-current-footer { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); }
.gap-leader { color: var(--red); }
.card-empty { background: var(--bg-card); border: 1px dashed var(--border); border-radius: 8px; padding: 24px; text-align: center; color: var(--text-muted); font-size: 12px; }
.table-empty { padding: 10px; text-align: center; font-size: 11px; color: var(--text-muted); }

/* === Liste à suivre === */
.list-upcoming { background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.list-row {
  display: grid;
  grid-template-columns: 32px 1fr 20px;
  align-items: center;
  padding: 6px 10px;
  font-size: 12px;
  border-bottom: 1px solid var(--bg);
  gap: 4px;
}
.list-row:last-child { border-bottom: none; }
.list-row .bib { color: var(--text-muted); font-size: 11px; }
.list-row.fav-row { background: #fffdf0; }

/* === Derniers arrivés === */
.table-finishers { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; box-shadow: var(--shadow); }
.table-head {
  display: grid;
  grid-template-columns: 28px 16px 1fr 58px 34px 42px 20px;
  gap: 3px;
  padding: 5px 10px;
  background: var(--bg);
  font-size: 10px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.table-head span, .table-row span { display: flex; align-items: center; }
.table-row {
  display: grid;
  grid-template-columns: 28px 16px 1fr 58px 34px 42px 20px;
  gap: 3px;
  padding: 8px 10px;
  font-size: 11px;
  align-items: center;
  border-bottom: 1px solid var(--bg);
}
.table-row:last-child { border-bottom: none; }
.table-row.fav-row { background: #fffdf0; }
.ranking-current { background: #e8f4ff; }
.ranking-current .name { color: var(--blue); font-weight: 700; }
.col-r { justify-content: flex-end; font-family: var(--font-mono); }
.col-pen-pos { color: var(--red); font-weight: 700; }
.col-pen-zero { color: var(--green); }
.medal { width: 10px; height: 10px; border-radius: 50%; }
.medal-1 { background: #d4ac0d; }
.medal-2 { background: #bdc3c7; }
.medal-3 { background: #cd7f32; }
.athlete-sub { font-size: 9px; color: var(--text-muted); }

/* === Classement === */
.table-ranking { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; box-shadow: var(--shadow); }
.ranking-footer { padding: 5px 10px; text-align: center; font-size: 10px; color: var(--text-muted); background: var(--bg); border-top: 1px solid var(--border); }
.rank-num { font-weight: 700; }
.rank-1 { color: #b08800; }
.rank-2 { color: #57606a; }
.rank-3 { color: #7d5a34; }

/* === Bouton favori === */
.btn-fav { font-size: 13px; color: #ccc; background: none; border: none; cursor: pointer; padding: 0; line-height: 1; transition: color .1s; }
.btn-fav.active { color: var(--gold); }
.btn-fav:hover { color: var(--gold); }

/* === Overlays === */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.overlay.open { display: flex; }
.overlay-panel {
  position: relative;
  background: var(--bg-card);
  border-radius: 10px;
  padding: 20px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.overlay-title { font-size: 15px; font-weight: 700; margin-bottom: 16px; }
.form-label { font-size: 11px; color: var(--text-muted); font-weight: 600; margin-bottom: 4px; display: block; }
.form-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font: inherit;
  font-size: 13px;
  background: var(--bg);
  margin-bottom: 12px;
  outline: none;
  transition: border-color .15s;
}
.form-input:focus { border-color: var(--blue); }
.btn-primary {
  width: 100%;
  padding: 9px;
  background: var(--blue);
  color: #fff;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 600;
  margin-top: 4px;
  transition: background .15s;
}
.btn-primary:hover { background: #002070; }
.overlay-close {
  position: absolute;
  top: 14px;
  right: 16px;
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}

/* === Panel debug === */
.debug-panel {
  display: none;
  position: fixed;
  inset: 0;
  background: #0d1117;
  z-index: 300;
  flex-direction: column;
}
.debug-panel.open { display: flex; }
.debug-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid #30363d; }
.debug-header-left { display: flex; align-items: center; gap: 10px; }
.debug-title { color: #3fb950; font-size: 13px; font-weight: 700; font-family: monospace; }
.debug-count { color: #7d8590; font-size: 11px; font-family: monospace; }
.debug-actions { display: flex; gap: 8px; }
.btn-debug-action {
  background: #21262d;
  color: #e6edf3;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid #30363d;
}
.btn-debug-action:hover { background: #30363d; }
.btn-debug-close { color: #7d8590; font-size: 18px; cursor: pointer; background: none; border: none; }
.debug-log { flex: 1; overflow-y: auto; padding: 8px 16px; font-family: var(--font-mono); font-size: 11px; line-height: 1.6; }
.debug-entry { border-bottom: 1px solid #161b22; padding: 3px 0; }
.debug-ts { color: #7d8590; margin-right: 8px; }
.debug-data { color: #58a6ff; word-break: break-all; }
.debug-data.error { color: #f85149; }

/* === Carrés de pénalité par porte === */
.penalty-gates { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.penalty-gate {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 3px;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
}
.penalty-gate-2  { background: #f5c400; color: #3a2d00; }
.penalty-gate-50 { background: var(--red); color: #fff; }

/* === Responsive === */
@media (max-width: 768px) {
  .main-split { grid-template-columns: 1fr; }
  .header-compet { display: none; }
  .chrono { font-size: 26px; }
}
