/* ── Bracket / Tree draw ───────────────────────────────────────────── */

.bracket-draw-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.bracket-view-toggle .btn {
  font-size: 0.82rem;
}

/* Section (main bracket or placement bracket) */
.bracket-section {
  margin-bottom: 1.5rem;
}

.bracket-section--placement {
  padding-top: 1rem;
  border-top: 1px solid rgba(15, 28, 23, 0.1);
}

.bracket-section-title {
  font-size: 0.92rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.bracket-section-toggle {
  font-size: 0.8rem;
  padding: 0;
}

/* Scroll wrapper */
.bracket-tree-scroll {
  overflow-x: auto;
  padding-bottom: 0.5rem;
}

/* The bracket grid: rounds as columns, matches as rows */
.bracket-tree {
  display: inline-flex;
  gap: 0;
  min-width: max-content;
}

/* Single round column */
.bracket-round {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  min-width: 220px;
}

.bracket-round-title {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.4rem 0.5rem;
  color: rgba(15, 28, 23, 0.55);
}

/* Matches column: vertically distribute matches evenly */
.bracket-round-matches {
  display: flex;
  flex-direction: column;
  flex: 1;
  justify-content: space-around;
}

/* Match wrapper: holds the match box + connector pseudo-elements */
.bracket-match-wrapper {
  display: flex;
  align-items: center;
  position: relative;
  padding: 6px 16px;
}

/* Connector: right line from match to next round */
.bracket-match-wrapper::after {
  content: '';
  position: absolute;
  right: 0;
  top: 50%;
  width: 16px;
  border-top: 2px solid rgba(15, 28, 23, 0.18);
}

/* Connector: left line from previous round into match */
.bracket-match-wrapper::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  width: 16px;
  border-top: 2px solid rgba(15, 28, 23, 0.18);
}

/* Hide left connector on first round, right connector on last round */
.bracket-round:first-child .bracket-match-wrapper::before {
  display: none;
}

.bracket-round:last-child .bracket-match-wrapper::after {
  display: none;
}

/* Vertical connector between pairs of matches feeding into next round.
   Applied via JS/Razor on even-indexed wrappers (top feeder of a pair). */
.bracket-match-wrapper--connector-top::after {
  height: calc(50% + 6px);
  top: 50%;
  border-right: 2px solid rgba(15, 28, 23, 0.18);
}

.bracket-match-wrapper--connector-bottom::after {
  height: calc(50% + 6px);
  bottom: 50%;
  top: auto;
  border-right: 2px solid rgba(15, 28, 23, 0.18);
}

/* The match box */
.bracket-match {
  border: 1px solid rgba(15, 28, 23, 0.18);
  border-radius: 4px;
  background: #fff;
  font-size: 0.82rem;
  width: 190px;
  flex-shrink: 0;
}

.bracket-match--bye {
  opacity: 0.55;
}

/* Game-by-game scores row above the player slots */
.bracket-game-scores {
  display: flex;
  gap: 0.3rem;
  padding: 2px 8px;
  font-size: 0.7rem;
  color: rgba(15, 28, 23, 0.5);
  border-bottom: 1px solid rgba(15, 28, 23, 0.08);
  background: rgba(15, 28, 23, 0.02);
  border-radius: 3px 3px 0 0;
}

.bracket-game {
  white-space: nowrap;
}

.bracket-game--win {
  color: var(--cui-success, #1b9e3e);
  font-weight: 600;
}

.bracket-game--loss {
  color: var(--cui-danger, #e55353);
}

/* Player slot (top / bottom) */
.bracket-slot {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 3px 8px;
  min-height: 24px;
  line-height: 1.25;
}

.bracket-slot-top {
  border-bottom: 1px solid rgba(15, 28, 23, 0.1);
}

/* Winner: green text + bold */
.bracket-slot.is-winner {
  font-weight: 600;
}

.bracket-slot.is-winner .bracket-player-name,
.bracket-slot.is-winner .bracket-match-score {
  color: var(--cui-success, #1b9e3e);
}

/* Loser: red text */
.bracket-slot.is-loser .bracket-player-name,
.bracket-slot.is-loser .bracket-match-score {
  color: var(--cui-danger, #e55353);
}

.bracket-slot--bye {
  color: rgba(15, 28, 23, 0.4);
  font-style: italic;
}

.bracket-seed {
  color: var(--cui-info, #3399ff);
  font-size: 0.72rem;
  font-weight: 600;
  flex-shrink: 0;
}

/* Match score (number of games won) before the flag */
.bracket-match-score {
  font-weight: 700;
  font-size: 0.82rem;
  min-width: 14px;
  text-align: center;
  flex-shrink: 0;
}

.bracket-player-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 120px;
}

.bracket-player-flag {
  width: 16px;
  height: 12px;
  flex-shrink: 0;
}

/* Winner box — shown after the final round */
.bracket-round--winner {
  min-width: auto;
}

.bracket-winner-box {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 6px 12px;
  background: linear-gradient(135deg, #f0faf3, #e8f5ec);
  border: 2px solid var(--cui-success, #1b9e3e);
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--cui-success, #1b9e3e);
}

.bracket-winner-box .bracket-player-name {
  max-width: 140px;
}

/* Compact mode for small brackets (1 round, 1-2 matches) */
.bracket-section--compact .bracket-tree {
  display: inline-flex;
}

.bracket-section--compact .bracket-round {
  min-width: auto;
}

.bracket-section--compact .bracket-match-wrapper::before,
.bracket-section--compact .bracket-match-wrapper::after {
  display: none;
}

/* Responsive: ensure horizontal scroll */
@media (max-width: 767.98px) {
  .bracket-round {
    min-width: 180px;
  }
  .bracket-match {
    width: 160px;
  }
  .bracket-player-name {
    max-width: 85px;
  }
}

/* Schedule tab overlay on bracket matches */
.bracket-schedule-info {
  display: flex;
  gap: 0.3rem;
  padding: 2px 6px;
  font-size: 0.7rem;
  border-top: 1px solid rgba(15, 28, 23, 0.08);
  background: rgba(13, 110, 253, 0.06);
  border-radius: 0 0 3px 3px;
}

.bracket-schedule-time {
  font-weight: 600;
  color: #0d6efd;
}

.bracket-schedule-court {
  color: rgba(15, 28, 23, 0.55);
}

.bracket-match--unassigned {
  border-style: dashed;
  opacity: 0.6;
}

/* ── End bracket / tree draw ──────────────────────────────────────── */
