/* ── Conteneur scrollable ─────────────────────────── */
.bracket-wrapper {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 8px 4px 16px;
  -webkit-overflow-scrolling: touch;
}

.bracket-section + .bracket-section {
  margin-top: 28px;
}

.bracket-section-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0;
  margin: 0 0 8px;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.bracket-section-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #475569;
}

.bracket-section-toggle .bracket-section-title {
  margin: 0;
}

.bracket-section-icon {
  flex: 0 0 auto;
  color: #64748b;
  font-size: 14px;
  line-height: 1;
  transition: transform .18s ease;
}

.bracket-section.is-collapsed .bracket-section-icon {
  transform: rotate(-90deg);
}

.bracket-section-content {
  display: block;
}

.bracket-section.is-collapsed .bracket-section-content {
  display: none;
}

.bracket-wrapper--double {
  padding-top: 12px;
}

.bracket-fit {
  transform-origin: top left;
  will-change: transform;
}

.bracket {
  display: flex;
  align-items: stretch;
  gap: 0;
  min-width: max-content;
}

.bracket-double {
  display: grid;
  grid-template-columns: auto 230px auto;
  gap: 18px;
  min-width: max-content;
  align-items: start;
}

.bracket-side {
  display: flex;
  gap: 0;
  align-items: stretch;
  position: relative;
  z-index: 1;
}

.bracket-side--right {
  flex-direction: row-reverse;
}

.bracket-center {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  padding-top: 2px;
  min-width: 200px;
  position: relative;
  z-index: 3;
}

.bracket-center-title {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #94a3b8;
  padding: 0 0 12px;
  white-space: nowrap;
}

/* ── Colonne d'un round ───────────────────────────── */
.bracket-round {
  display: flex;
  flex-direction: column;
  min-width: 210px;
  padding: 0 10px;
  position: relative;
}

.bracket-round--winner {
  min-width: 200px;
}

.bracket-round-title {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #94a3b8;
  padding: 0 0 12px;
  white-space: nowrap;
}

/* ── Wrapper match + connecteur ──────────────────── */
.bracket-match-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 2;
  padding: 6px 0;
}

.bracket-leg-badge {
  margin-bottom: 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #64748b;
}

/* Ligne horizontale gauche (entrante) */
.bracket-match-wrapper::before {
  content: '';
  position: absolute;
  left: -10px;
  top: 50%;
  width: 10px;
  height: 2px;
  background: #e2e8f0;
}
.bracket-round:first-child .bracket-match-wrapper::before {
  display: none;
}

/* ── Groupe de 2 matchs + connecteur vertical droit ─ */
.bracket-pair {
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex: 1;
  position: relative;
}

/* Ligne verticale reliant les 2 matchs d'une paire (côté droit) */
.bracket-pair::after {
  content: '';
  position: absolute;
  right: -10px;
  top: calc(25%);
  height: calc(50%);
  width: 2px;
  background: #e2e8f0;
}
/* Pas de connecteur sur le dernier round */
.bracket-round:last-child .bracket-pair::after {
  display: none;
}

/* Ligne horizontale droite sortante (milieu de la paire) */
.bracket-pair::before {
  content: '';
  position: absolute;
  right: -20px;
  top: 50%;
  width: 10px;
  height: 2px;
  background: #e2e8f0;
}
.bracket-round:last-child .bracket-pair::before {
  display: none;
}

/* New aligned geometry (overrides legacy pair spacing) */
.bracket-round-list {
  position: relative;
  width: 100%;
  padding-bottom: 16px;
}

.bracket-slot {
  position: absolute;
  left: 0;
  width: max-content;
}

.bracket-slot.has-connectors::before {
  content: '';
  position: absolute;
  z-index: 0;
  left: -18px;
  top: 50%;
  width: 18px;
  height: 2px;
  background: #e2e8f0;
}

.bracket-slot.has-connectors::after {
  content: '';
  position: absolute;
  z-index: 0;
  left: -18px;
  top: calc(50% - var(--connector-span, 0px));
  width: 2px;
  height: calc(var(--connector-span, 0px) * 2);
  background: #e2e8f0;
}

.bracket-round--right .bracket-slot.has-connectors::before {
  left: auto;
  right: -18px;
}

.bracket-round--right .bracket-slot.has-connectors::after {
  left: auto;
  right: -18px;
}

/* Disable legacy per-card connector line in aligned mode */
.bracket-match-wrapper::before {
  display: none;
}

/* ── Carte match ──────────────────────────────────── */
.bracket-match {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  width: 190px;
  flex-shrink: 0;
}

.bracket-match--two-legged {
  width: 206px;
}

.bracket-team--editable {
  cursor: pointer;
}

.bracket-team--editable:hover {
  background: #f8fafc;
}

/* ── Ligne équipe ─────────────────────────────────── */
.bracket-team {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  min-height: 40px;
  transition: background .15s;
}

.bracket-team + .bracket-team {
  border-top: 1px solid #f1f5f9;
}

.bracket-team.winner {
  background: #eff6ff;
}
.bracket-team.winner .bracket-team-name {
  color: #1d4ed8;
  font-weight: 700;
}
.bracket-team.loser .bracket-team-name {
  color: #94a3b8;
}

/* Logo équipe */
.bracket-logo {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.bracket-initials {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #2563eb;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.bracket-team-name {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #1e293b;
}

.bracket-team-placeholder {
  flex: 1;
  font-size: 12px;
  color: #94a3b8;
  font-style: italic;
}

.bracket-score {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  font-size: 14px;
  font-weight: 700;
  color: #1e293b;
  min-width: 34px;
  text-align: right;
  white-space: nowrap;
}
.bracket-score.empty {
  color: #cbd5e1;
}

.bracket-score-leg {
  min-width: 10px;
  text-align: center;
}

.bracket-score-separator {
  color: #94a3b8;
  font-size: 11px;
  font-weight: 700;
}

/* ── Empty state ──────────────────────────────────── */
.bracket-empty {
  padding: 40px 20px;
  text-align: center;
  color: #94a3b8;
  font-size: 15px;
}

.bracket-layout-switch {
  display: inline-flex;
  align-items: center;
  padding: 4px;
  background: #e2e8f0;
  border-radius: 999px;
  gap: 4px;
  flex-wrap: wrap;
}

.bc-switch-btn {
  border: 0;
  background: transparent;
  color: #475569;
  font-weight: 700;
  padding: 9px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s, color .15s, box-shadow .15s;
}

.bc-switch-btn.active {
  background: #fff;
  color: #0f172a;
  box-shadow: 0 1px 4px rgba(15, 23, 42, .12);
}

.bracket-winner-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 120px;
  padding: 18px 16px;
  background: linear-gradient(180deg, #fff 0%, #f8fafc 100%);
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

.bracket-winner-card .bracket-logo {
  width: 42px;
  height: 42px;
}

.bracket-winner-name {
  font-size: 15px;
  font-weight: 700;
  color: #1e293b;
  text-align: center;
}

.bracket-winner-placeholder {
  font-size: 13px;
  color: #94a3b8;
  text-align: center;
}

.bracket-round-list--winner {
  position: relative;
  width: 100%;
}

.bracket-round-list--winner-center {
  min-width: 200px;
}

.bracket-final-card--positioned {
  position: absolute;
  z-index: 4;
  left: 50%;
  transform: translateX(-50%);
}

.bracket-winner-card--positioned {
  position: absolute;
  z-index: 4;
  left: 0;
  right: 0;
}

.bracket-winner-card--below-final {
  z-index: 3;
}

body.ranking-fullscreen .topbar {
  display: none;
}

body.ranking-fullscreen .sidebar {
  display: none;
}

body.ranking-fullscreen .content {
  margin-left: 0;
  padding: 14px 20px 28px;
}

body.ranking-fullscreen .page-header {
  margin-top: 0;
}

body.ranking-fullscreen #brackets-container {
  min-height: calc(100dvh - 180px);
}

body.ranking-fullscreen .bracket-wrapper {
  overflow: hidden;
}

.btn-fullscreen {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 9999;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #1e293b;
  color: #fff;
  border: 2px solid #fff;
  font-size: 18px;
  cursor: pointer;
  opacity: .8;
  transition: opacity .2s;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}

.btn-fullscreen:hover {
  opacity: 1;
}

@media (max-width: 960px) {
  .bracket-wrapper {
    padding-left: 0;
    padding-right: 0;
  }

  .bracket-double {
    grid-template-columns: auto 180px auto;
    gap: 10px;
  }

  .bracket-side,
  .bracket-side--left {
    flex-direction: row;
  }

  .bracket-side--right {
    flex-direction: row-reverse;
  }

  .bracket-round {
    min-width: 172px;
    padding: 0 10px;
  }

  .bracket-round--winner {
    min-width: 156px;
  }

  .bracket-match {
    width: 162px;
  }

  .bracket-match--two-legged {
    width: 176px;
  }

  .bracket-slot.has-connectors::before {
    left: -12px;
    width: 12px;
  }

  .bracket-slot.has-connectors::after {
    left: -12px;
  }

  .bracket-round--right .bracket-slot.has-connectors::before {
    right: -12px;
  }

  .bracket-round--right .bracket-slot.has-connectors::after {
    right: -12px;
  }

  .bracket-team {
    gap: 6px;
    padding: 7px 8px;
    min-height: 36px;
  }

  .bracket-logo {
    width: 20px;
    height: 20px;
  }

  .bracket-team-name {
    font-size: 12px;
  }

  .bracket-score {
    font-size: 13px;
    gap: 3px;
    min-width: 30px;
  }

  .bracket-score-separator {
    font-size: 10px;
  }

  .bracket-center {
    gap: 10px;
    padding-top: 0;
    min-width: 180px;
  }

  .bracket-center-title,
  .bracket-round-title {
    font-size: 10px;
    padding-bottom: 10px;
  }

  .bracket-winner-card {
    min-height: 104px;
    padding: 14px 10px;
  }

  .bracket-winner-card .bracket-logo {
    width: 34px;
    height: 34px;
  }

  .bracket-winner-name {
    font-size: 13px;
  }

  .bc-switch-btn {
    padding: 8px 12px;
    font-size: 13px;
  }

  body.ranking-fullscreen .content {
    padding: 12px 10px 18px;
  }
}
