:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-card-hover: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border);
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

.tournament-selector-container {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: var(--bg-card);
    padding: 0.25rem 0.5rem;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.tournament-selector-container label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
}

#tournamentSelect {
    background: transparent;
    border: none;
    font-size: 0.9rem;
    color: var(--text);
    padding: 2px 4px;
    cursor: pointer;
}

#newTournamentBtn {
    padding: 0 6px;
    font-size: 1.2rem;
    line-height: 1;
    min-width: 28px;
}

.card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
    transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(79, 70, 229, 0.15);
}

.card h2,
.card h3 {
    margin-bottom: 1rem;
    color: var(--text);
}

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

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-muted);
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
    transition: border-color 0.2s;
}

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

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-block;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
}

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

.btn-secondary:hover {
    background: #475569;
}

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

.btn-danger:hover {
    background: #dc2626;
}

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

.btn-success:hover {
    background: #059669;
}

.hidden {
    display: none !important;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.tournament-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.round-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.pairings-grid {
    display: grid;
    gap: 1rem;
}

.pairing-item {
    background: var(--bg);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.pairing-teams {
    flex: 1;
}

.team {
    font-weight: 600;
}

.team-aff {
    color: #60a5fa;
}

.team-neg {
    color: #f472b6;
}

.result-buttons {
    display: flex;
    gap: 0.5rem;
}

.result-buttons button {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

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

.standings-table th,
.standings-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.standings-table th {
    background: var(--bg);
    font-weight: 600;
    color: var(--text-muted);
}

.standings-table tr:hover {
    background: var(--bg-card-hover);
}

.text-muted {
    color: var(--text-muted);
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.875rem;
    font-weight: 600;
}

.badge-success {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
}

.badge-warning {
    background: rgba(251, 191, 36, 0.2);
    color: #fbbf24;
}

@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    header {
        flex-direction: column;
        gap: 1rem;
    }

    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    max-width: 400px;
    width: 90%;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal h3 {
    margin-bottom: 1rem;
    color: var(--text);
    font-size: 1.5rem;
}

.modal p {
    margin-bottom: 1.5rem;
    color: var(--text-muted);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* Tab Navigation */
.tabs {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0.5rem;
}

.tab-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1rem;
    font-weight: 600;
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--text);
    background: var(--bg-card-hover);
}

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

/* Tab Content */
.tab-content {
    display: none;
    animation: fadeIn 0.3s ease-out;
}

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

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Sub-tabs */
.sub-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.sub-tab-btn {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.5rem 1rem;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.sub-tab-btn:hover {
    color: var(--text);
    border-color: var(--primary);
}

.sub-tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Tab Content Container */
.tab-content-container {
    min-height: 300px;
}

/* New Round Button */
.tab-btn.new-round-btn {
    background: var(--success);
    color: white;
    font-weight: 700;
    font-size: 1.2rem;
    padding: 0.75rem 1.25rem;
}

.tab-btn.new-round-btn:hover {
    background: #059669;
    transform: translateY(-1px);
}

/* New Round Button */
.new-round-btn {
    font-weight: bold;
    font-size: 1.2rem;
    color: var(--success-color);
}

.new-round-btn:hover {
    background-color: #e8f5e9;
}

/* Correction Buttons */
.correction-buttons {
    display: inline-flex;
    gap: 5px;
    margin-left: 10px;
}

.btn-sm {
    padding: 2px 8px;
    font-size: 0.8rem;
    min-width: auto;
}

.btn-warning {
    background-color: #ffc107;
    color: #000;
}

.btn-warning:hover {
    background-color: #e0a800;
}

/* Team Links */
.team-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.team-link:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

/* Team Stats Grid */
.team-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border-radius: 8px;
    padding: 1.5rem;
    text-align: center;
}

.stat-label {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
}

/* Result Indicators */
.result-win {
    color: var(--success-color);
    font-weight: bold;
}

.result-loss {
    color: var(--danger-color);
    font-weight: bold;
}

/* Bracket Styles */
.bracket {
    display: flex;
    gap: 3rem;
    overflow-x: auto;
    padding: 2rem 0;
    align-items: center;
    /* Center align rounds vertically */
}

.bracket-round {
    display: flex;
    flex-direction: column;
    justify-content: center;
    /* Center matches within each round */
    min-width: 250px;
    position: relative;
}

.bracket-matches {
    display: flex;
    flex-direction: column;
    justify-content: center;
    /* Center matches vertically */
}

.bracket-round-label {
    font-size: 1.1rem;
    font-weight: 700;
    text-align: center;
    color: var(--primary);
    margin-bottom: 1.5rem;
    padding: 0.5rem;
    background: var(--bg);
    border-radius: 8px;
}

.bracket-match {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    position: relative;
}

/* Spacing between matches increases in earlier rounds to create convergence */
.bracket-round:nth-child(1) .bracket-match {
    margin-bottom: 1rem;
}

.bracket-round:nth-child(2) .bracket-match {
    margin-bottom: 3rem;
}

.bracket-round:nth-child(3) .bracket-match {
    margin-bottom: 7rem;
}

.bracket-round:nth-child(4) .bracket-match {
    margin-bottom: 15rem;
}

/* Add connecting lines */
.bracket-match::after {
    content: '';
    position: absolute;
    left: 100%;
    top: 50%;
    width: 3rem;
    height: 2px;
    background: var(--border);
    transform: translateY(-50%);
}

/* No line after the last round */
.bracket-round:last-child .bracket-match::after {
    display: none;
}

.bracket-team {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 8px;
    transition: all 0.2s;
    position: relative;
    z-index: 1;
}

.bracket-team:hover {
    background: var(--bg-card-hover);
    transform: translateX(-2px);
}

.bracket-team.winner {
    border-color: var(--success);
    background: rgba(16, 185, 129, 0.1);
    font-weight: 600;
}

.bracket-team.loser {
    opacity: 0.5;
    text-decoration: line-through;
}

.bracket-team .seed {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    background: var(--secondary);
    color: white;
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 700;
}

.bracket-team.winner .seed {
    background: var(--success);
}

.bracket-team .team-name {
    flex: 1;
}

.bracket-team .side-label {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    background: var(--bg-card);
    color: var(--text-muted);
    margin-left: 0.5rem;
}

.bracket-team .win-indicator {
    color: var(--success);
    font-size: 1.2rem;
    font-weight: 700;
}

/* Responsive bracket */
@media (max-width: 768px) {
    .bracket {
        flex-direction: column;
        gap: 2rem;
    }

    .bracket-round {
        min-width: 100%;
    }

    .bracket-match::after {
        display: none;
    }

    /* Reset spacing on mobile */
    .bracket-round:nth-child(1) .bracket-match,
    .bracket-round:nth-child(2) .bracket-match,
    .bracket-round:nth-child(3) .bracket-match,
    .bracket-round:nth-child(4) .bracket-match {
        margin-bottom: 1rem;
    }
}

/* Pairing Sections - Three Equal Boxes */
.pairing-sections {
    display: flex;
    align-items: stretch;
    gap: 1rem;
}

.team-section,
.match-section {
    flex: 1;
    padding: 0.75rem;
    border-radius: 8px;
    border: 2px solid var(--border);
    display: flex;
    flex-direction: column;
}

.team-aff-section {
    background: rgba(96, 165, 250, 0.05);
    border-color: rgba(96, 165, 250, 0.3);
}

.team-neg-section {
    background: rgba(244, 114, 182, 0.05);
    border-color: rgba(244, 114, 182, 0.3);
}

.match-section {
    background: rgba(139, 92, 246, 0.05);
    border-color: rgba(139, 92, 246, 0.3);
}

.team-header,
.match-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.side-label {
    color: var(--text-muted);
    font-weight: normal;
    font-size: 0.9rem;
}

.win-indicator {
    color: var(--success);
    font-size: 1.1rem;
    margin-left: auto;
}

.match-id {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.members-list,
.match-content {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
}

.match-content {
    justify-content: center;
}

.member-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.6rem;
    background: var(--bg);
    border-radius: 6px;
    font-size: 0.9rem;
    border: 1px solid transparent;
    transition: border-color 0.2s;
}

.member-item:hover {
    border-color: var(--border);
}

.member-name {
    flex: 1;
    color: var(--text);
}

.speaker-point-value {
    font-weight: 600;
    color: var(--success);
    min-width: 35px;
    text-align: right;
    font-size: 0.9rem;
}

.speaker-point-input-container {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.speaker-points-input-inline {
    width: 70px;
    padding: 0.3rem 0.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.85rem;
    transition: border-color 0.2s;
}

.speaker-points-input-inline:focus {
    outline: none;
    border-color: var(--primary);
}

/* Match Result Buttons and Status */
.result-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.result-status {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: center;
}

.result-winner {
    font-weight: 600;
    font-size: 1rem;
}

.correction-buttons {
    display: flex;
    gap: 0.5rem;
}

/* Participant Standings */
.participant-standings-section {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 2px solid var(--border);
}

.method-selector {
    padding: 0.5rem 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.2s;
}

.method-selector:focus {
    outline: none;
    border-color: var(--primary);
}

/* Responsive pairing teams */
@media (max-width: 768px) {
    .pairing-teams {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .vs-divider {
        text-align: center;
    }

    .members-list {
        margin-left: 0.5rem;
    }

    .member-item {
        flex-wrap: wrap;
    }

    .speaker-point-input-container {
        width: 100%;
        margin-top: 0.3rem;
    }
}

/* Judge Management Styles */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.judge-assignment {
    background: var(--bg);
    padding: 0.75rem;
    border-radius: 6px;
    font-size: 0.9rem;
}

.judge-assignment select {
    padding: 0.4rem;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    width: 100%;
    max-width: 200px;
}

.judge-assignment select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Highlight animation for match linking */
@keyframes highlightFade {
    0% {
        background-color: rgba(255, 255, 0, 0.5);
    }

    100% {
        background-color: transparent;
    }
}

.highlight-match {
    animation: highlightFade 3s ease-out;
    border: 2px solid #ffc107;
    /* Optional: add a border for better visibility */
}

/* Judge Autocomplete Styles */
.judge-autocomplete-container {
    position: relative;
    flex: 1;
}

.judge-search-input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-card);
    color: var(--text);
}

.judge-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 200px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    display: none;
}

.judge-result-item {
    padding: 0.5rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}

.judge-result-item:last-child {
    border-bottom: none;
}

.judge-result-item:hover {
    background: var(--bg-card-hover);
}

/* Loading Overlay */
#loadingOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(79, 70, 229, 0.1);
    border-top: 5px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

#loadingMessage {
    color: var(--text);
    font-weight: 500;
    font-size: 1.1rem;
}

/* Button Loading State */
.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn-loading::after {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    top: 50%;
    left: 50%;
    margin: -10px 0 0 -10px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Syncing Toast Indicator */
#syncIndicator {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--bg-card);
    border: 1px solid var(--primary);
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    z-index: 1500;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    transform: translateY(150%);
    opacity: 0;
}

#syncIndicator.visible {
    transform: translateY(0);
    opacity: 1;
}

.sync-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(79, 70, 229, 0.1);
    border-top: 2px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.sync-text {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text);
}

.sync-success-icon {
    color: #10b981;
    display: none;
}

#syncIndicator.sync-complete .sync-spinner {
    display: none;
}

#syncIndicator.sync-complete .sync-success-icon {
    display: block;
}

#syncIndicator.sync-complete {
    border-color: #10b981;
}

/* Hub Styles */
.hub-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.hub-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.tournament-card {
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.tournament-card:hover {
    border-color: var(--primary);
    transform: translateY(-4px);
    box-shadow: 0 10px 25px rgba(79, 70, 229, 0.2);
}

.tournament-card .tournament-id {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: monospace;
    text-transform: uppercase;
}

.tournament-card h3 {
    font-size: 1.25rem;
    color: var(--text);
    margin: 0;
}

.tournament-card .tournament-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.loading-placeholder {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
    font-style: italic;
}