/* Reset e Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2196F3;
    --secondary-color: #4CAF50;
    --danger-color: #f44336;
    --warning-color: #ff9800;
    --bg-dark: #1a1a2e;
    --bg-medium: #16213e;
    --bg-light: #0f3460;
    --text-light: #ffffff;
    --text-muted: #b0b0b0;
    --border-color: #2d3561;
    --success-color: #4CAF50;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-medium) 100%);
    color: var(--text-light);
    min-height: 100vh;
    overflow-x: hidden;
}

.container {
    max-width: 1920px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px;
    background: linear-gradient(135deg, var(--bg-light) 0%, var(--bg-medium) 100%);
    border-radius: 15px;
    margin-bottom: 30px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
    min-height: 60px;
}

.header::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(33, 150, 243, 0.1) 0%, transparent 70%);
    animation: pulse 4s ease-in-out infinite;
    z-index: 0;
}

.header h1 {
    font-size: 2.5em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 3px;
    background: linear-gradient(45deg, #2196F3, #4CAF50);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    position: relative;
    z-index: 1;
    margin: 0;
    flex-shrink: 0;
}

.live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 6px 16px;
    background: rgba(244, 67, 54, 0.2);
    border-radius: 25px;
    border: 2px solid var(--danger-color);
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}

/* Ensure auth buttons are above decorative header background */
.auth-area {
    position: relative;
    z-index: 2;
    flex-shrink: 0;
}

.exit-button {
    padding: 8px 20px;
    background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(244, 67, 54, 0.3);
}

.exit-button:hover {
    background: linear-gradient(135deg, #d32f2f 0%, #b71c1c 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(244, 67, 54, 0.4);
}

/* Debug bar - now hidden by default */
.debug-bar {
    display: none !important;
}

.pulse {
    width: 12px;
    height: 12px;
    background: var(--danger-color);
    border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(1.2);
    }
}

/* Tournament Selector */
.tournament-selector {
    background: var(--bg-light);
    padding: 8px 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    min-height: 60px;
}

.tournament-selector label {
    font-size: 1.1em;
    font-weight: 600;
    margin: 0;
}

.tournament-selector select {
    padding: 8px 20px;
    font-size: 1em;
    border-radius: 8px;
    border: 2px solid var(--border-color);
    background: var(--bg-medium);
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 300px;
}

.tournament-selector select:hover {
    border-color: var(--primary-color);
}

.tournament-selector select:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.2);
}

/* Tabs */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
    flex-wrap: wrap;
    justify-content: center;
}

.tab-button {
    padding: 15px 30px;
    font-size: 1.2em;
    font-weight: 600;
    background: var(--bg-light);
    color: var(--text-light);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.tab-button:hover {
    background: var(--bg-medium);
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.tab-button.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    box-shadow: 0 5px 20px rgba(33, 150, 243, 0.4);
}

/* Content Sections */
.content {
    min-height: 60vh;
}

.section {
    display: none;
}

.section.active {
    display: block;
    animation: fadeIn 0.5s ease;
}

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

/* Groups Grid */
.groups-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 25px;
    margin-top: 20px;
}

.group-card {
    background: var(--bg-light);
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    border: 2px solid var(--border-color);
    transition: all 0.3s ease;
}

.group-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 32px rgba(33, 150, 243, 0.2);
    border-color: var(--primary-color);
}

.group-card h2 {
    font-size: 2em;
    margin-bottom: 20px;
    color: var(--primary-color);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.standings-table {
    width: 100%;
    border-collapse: collapse;
}

.standings-table thead {
    background: rgba(33, 150, 243, 0.2);
}

.standings-table th {
    padding: 12px 8px;
    text-align: left;
    font-size: 0.9em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.standings-table th:first-child {
    width: 40px;
    text-align: center;
}

.standings-table th:nth-child(2) {
    width: auto;
    min-width: 120px;
}

.standings-table th:not(:first-child):not(:nth-child(2)) {
    width: 40px;
    text-align: center;
}

.standings-table td {
    padding: 12px 6px;
    border-bottom: 1px solid var(--border-color);
    font-size: 1em;
}

.standings-table td:first-child {
    text-align: center;
}

.standings-table td:nth-child(2) {
    font-weight: 600;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 200px;
    min-width: 120px;
    line-height: 1.3;
}

.standings-table td:not(:first-child):not(:nth-child(2)) {
    text-align: center;
}

.standings-table tbody tr {
    transition: all 0.2s ease;
}

.standings-table tbody tr:hover {
    background: rgba(33, 150, 243, 0.1);
}

.standings-table tbody tr.qualified {
    background: rgba(76, 175, 80, 0.1);
    border-left: 4px solid var(--success-color);
}

.position-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 35px;
    height: 35px;
    background: var(--primary-color);
    border-radius: 50%;
    font-weight: bold;
    font-size: 1.1em;
}

.position-badge.first {
    background: gold;
    color: #000;
}

.position-badge.second {
    background: silver;
    color: #000;
}

.stats {
    display: flex;
    gap: 15px;
    font-size: 0.95em;
    color: var(--text-muted);
}

/* Calendar */
.calendar-filters {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-bottom: 25px;
}

.filter-btn {
    padding: 12px 30px;
    font-size: 1.1em;
    background: var(--bg-light);
    color: var(--text-light);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.filter-btn:hover {
    background: var(--bg-medium);
    border-color: var(--primary-color);
}

.filter-btn.active {
    background: var(--secondary-color);
    border-color: var(--secondary-color);
}

.calendar-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Calendar Grid Layout for Groups */
.calendar-grid {
    display: grid;
    gap: 20px;
    width: 100%;
}

.calendar-group-column {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.calendar-group-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: var(--text-light);
    padding: 12px 20px;
    border-radius: 10px;
    text-align: center;
    font-size: 1.3em;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    margin-bottom: 5px;
}

.match-card {
    background: var(--bg-light);
    border-radius: 12px;
    padding: 14px 18px; /* reduced padding to decrease card height */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28);
    border-left: 5px solid var(--primary-color);
    transition: all 0.2s ease;
}

.match-card:hover {
    transform: translateX(5px);
    box-shadow: 0 8px 24px rgba(33, 150, 243, 0.3);
}

.match-card.live {
    border-left-color: var(--danger-color);
    animation: liveBlink 2s ease-in-out infinite;
}

.match-card.completed {
    border-left-color: var(--success-color);
    opacity: 0.8;
}

@keyframes liveBlink {
    0%, 100% {
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    }
    50% {
        box-shadow: 0 8px 32px rgba(244, 67, 54, 0.5);
    }
}

.match-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px; /* smaller gap to reduce height */
}

.match-time {
    font-size: 1.05em;
    font-weight: 600;
    color: var(--primary-color);
}

.match-status {
    padding: 6px 15px;
    border-radius: 20px;
    font-size: 0.95em;
    font-weight: 600;
    text-transform: uppercase;
}

.match-status.scheduled {
    background: rgba(33, 150, 243, 0.2);
    color: var(--primary-color);
}

.match-status.live {
    background: rgba(244, 67, 54, 0.2);
    color: var(--danger-color);
}

.match-status.completed {
    background: rgba(76, 175, 80, 0.2);
    color: var(--success-color);
}

.match-teams {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 30px;
}

.team {
    flex: 1;
    text-align: center;
}

.team-name {
    font-size: 1.25em; /* reduced */
    font-weight: 700;
    margin-bottom: 6px;
}

.team-score {
    font-size: 2.2em; /* reduced */
    font-weight: 800;
    color: var(--primary-color);
}

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

.vs {
    font-size: 1.5em;
    font-weight: 600;
    color: var(--text-muted);
}

.match-info {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    color: var(--text-muted);
    font-size: 0.95em;
}

.match-field {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.match-group {
    opacity: 0.95;
}

/* Bracket */
.bracket-container {
    overflow-x: auto;
    padding: 20px;
    position: relative; /* needed to position SVG connectors overlay */
}

.bracket-round {
    margin-bottom: 40px;
}

.bracket-round h3 {
    font-size: 2em;
    color: var(--primary-color);
    margin-bottom: 20px;
    text-align: center;
    text-transform: uppercase;
}

.bracket-matches {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Bracket tree layout: columns for each round */
.bracket-columns {
    display: flex;
    gap: 30px;
    align-items: flex-start;
    padding: 10px 20px;
}

.bracket-column {
    min-width: 260px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.bracket-column .bracket-matches {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

 .bracket-match {
     background: var(--bg-light);
     border-radius: 10px;
     padding: 34px 20px 18px 20px; /* more top padding so badge doesn't overlap content */
     border: 2px solid var(--border-color);
     position: relative; /* anchor for the match-number badge */
 }

.bracket-match.final {
    border-color: gold;
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.3);
}

/* Vertical bracket layout: rounds stacked top -> bottom, matches in each round laid out horizontally */
.bracket-rows {
    display: flex;
    flex-direction: column;
    gap: 40px;
    padding: 10px 20px;
}

.bracket-row {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.bracket-row .round-header {
    width: 100%;
    text-align: center;
}

.bracket-row .round-matches {
    display: flex;
    gap: 24px;
    justify-content: center;
    flex-wrap: wrap; /* allow matches to wrap onto multiple rows instead of horizontal scrolling */
    overflow-x: visible; /* avoid horizontal slide — let content wrap */
    padding: 6px 4px;
}

/* two-rows mode: the container holds two horizontal rows stacked vertically */
.bracket-row .round-matches.two-rows {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.bracket-row .round-matches-row {
    display: flex;
    gap: 24px;
    justify-content: center;
    flex-wrap: nowrap; /* keep items in the row; balanced by JS */
}

.bracket-row .bracket-match {
    min-width: 300px;
    max-width: 380px;
}

/* Connector SVG removed: no connector overlay styles needed */

.bracket-team {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    margin: 5px 0;
    background: var(--bg-medium);
    border-radius: 6px;
}

.bracket-team.winner {
    background: rgba(76, 175, 80, 0.2);
    border-left: 4px solid var(--success-color);
    font-weight: bold;
}

.bracket-team-name {
    font-size: 1.3em;
}

.match-number {
    position: absolute;
    top: -12px; /* place slightly outside the card so it doesn't overlap content */
    right: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 28px;
    padding: 0 8px;
    background: rgba(255, 215, 0, 0.12); /* subtle gold background as before */
    color: #FFD700; /* gold text */
    border-radius: 10px;
    border: 1px solid rgba(255, 215, 0, 0.25);
    box-shadow: 0 4px 12px rgba(0,0,0,0.18);
    font-weight: 700;
    font-size: 0.9em;
    z-index: 6;
}

/* alternative smaller badge style when used on compact layouts */
.bracket-match.small .match-number {
    min-width: 32px;
    height: 24px;
    font-size: 0.82em;
    right: 10px;
    top: -10px;
}

/* Inline badge used next to Campo */
.match-number-inline {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
    min-width: 34px;
    height: 24px;
    padding: 0 8px;
    background: rgba(255, 215, 0, 0.12);
    color: #FFD700;
    border-radius: 12px;
    border: 1px solid rgba(255, 215, 0, 0.22);
    font-weight: 700;
    font-size: 0.85em;
}

.bracket-team-score {
    font-size: 1.5em;
    font-weight: bold;
    color: var(--primary-color);
}

/* Split View */
.split-view {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}

.split-view h2 {
    font-size: 2em;
    color: var(--primary-color);
    margin-bottom: 20px;
    text-align: center;
    text-transform: uppercase;
}

.groups-grid-compact {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.groups-grid-compact .group-card {
    padding: 20px;
}

.groups-grid-compact .group-card h2 {
    font-size: 1.5em;
}

.groups-grid-compact .standings-table td {
    padding: 10px 8px;
    font-size: 1em;
}

.calendar-container-compact .match-card {
    padding: 20px;
}

.calendar-container-compact .team-name {
    font-size: 1.4em;
}

.calendar-container-compact .team-score {
    font-size: 2em;
}

/* Footer */
.footer {
    margin-top: 50px;
    padding: 20px;
    text-align: center;
    background: var(--bg-light);
    border-radius: 10px;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Loading */
.loading {
    text-align: center;
    padding: 60px 20px;
    font-size: 1.5em;
    color: var(--text-muted);
}

.loading::after {
    content: '...';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0%, 20% {
        content: '.';
    }
    40% {
        content: '..';
    }
    60%, 100% {
        content: '...';
    }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state h3 {
    font-size: 2em;
    margin-bottom: 15px;
}

.empty-state p {
    font-size: 1.2em;
}

/* Responsive */
@media (max-width: 1200px) {
    .split-view {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .header h1 {
        font-size: 2.5em;
    }
    
    .groups-grid {
        grid-template-columns: 1fr;
    }
    
    .tabs {
        flex-direction: column;
    }
    
    .match-teams {
        flex-direction: column;
        gap: 15px;
    }
}

/* Login Dialog */
.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.dialog-content {
    background: var(--bg-light);
    border-radius: 15px;
    padding: 40px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
}

.dialog-content h2 {
    margin-bottom: 30px;
    text-align: center;
    color: var(--primary-color);
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-light);
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 12px 15px;
    background: var(--bg-dark);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-light);
    font-size: 16px;
    transition: border-color 0.3s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.dialog-buttons {
    display: flex;
    gap: 15px;
    margin-top: 30px;
}

.btn-primary, .btn-secondary {
    flex: 1;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: #1976D2;
    transform: translateY(-2px);
}

.btn-secondary {
    background: var(--bg-dark);
    color: var(--text-light);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-medium);
}

.error-message {
    margin-top: 15px;
    padding: 12px;
    background: rgba(244, 67, 54, 0.2);
    border-left: 4px solid var(--danger-color);
    border-radius: 4px;
    color: var(--text-light);
}
