@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Lexend:wght@400;600;800&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200');

/* ═══════════════════════════════════════════
   CSS VARIABLES — JDMRules Dark Theme
   ═══════════════════════════════════════════ */
:root {
  --bg: #04132b;
  --surface: #0b1c3d;
  --surface-low: #12264c;
  --surface-high: #1a305b;
  --surface-high-97: rgba(26, 48, 91, 0.97);
  --primary: #3fff8b;
  --primary-container: #1a5f33;
  --on-primary-container: #a8ffe1;
  --team: #4da6ff;
  --secondary: #feb300;
  --error: #ff5449;
  --error-container: #93000a;
  --on-surface: #ffffff;
  --on-surface-variant: #b0b5bd;
  --on-surface-variant-60: rgba(176, 181, 189, 0.6);
  --on-surface-variant-40: rgba(176, 181, 189, 0.4);
  --on-surface-variant-30: rgba(176, 181, 189, 0.3);
  --white-5: rgba(255, 255, 255, 0.05);
  --white-8: rgba(255, 255, 255, 0.08);
  --white-10: rgba(255, 255, 255, 0.1);
  --white-15: rgba(255, 255, 255, 0.15);
  --white-20: rgba(255, 255, 255, 0.2);
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-glow-green: 0 8px 24px rgba(63, 255, 139, 0.25);
  --shadow-glow-green-lg: 0 10px 30px rgba(63, 255, 139, 0.3);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 2rem;
}

/* ═══════════════════════════════════════════
   RESET & BASE
   ═══════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--on-surface);
  max-width: 430px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body.admin-body { max-width: 600px; }

.material-symbols-outlined {
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  vertical-align: middle;
}

/* ═══════════════════════════════════════════
   HEADER
   ═══════════════════════════════════════════ */
.app-header {
  background: linear-gradient(180deg, var(--bg) 0%, rgba(4, 19, 43, 0) 100%);
  color: white;
  padding: 1rem 1rem 0;
  position: static;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.5rem;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-brand .logo {
  width: 36px;
  height: 36px;
  background: var(--primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Lexend', sans-serif;
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--bg);
}

.header-brand .logo-img {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  object-fit: cover;
}

.header-author {
  font-size: 0.6rem;
  color: var(--on-surface-variant-60);
  font-weight: 500;
  margin-top: 0.15rem;
}

.header-brand h1 {
  font-family: 'Lexend', sans-serif;
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.3px;
}

.header-subtitle {
  font-size: 0.7rem;
  color: var(--primary);
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.header-subtitle .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.header-tennis {
  font-size: 1.5rem;
  filter: drop-shadow(0 0 6px rgba(63, 255, 139, 0.4));
}

.header-line {
  width: 100%;
  height: 1px;
  background: linear-gradient(90deg, var(--primary) 0%, rgba(63, 255, 139, 0.1) 50%, transparent 100%);
  margin-top: 0.5rem;
}

/* Admin header */
.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.5rem;
}

.admin-header h1 {
  font-family: 'Lexend', sans-serif;
  font-weight: 800;
  font-size: 1.15rem;
}

.tournament-select {
  background: var(--surface);
  border: 1px solid var(--white-10);
  color: var(--on-surface);
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  max-width: 220px;
}

.tournament-select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.tournament-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(63, 255, 139, 0.08);
  border: 1px solid rgba(63, 255, 139, 0.15);
  border-radius: var(--radius-md);
  padding: 0.5rem 0.75rem;
  margin: 0.5rem 0 0.25rem;
}

.tournament-bar-icon {
  font-size: 1.1rem;
  color: var(--primary);
}

.tournament-bar-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.tournament-select-bar {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--white-10);
  color: var(--on-surface);
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: 'Lexend', sans-serif;
  cursor: pointer;
  min-width: 0;
}

.tournament-select-bar:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.logout-btn {
  background: var(--white-8);
  border: 1px solid var(--white-10);
  color: var(--on-surface-variant);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: all 0.2s;
}

.logout-btn:active { transform: scale(0.96); }

/* ═══════════════════════════════════════════
   TAB NAVIGATION
   ═══════════════════════════════════════════ */
.tab-nav-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.tab-nav {
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  gap: 4px;
  scrollbar-width: none;
  scroll-behavior: smooth;
  padding: 0.5rem 0;
  width: 100%;
}

.tab-nav::-webkit-scrollbar { display: none; }

.tab-scroll-btn {
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--bg);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  z-index: 5;
  flex-shrink: 0;
  transition: opacity 0.2s ease;
}

.tab-scroll-btn.hidden { opacity: 0; pointer-events: none; }

.tab-nav button {
  flex-shrink: 0;
  background: var(--white-5);
  border: 1px solid var(--white-5);
  color: var(--on-surface-variant);
  padding: 0.5rem 0.85rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-xl);
  transition: all 0.25s ease;
  white-space: nowrap;
  font-family: 'Inter', sans-serif;
}

.tab-nav button.active {
  background: var(--primary);
  color: var(--bg);
  border-color: var(--primary);
  box-shadow: var(--shadow-glow-green);
  font-weight: 700;
}

.tab-nav button:active { transform: scale(0.96); }

/* ═══════════════════════════════════════════
   TAB CONTENT
   ═══════════════════════════════════════════ */
.tab-content {
  display: none;
  padding: 0.75rem 1rem 2rem;
  animation: fadeSlideIn 0.3s ease;
}

.tab-content.active { display: block; }

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════
   CARDS
   ═══════════════════════════════════════════ */
.card {
  background: var(--surface-high);
  border: 1px solid var(--white-5);
  border-radius: var(--radius-lg);
  padding: 1rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow-card);
}

 .card h3 {
  font-family: 'Lexend', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.6rem;
  color: var(--on-surface);
}

.collapse-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: var(--surface-low);
  border: 1px solid var(--white-5);
  border-radius: var(--radius-md);
  padding: 0.7rem 0.9rem;
  cursor: pointer;
  font-family: 'Lexend', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--on-surface);
  transition: background 0.15s ease;
}
.collapse-toggle:hover { background: var(--surface); }
.collapse-toggle-left { display: flex; align-items: center; gap: 0.45rem; }
.collapse-toggle .chevron { font-size: 1.3rem; transition: transform 0.2s ease; }
.collapse-toggle.open .chevron { transform: rotate(180deg); }
#j-form-body { margin-top: 0.85rem; }

/* ═══════════════════════════════════════════
   TABLES
   ═══════════════════════════════════════════ */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--white-5);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

th {
  padding: 0.65rem 0.5rem;
  text-align: left;
  background: var(--surface-low);
  color: var(--on-surface-variant);
  font-family: 'Lexend', sans-serif;
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

td {
  padding: 0.65rem 0.5rem;
  border-top: 1px solid var(--white-5);
  font-size: 0.85rem;
  color: var(--on-surface);
}

tr:first-child td { border-top: none; }

.col-pos { width: 2.5rem; text-align: center; }
.col-stat { width: 2rem; text-align: center; }
td.col-pos, td.col-stat { text-align: center; }

.col-player { text-align: left; }
.col-player-hint {
  font-size: 0.6rem;
  font-weight: 400;
  color: var(--on-surface-variant-40);
  margin-left: 0.35rem;
}
td.col-player { text-align: left; }

.player-link {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
}

.pl-name {
  color: var(--primary);
  transition: color 0.2s;
}

.player-link:hover .pl-name {
  color: #7dffb0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.pl-icon {
  font-size: 0.7rem;
  color: var(--on-surface-variant-40);
  transition: color 0.2s;
}

.player-link:hover .pl-icon {
  color: var(--primary);
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-family: 'Lexend', sans-serif;
  font-size: 0.7rem;
  font-weight: 800;
  background: var(--white-8);
  color: var(--on-surface-variant);
}

.rank-badge.gold {
  background: linear-gradient(135deg, #f9a825, #fdd835);
  color: #1a1a2e;
  box-shadow: 0 2px 8px rgba(249, 168, 37, 0.4);
}

.rank-badge.silver {
  background: linear-gradient(135deg, #90a4ae, #cfd8dc);
  color: #1a1a2e;
}

.rank-badge.bronze {
  background: linear-gradient(135deg, #8d6e63, #a1887f);
  color: white;
}

.rank-badge.qualify {
  background: #fdd835;
  color: #0B111F;
}

/* ═══════════════════════════════════════════
   EMPTY STATE
   ═══════════════════════════════════════════ */
.empty-state {
  text-align: center;
  padding: 2.5rem 1.5rem;
  color: var(--on-surface-variant-40);
}

.empty-state .material-symbols-outlined {
  font-size: 3rem;
  margin-bottom: 0.75rem;
  color: var(--on-surface-variant-30);
}

.empty-state p {
  font-size: 0.85rem;
  line-height: 1.4;
}

/* ═══════════════════════════════════════════
   BRACKET (LLAVE GRÁFICA)
   ═══════════════════════════════════════════ */
.bracket-round {
  background: var(--surface);
  border: 1px solid var(--white-5);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.bracket-round-header {
  background: var(--surface-low);
  color: var(--on-surface-variant);
  padding: 0.6rem 1rem;
  font-family: 'Lexend', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  text-align: center;
  border-bottom: 1px solid var(--white-5);
}

.bracket-match {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--white-5);
  gap: 0.75rem;
}

.bracket-match:first-of-type { border-top: none; }

.bracket-match-body { flex: 1; min-width: 0; }

.bracket-team {
  font-size: 0.82rem;
  padding: 0.15rem 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--on-surface-variant);
}

.bracket-team.winner {
  color: var(--primary);
  font-weight: 700;
}

.bracket-vs {
  font-size: 0.65rem;
  color: var(--on-surface-variant-30);
  text-transform: uppercase;
  font-weight: 600;
  padding: 0.1rem 0;
}

.bracket-score {
  font-family: 'Lexend', sans-serif;
  font-weight: 800;
  font-size: 1rem;
  color: var(--secondary);
  min-width: 3rem;
  text-align: center;
  background: var(--white-5);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.6rem;
}

.bracket-score.tbd {
  color: var(--on-surface-variant-30);
  font-size: 0.7rem;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
}

/* ═══════════════════════════════════════════
   RESULTADOS
   ═══════════════════════════════════════════ */
.resultado-card {
  background: var(--surface);
  border: 1px solid var(--white-5);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-lg);
  padding: 0.85rem 1rem;
  margin-bottom: 0.6rem;
  box-shadow: var(--shadow-card);
}

.resultado-card .r-match {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--on-surface);
}

.resultado-card .r-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.72rem;
}

.resultado-card .r-score {
  font-family: 'Lexend', sans-serif;
  font-weight: 800;
  color: var(--secondary);
  font-size: 0.85rem;
}

.resultado-card .r-fecha {
  color: var(--on-surface-variant-40);
}

.resultado-card .match-pair-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.25rem 0;
}
.resultado-card .match-pair-name {
  flex: 1;
  min-width: 0;
  font-family: 'Lexend', sans-serif;
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--on-surface);
  word-break: break-word;
  line-height: 1.3;
}
.resultado-card .match-pair-score {
  font-family: 'Lexend', sans-serif;
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--primary);
  text-align: right;
  flex-shrink: 0;
  min-width: 2rem;
}
.resultado-card .match-pair-name.team-blue { color: var(--team); }
.resultado-card .match-pair-name.team-gold { color: var(--secondary); }
.resultado-card .match-pair-score.team-blue { color: var(--team); }
.resultado-card .match-pair-score.team-gold { color: var(--secondary); }
.resultado-card .match-pair-name.state-win, .resultado-card .match-pair-score.state-win { color: var(--primary); }
.resultado-card .match-pair-name.state-lose, .resultado-card .match-pair-score.state-lose { color: var(--error); }
.resultado-card .match-pair-name.state-tie, .resultado-card .match-pair-score.state-tie { color: var(--secondary); }
.resultado-card .match-pair-divider {
  height: 1px;
  background: var(--white-5);
  margin: 0.1rem 0;
}
.resultado-card .r-meta {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  font-size: 0.72rem;
  margin-top: 0.3rem;
  padding-top: 0.25rem;
  border-top: 1px solid var(--white-5);
}

/* ═══════════════════════════════════════════
   FORMS (LOGIN & ADMIN)
   ═══════════════════════════════════════════ */
.login-container {
  max-width: 320px;
  margin: 2.5rem auto;
  padding: 1.75rem;
  background: var(--surface);
  border: 1px solid var(--white-5);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.login-container h2 {
  text-align: center;
  margin-bottom: 1.25rem;
  font-family: 'Lexend', sans-serif;
  font-weight: 800;
  font-size: 1.1rem;
}

.form-group {
  margin-bottom: 0.85rem;
}

.form-group label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--on-surface-variant);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  background: var(--surface-low);
  border: 1px solid var(--white-10);
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-family: 'Inter', sans-serif;
  color: var(--on-surface);
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.form-group input::placeholder { color: var(--on-surface-variant-40); }

.form-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%23b0b5bd'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(63, 255, 139, 0.15);
}

.form-row {
  display: flex;
  gap: 0.6rem;
}

.form-row .form-group { flex: 1; }

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
}

.checkbox-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.checkbox-group label {
  font-size: 0.85rem;
  text-transform: none;
  letter-spacing: 0;
  margin-bottom: 0;
  cursor: pointer;
  color: var(--on-surface);
}

/* ═══════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: 'Lexend', sans-serif;
  gap: 0.4rem;
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-container));
  color: var(--bg);
  box-shadow: var(--shadow-glow-green);
}
.btn-primary:hover { box-shadow: var(--shadow-glow-green-lg); }

.btn-success {
  background: linear-gradient(135deg, var(--primary), var(--primary-container));
  color: var(--bg);
  box-shadow: var(--shadow-glow-green);
}

.btn-danger {
  background: rgba(255, 84, 73, 0.15);
  color: var(--error);
  border: 1px solid rgba(255, 84, 73, 0.2);
}
.btn-danger:active { background: rgba(255, 84, 73, 0.25); }

.btn-warning {
  background: linear-gradient(135deg, var(--secondary), #e09200);
  color: var(--bg);
}

.btn-outline {
  background: transparent;
  color: var(--on-surface-variant);
  border: 1px solid var(--white-10);
}
.btn-outline:active { background: var(--white-5); }

.btn-sm {
  padding: 0.3rem 0.6rem;
  font-size: 0.72rem;
  border-radius: var(--radius-sm);
}

.btn-block { display: flex; width: 100%; }

.btn-group {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.btn-group-spaced {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.6rem;
}

/* ═══════════════════════════════════════════
   SCORE CONTROL (+/- BUTTONS)
   ═══════════════════════════════════════════ */
.score-control {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
}

.score-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  border: 1px solid var(--white-10);
  background: var(--white-8);
  color: var(--on-surface-variant);
  font-size: 1.4rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  font-family: 'Inter', sans-serif;
}

.score-btn:active {
  transform: scale(0.92);
  background: var(--white-15);
}

.score-btn.team-blue:active { background: rgba(77, 166, 255, 0.2); }
.score-btn.team-gold:active { background: rgba(254, 179, 0, 0.2); }

.score-value {
  font-family: 'Lexend', sans-serif;
  font-size: 2.2rem;
  font-weight: 800;
  min-width: 3.5rem;
  text-align: center;
  line-height: 1;
}

.score-value.blue { color: var(--team); text-shadow: 0 0 20px rgba(77, 166, 255, 0.3); }
.score-value.gold { color: var(--secondary); text-shadow: 0 0 20px rgba(254, 179, 0, 0.3); }

.score-label {
  font-family: 'Lexend', sans-serif;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  text-align: center;
  padding: 0.4rem 0;
  color: var(--on-surface-variant-60);
  border-top: 1px solid var(--white-5);
  margin-top: 0.25rem;
}

/* ═══════════════════════════════════════════
   TOAST
   ═══════════════════════════════════════════ */
.toast-container {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: var(--surface-high);
  color: var(--on-surface);
  padding: 0.7rem 1.4rem;
  border-radius: var(--radius-xl);
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: var(--shadow-card);
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.4s forwards;
  pointer-events: auto;
  text-align: center;
  border: 1px solid var(--white-10);
}

.toast.success {
  background: var(--primary-container);
  color: var(--on-primary-container);
  border-color: rgba(63, 255, 139, 0.2);
}

.toast.error {
  background: var(--error-container);
  color: white;
  border-color: rgba(255, 84, 73, 0.2);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(16px); }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ═══════════════════════════════════════════
   LOADING OVERLAY + TENNIS BALL SPINNER
   ═══════════════════════════════════════════ */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 19, 43, 0.85);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.tennis-ball-spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #c8e64e 0%, #a8c92a 50%, #8aad1a 100%);
  box-shadow: inset -4px -4px 8px rgba(0, 0, 0, 0.2), 0 0 16px rgba(168, 201, 42, 0.3);
  position: relative;
  animation: tennisBounce 0.8s ease-in-out infinite;
}

.tennis-ball-spinner::after {
  content: '';
  position: absolute;
  top: 6px;
  left: 8px;
  right: 8px;
  bottom: 6px;
  border: 2.5px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  border-left-color: transparent;
  border-right-color: transparent;
  transform: rotate(-30deg);
}

@keyframes tennisBounce {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-12px) scale(1.05); }
}

.loading-text {
  color: var(--text);
  font-family: 'Lexend', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
}

.panel-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  gap: 1rem;
}

.panel-loading .tennis-ball-spinner {
  width: 36px;
  height: 36px;
}

/* ═══════════════════════════════════════════
   ADMIN LINK
   ═══════════════════════════════════════════ */
.admin-link {
  color: var(--on-surface-variant-30);
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  transition: color 0.2s, background 0.2s;
}

.admin-link:hover {
  color: var(--primary);
  background: rgba(63, 255, 139, 0.08);
}

/* ═══════════════════════════════════════════
   ADMIN PANELS
   ═══════════════════════════════════════════ */
.admin-panel {
  display: none;
  padding: 0.75rem 1rem 2rem;
}

.admin-panel.active {
  display: block;
  animation: fadeSlideIn 0.3s ease;
}

.admin-section-title {
  font-family: 'Lexend', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--on-surface-variant);
  margin: 1.2rem 0 0.6rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--white-5);
}

.search-bar {
  position: relative;
  margin-bottom: 0.75rem;
}

.search-bar .search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
  color: var(--on-surface-variant-30);
  pointer-events: none;
}

.search-bar input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--white-10);
  border-radius: var(--radius-lg);
  padding: 0.65rem 1rem 0.65rem 2.5rem;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
}

.search-bar input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(63, 255, 139, 0.15);
}

.search-bar input::placeholder {
  color: var(--on-surface-variant-30);
}

/* ═══════════════════════════════════════════
   PLAYER CARD (ADMIN)
   ═══════════════════════════════════════════ */
.player-card {
  background: var(--surface);
  border: 1px solid var(--white-5);
  border-radius: var(--radius-lg);
  padding: 0.8rem 1rem;
  margin-bottom: 0.5rem;
  box-shadow: var(--shadow-card);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.player-card .player-main { flex: 1; min-width: 0; }

.player-card .player-name {
  font-family: 'Lexend', sans-serif;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--on-surface);
}

.player-card .player-meta {
  font-size: 0.72rem;
  color: var(--on-surface-variant-60);
  margin-top: 0.15rem;
}

.player-card .player-stats {
  display: flex;
  gap: 0.5rem;
  font-size: 0.7rem;
  color: var(--on-surface-variant-40);
  margin-top: 0.2rem;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-success {
  background: rgba(63, 255, 139, 0.12);
  color: var(--primary);
}

.badge-danger {
  background: rgba(255, 84, 73, 0.12);
  color: var(--error);
}

/* ═══════════════════════════════════════════
   MATCH FORM (ADMIN)
   ═══════════════════════════════════════════ */
.match-form {
  background: var(--surface);
  border: 1px solid var(--white-5);
  border-radius: var(--radius-lg);
  padding: 1rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow-card);
}

.match-form h3 {
  font-family: 'Lexend', sans-serif;
  font-weight: 800;
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.match-form .pair-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.match-form .pair-label.team-a { color: var(--team); }
.match-form .pair-label.team-b { color: var(--secondary); }

.match-form .pair-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
  align-items: center;
}

@media (max-width: 480px) {
  .match-form .pair-row {
    flex-direction: column;
  }
}

.match-form .pair-row select {
  flex: 1;
  padding: 0.55rem;
  background: var(--surface-low);
  border: 1px solid var(--white-10);
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  font-family: 'Inter', sans-serif;
  color: var(--on-surface);
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%23b0b5bd'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  padding-right: 1.8rem;
}

.match-form .pair-row select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(63, 255, 139, 0.1);
}

.match-form .vs-divider {
  font-family: 'Lexend', sans-serif;
  font-weight: 800;
  color: var(--on-surface-variant-30);
  font-size: 0.75rem;
  padding: 0 0.2rem;
}

.score-display-card {
  background: var(--surface-low);
  border: 1px solid var(--white-5);
  border-radius: var(--radius-lg);
  padding: 0.75rem;
  margin: 0.75rem 0;
}

.score-display-card .score-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
}

.score-display-card .score-row:first-child { border-bottom: 1px solid var(--white-5); }

.score-display-card .team-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.score-display-card .team-dot.blue { background: var(--team); }
.score-display-card .team-dot.gold { background: var(--secondary); }

.score-display-card .team-name {
  flex: 1;
  font-size: 0.82rem;
  font-weight: 600;
  min-width: 0;
}

.score-display-card .team-name.blue { color: var(--team); }
.score-display-card .team-name.gold { color: var(--secondary); }

/* ═══════════════════════════════════════════
   MATCH HISTORY ITEM (ADMIN)
   ═══════════════════════════════════════════ */
.match-item {
  background: var(--surface);
  border: 1px solid var(--white-5);
  border-radius: var(--radius-lg);
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  box-shadow: var(--shadow-card);
}

.match-item .match-info { flex: 1; min-width: 0; }

.match-item .match-teams {
  font-family: 'Lexend', sans-serif;
  font-weight: 600;
  font-size: 0.82rem;
}

.match-item .match-score-big {
  font-family: 'Lexend', sans-serif;
  font-weight: 800;
  font-size: 1.3rem;
  color: var(--primary);
  text-align: center;
  padding: 0.2rem 0;
  letter-spacing: 2px;
}

.match-item .match-vs {
  font-size: 0.7rem;
  color: var(--on-surface-variant-30);
  text-transform: uppercase;
  text-align: center;
  padding: 0.1rem 0;
}

.match-item .match-meta {
  font-size: 0.7rem;
  color: var(--on-surface-variant-40);
  margin-top: 0.15rem;
  text-align: center;
}

/* ── Match Pair Row Layout (Draw) ── */
.match-item .match-pair-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.3rem 0;
}
.match-item .match-pair-name {
  flex: 1;
  min-width: 0;
  font-family: 'Lexend', sans-serif;
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--on-surface);
  word-break: break-word;
  line-height: 1.3;
}
.match-item .match-pair-score {
  font-family: 'Lexend', sans-serif;
  font-weight: 800;
  font-size: 1.3rem;
  color: var(--primary);
  text-align: right;
  flex-shrink: 0;
  min-width: 2rem;
}
.match-item .match-pair-name.team-blue { color: var(--team); }
.match-item .match-pair-name.team-gold { color: var(--secondary); }
.match-item .match-pair-score.team-blue { color: var(--team); }
.match-item .match-pair-score.team-gold { color: var(--secondary); }
.match-item .match-pair-name.state-win, .match-item .match-pair-score.state-win { color: var(--primary); }
.match-item .match-pair-name.state-lose, .match-item .match-pair-score.state-lose { color: var(--error); }
.match-item .match-pair-name.state-tie, .match-item .match-pair-score.state-tie { color: var(--secondary); }
.match-item .match-pair-divider {
  height: 1px;
  background: var(--white-5);
  margin: 0.1rem 0;
}
.match-item .match-score-ctl {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
}
.match-item .match-score-ctl .score-btn {
  width: 34px;
  height: 34px;
  font-size: 1.1rem;
}
.match-item .match-meta {
  text-align: left;
  margin-top: 0.3rem;
  padding-top: 0.25rem;
  border-top: 1px solid var(--white-5);
}

/* ── Match Pair Row Layout (Resultados - .card) ── */
.card .match-pair-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.35rem 0;
}
.card .match-pair-name {
  flex: 1;
  min-width: 0;
  font-family: 'Lexend', sans-serif;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--on-surface);
  word-break: break-word;
  line-height: 1.3;
}
.draw-cnt {
  font-size: 0.7rem;
  color: var(--primary);
  font-weight: 700;
  white-space: nowrap;
}
.card .match-pair-score {
  font-family: 'Lexend', sans-serif;
  font-weight: 800;
  font-size: 1.5rem;
  color: var(--primary);
  text-align: right;
  flex-shrink: 0;
  min-width: 2.5rem;
}
.card .match-pair-name.team-blue { color: var(--team); }
.card .match-pair-name.team-gold { color: var(--secondary); }
.card .match-pair-score.team-blue { color: var(--team); }
.card .match-pair-score.team-gold { color: var(--secondary); }
.card .match-pair-name.state-win, .card .match-pair-score.state-win { color: var(--primary); }
.card .match-pair-name.state-lose, .card .match-pair-score.state-lose { color: var(--error); }
.card .match-pair-name.state-tie, .card .match-pair-score.state-tie { color: var(--secondary); }
.card .match-score-ctl .score-btn.team-blue { border-color: rgba(77, 166, 255, 0.3); color: var(--team); }
.card .match-score-ctl .score-btn.team-gold { border-color: rgba(254, 179, 0, 0.3); color: var(--secondary); }
.card .match-pair-divider {
  height: 1px;
  background: var(--white-5);
  margin: 0.1rem 0;
}
.card .match-score-ctl {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}
.card .match-score-ctl .score-btn {
  width: 38px;
  height: 38px;
  font-size: 1.2rem;
}
.card .match-meta {
  font-size: 0.7rem;
  color: var(--on-surface-variant-40);
  margin-top: 0.3rem;
  padding-top: 0.3rem;
  border-top: 1px solid var(--white-5);
  text-align: left;
}

.search-input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: var(--surface-low);
  border: 1px solid var(--white-10);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  color: var(--on-surface);
  margin-bottom: 0.75rem;
  outline: none;
  box-sizing: border-box;
}

.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(63, 255, 139, 0.1);
}

/* ═══════════════════════════════════════════
   PLAYER MATCH HISTORY MODAL
   ═══════════════════════════════════════════ */
.modal-wide {
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
}

.player-match-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.player-match-header .modal-title {
  font-family: 'Lexend', sans-serif;
  font-weight: 800;
  font-size: 1rem;
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--on-surface-variant);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
}

.modal-close-btn:hover {
  color: var(--on-surface);
}

.player-match-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.player-match-item {
  background: var(--surface-low);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
}

.player-match-item.resultado-card {
  background: var(--surface-low);
  border: none;
  border-left: none;
  margin-bottom: 0;
  padding: 0.65rem 0.75rem;
  box-shadow: none;
}

.player-match-item .match-round {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--on-surface-variant-50);
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.player-match-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--on-surface-variant-60);
  font-size: 0.85rem;
}

/* ═══════════════════════════════════════════
   MODAL / DIALOG
   ═══════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 19, 43, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--white-10);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-card);
  animation: modalSlideIn 0.25s ease;
}

@keyframes modalSlideIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal h3 {
  font-family: 'Lexend', sans-serif;
  font-weight: 800;
  margin-bottom: 1rem;
}

.modal .btn-group {
  justify-content: flex-end;
  margin-top: 1rem;
}

/* ═══════════════════════════════════════════
   FOOTER
   ═══════════════════════════════════════════ */
.app-footer {
  text-align: center;
  padding: 1.5rem 1rem;
  font-size: 0.7rem;
  color: var(--on-surface-variant-60);
  border-top: 1px solid rgba(255,255,255,0.05);
  margin-top: 2rem;
}

/* ═══════════════════════════════════════════
   SAFARI / iOS FIXES
   ═══════════════════════════════════════════ */
@supports (-webkit-touch-callout: none) {
  input, select, button {
    font-size: 16px !important;
  }
}

@media (max-width: 374px) {
  .tab-nav button {
    padding: 0.45rem 0.6rem;
    font-size: 0.72rem;
  }
  th, td {
    padding: 0.5rem 0.35rem;
    font-size: 0.78rem;
  }
}

/* ═══════════════════════════════════════════
   MOBILE RESPONSIVE IMPROVEMENTS
   ═══════════════════════════════════════════ */
@media (max-width: 640px) {
  /* Tab navigation - ensure all 7 tabs are accessible */
  .tab-nav {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.5rem;
  }
  .tab-nav button {
    scroll-snap-align: start;
    flex-shrink: 0;
    white-space: nowrap;
  }
  .tab-scroll-btn {
    display: none !important; /* Native scrolling is better on mobile */
  }

  /* Cards - full width with comfortable padding */
  .card {
    margin: 0.5rem 0;
    padding: 1rem;
  }
  .card[style*="border-left"] {
    border-left-width: 3px !important;
  }

  /* Form inputs - touch-friendly */
  input[type="number"],
  input[type="text"],
  input[type="email"],
  input[type="date"],
  select {
    font-size: 16px !important; /* Prevents zoom on iOS */
    padding: 0.75rem;
  }

  /* Button groups - stack on mobile */
  .btn-group-spaced {
    flex-direction: column;
    gap: 0.5rem;
  }
  .btn-group-spaced .btn {
    width: 100%;
  }

  /* Table responsive - horizontal scroll */
  .table-wrapper,
  .admin-panel > div,
  .panel-jugadores,
  .panel-equipos,
  .panel-resultados,
  .panel-posiciones,
  .panel-jornadas,
  .panel-semifinales,
  .panel-final,
  .panel-draw,
  .panel-torneos {
    overflow-x: auto;
  }

  /* Team badges in Equipos view */
  .badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
  }

  /* Result cards - stack on mobile */
  .resultado-card,
  .match-item {
    padding: 1rem;
    margin-bottom: 0.5rem;
  }
  .match-pair-row {
    flex-wrap: wrap;
  }
  .match-pair-name,
  .match-pair-score {
    flex: 1 1 100%;
    text-align: center;
  }
  .match-pair-divider {
    display: none;
  }

  /* Header - compact */
  .header-top {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .header-brand h1 {
    font-size: 1.25rem;
  }
  .header-subtitle {
    font-size: 0.75rem;
  }

  /* Tournament bar */
  .tournament-bar {
    order: 3;
    width: 100%;
    margin-top: 0.5rem;
  }
  .tournament-select-bar {
    width: 100%;
    font-size: 16px !important;
  }
}

/* Print styles */
@media print {
  .tab-nav, .btn, .admin-link, .tournament-bar, .btn-group-spaced {
    display: none !important;
  }
  .tab-content {
    display: block !important;
  }
  body {
    background: white;
    color: black;
  }
}

/* ═══════════════════════════════════════════
   CHAMPION CARD
   ═══════════════════════════════════════════ */
.champion-card {
  background: linear-gradient(135deg, var(--surface-high) 0%, var(--surface-low) 100%);
  border: 2px solid var(--secondary);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1rem;
  text-align: center;
  box-shadow: var(--shadow-card), 0 0 30px rgba(254, 179, 0, 0.15);
  margin-bottom: 0.75rem;
}
.champion-card .champion-trophy {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 0.25rem;
}
.champion-card .champion-title {
  font-family: 'Lexend', sans-serif;
  font-weight: 800;
  font-size: 1.3rem;
  color: var(--secondary);
  text-transform: uppercase;
  letter-spacing: 3px;
  margin-bottom: 0.5rem;
}
.champion-card .champion-name {
  font-family: 'Lexend', sans-serif;
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--on-surface);
  line-height: 1.4;
}
.champion-card .champion-score {
  font-size: 0.8rem;
  color: var(--on-surface-variant-60);
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--white-5);
}
