/* ==========================================================================
   Bracket CSS — List & Tree bracket visualization
   Requires public.css variables
   ========================================================================== */

/* --- 1. Bracket View Switch --- */
.tp-bracket-switch {
  display: flex;
  background-color: var(--tp-border);
  border-radius: 20px;
  padding: 3px;
  margin: 12px 16px;
}

.tp-switch-btn,
.tp-gswitch-btn {
  flex: 1;
  padding: 8px 16px;
  border: none;
  background: none;
  border-radius: 17px;
  font-size: 13px;
  font-weight: 600;
  color: var(--tp-text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  text-align: center;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.tp-switch-btn.active,
.tp-gswitch-btn.active {
  background-color: var(--tp-primary);
  color: #FFFFFF;
  box-shadow: 0 2px 6px rgba(27, 42, 74, 0.25);
}

.tp-switch-btn:active:not(.active),
.tp-gswitch-btn:active:not(.active) {
  background-color: rgba(0, 0, 0, 0.05);
}

/* --- 2. Bracket / Groups Views Visibility --- */
.tp-bracket-view,
.tp-groups-view {
  display: none;
}

.tp-bracket-view.active,
.tp-groups-view.active {
  display: block;
}

/* --- 3. List View --- */
.tp-bracket-round {
  margin-bottom: 16px;
}

.tp-round-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--tp-primary);
  color: #FFFFFF;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 10px 16px;
}

.tp-round-header-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 600;
  min-width: 22px;
}

.tp-bracket-match {
  border-left: 3px solid var(--tp-border);
  padding: 12px 16px;
  background-color: var(--tp-card);
  border-bottom: 1px solid var(--tp-border);
  cursor: pointer;
  min-height: var(--tp-touch-min);
  transition: background-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.tp-bracket-match:active {
  background-color: #F1F5F9;
}

.tp-bracket-match.tp-match-finished {
  border-left-color: var(--tp-success);
}

.tp-bracket-match.tp-match-live {
  border-left-color: var(--tp-danger);
}

.tp-bracket-match.tp-match-scheduled {
  border-left-color: var(--tp-info);
}

.tp-bracket-match.tp-match-bye {
  border-left-color: var(--tp-text-muted);
}

/* Match label row */
.tp-bm-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 10px;
  color: var(--tp-text-muted);
}

.tp-bm-label-id {
  font-weight: 600;
  letter-spacing: 0.3px;
}

/* Match teams */
.tp-bm-teams {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tp-bm-team {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 26px;
}

.tp-bm-seed {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: var(--tp-bg);
  font-size: 9px;
  font-weight: 700;
  color: var(--tp-text-muted);
  flex-shrink: 0;
}

.tp-bm-name {
  flex: 1;
  font-size: 14px;
  color: var(--tp-text);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tp-bm-score {
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
  font-size: 14px;
  font-weight: 700;
  color: var(--tp-text);
  min-width: 24px;
  text-align: right;
  flex-shrink: 0;
}

/* Winner / Loser / TBD states */
.tp-bm-team.tp-team-winner .tp-bm-name {
  font-weight: 700;
}

.tp-bm-team.tp-team-winner .tp-bm-score {
  color: var(--tp-success);
}

.tp-bm-team.tp-team-loser .tp-bm-name {
  color: var(--tp-text-muted);
}

.tp-bm-team.tp-team-loser .tp-bm-score {
  color: var(--tp-text-muted);
}

.tp-bm-team.tp-team-tbd .tp-bm-name {
  font-style: italic;
  color: var(--tp-text-muted);
}

/* Advance label */
.tp-bm-advance {
  margin-top: 6px;
  font-size: 10px;
  color: var(--tp-success);
  font-weight: 600;
}

/* --- 4. Tree View --- */
.tp-tree-container {
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px;
  gap: 0;
  min-height: 300px;
}

.tp-tree-round {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  min-width: 180px;
}

.tp-tree-round-title {
  flex: 0 0 auto;            /* il titolo resta in alto, allineato tra i round */
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--tp-text-muted);
  padding-bottom: 12px;
  border-bottom: 2px solid var(--tp-border);
  margin-bottom: 12px;
}

/* Area match: cresce e distribuisce le partite in modo uniforme, così ogni
   blocco di un round è centrato rispetto ai due che lo alimentano. */
.tp-tree-matches {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}

.tp-tree-match {
  width: 170px;
  margin: 6px;
  min-height: 78px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background-color: var(--tp-card);
  border: 2px solid var(--tp-border);
  border-radius: 8px;
  cursor: pointer;
  overflow: hidden;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.tp-tree-match:hover {
  border-color: var(--tp-primary);
  box-shadow: var(--tp-shadow-lg);
  transform: translateY(-1px);
}

.tp-tree-match:active {
  transform: translateY(0);
}

.tp-tree-match.finished {
  border-color: var(--tp-success);
}

.tp-tree-match.live {
  border-color: var(--tp-danger);
}

/* Tree match label */
.tp-tree-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #F1F5F9;
  padding: 4px 8px;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--tp-text-muted);
  border-bottom: 1px solid var(--tp-border);
}

/* Tree match team rows */
.tp-tree-team {
  display: flex;
  align-items: center;
  font-size: 11px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--tp-border);
  gap: 6px;
}

.tp-tree-team:last-child {
  border-bottom: none;
}

.tp-tree-seed {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: var(--tp-bg);
  font-size: 8px;
  font-weight: 700;
  color: var(--tp-text-muted);
  flex-shrink: 0;
}

.tp-tree-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--tp-text);
}

.tp-tree-score {
  font-family: 'SF Mono', 'Menlo', monospace;
  font-size: 11px;
  font-weight: 700;
  color: var(--tp-text);
  flex-shrink: 0;
  min-width: 16px;
  text-align: right;
}

.tp-tree-team.tp-team-winner {
  background-color: rgba(251, 191, 36, 0.1);
}

.tp-tree-team.tp-team-winner .tp-tree-name {
  font-weight: 700;
}

.tp-tree-team.tp-team-winner .tp-tree-score {
  color: var(--tp-success);
}

.tp-tree-team.tp-team-tbd .tp-tree-name {
  font-style: italic;
  color: var(--tp-text-muted);
}

.tp-tree-team.tp-team-loser .tp-tree-name {
  color: var(--tp-text-muted);
}

.tp-tree-team.tp-team-loser .tp-tree-score {
  color: var(--tp-text-muted);
}

/* --- 5. SVG Connectors --- */
.tp-tree-connectors {
  flex-shrink: 0;
  width: 32px;
  position: relative;
  display: flex;
  align-items: stretch;
}

.tp-tree-connectors svg {
  width: 100%;
  height: 100%;
  display: block;
}

.tp-tree-connectors svg line,
.tp-tree-connectors svg path {
  stroke: var(--tp-text-muted);
  stroke-width: 1.5;
  fill: none;
}

/* --- 6. Champion Box --- */
.tp-champion {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 0 20px;
  min-width: 120px;
  text-align: center;
}

.tp-champion-trophy {
  font-size: 40px;
  line-height: 1;
  margin-bottom: 8px;
}

.tp-champion-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--tp-text-muted);
  margin-bottom: 4px;
}

.tp-champion-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--tp-success);
  word-break: break-word;
  max-width: 140px;
}

.tp-champion.tp-no-winner .tp-champion-name {
  color: var(--tp-text-muted);
  font-style: italic;
  font-weight: 500;
}

/* --- 7. Responsive (Desktop 1024px+) --- */
@media (min-width: 1024px) {
  .tp-tree-round {
    min-width: 200px;
  }

  .tp-tree-match {
    width: 190px;
  }

  .tp-tree-team {
    font-size: 12px;
    padding: 7px 10px;
  }

  .tp-tree-score {
    font-size: 12px;
  }

  .tp-tree-seed {
    width: 18px;
    height: 18px;
    font-size: 9px;
  }

  .tp-tree-label {
    font-size: 10px;
    padding: 5px 10px;
  }

  .tp-champion-name {
    font-size: 16px;
    max-width: 180px;
  }

  .tp-champion-trophy {
    font-size: 48px;
  }
}

/* --- 8. Tree view horizontal scroll hint --- */
.tp-tree-scroll-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 11px;
  color: var(--tp-text-muted);
}

.tp-tree-scroll-hint-arrow {
  animation: tp-hint-bounce 1.5s ease-in-out infinite;
}

@keyframes tp-hint-bounce {
  0%, 100% {
    transform: translateX(0);
  }
  50% {
    transform: translateX(4px);
  }
}

/* Hide scroll hint on desktop when bracket fits */
@media (min-width: 1024px) {
  .tp-tree-scroll-hint {
    display: none;
  }
}

/* ------------------------------------------------------------------
   Griglia punteggio nel tabellone (stessa della lista, versione compatta)
   ------------------------------------------------------------------ */
.tp-score-grid--bracket .tp-sg-name {
  font-size: 12px;
  padding: 3px 8px 3px 0;
  line-height: 1.25;
  /* Riserva sempre l'altezza di due righe-nome (coppia su due righe). Cosi le
     righe con una sola riga di testo (BYE / Da definire) restano alte come una
     coppia normale e tutte le card del tabellone hanno la stessa altezza. Il
     vertical-align: middle ereditato centra il testo singolo. */
  height: 2.5em;
}

.tp-score-grid--bracket .tp-sg-result {
  font-size: 14px;
  padding: 3px 8px;
}

.tp-score-grid--bracket .tp-sg-set {
  font-size: 11px;
  padding: 3px 4px;
}

.tp-score-grid--bracket .tp-tb {
  font-size: 8px;
}

/* Slot "BYE": avversario assente di una squadra passata di diritto. Sbiadito,
   in maiuscoletto, per distinguerlo da un "Da definire" ancora da assegnare. */
.tp-sg-bye .tp-sg-player {
  color: var(--tp-text-muted);
  font-style: italic;
  letter-spacing: 0.5px;
}

/* I match "bye" sono sintetici: non si aprono i dettagli (non hanno una partita
   reale), quindi niente cursore/effetti che facciano pensare a un click utile. */
.tp-bye-match,
.tp-bye-match:hover,
.tp-bye-match:active {
  cursor: default;
  transform: none;
  box-shadow: none;
}

/* Inset della griglia dentro le card ad albero (prima lo davano le righe). */
.tp-tree-match .tp-score-grid--bracket {
  padding: 12px 14px;
}

/* Card ad albero abbastanza larghe per ospitare nomi + risultato + parziali
   con il giusto margine dai bordi. */
.tp-tree-match {
  width: 240px;
}

@media (min-width: 1024px) {
  .tp-tree-match {
    width: 252px;
  }
}
