:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #10b981;
    --secondary-hover: #059669;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --bg-color: #0f172a;
    --text-color: #f8fafc;
    --text-muted: #94a3b8;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

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

html {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-color);
    background-image: radial-gradient(circle at 15% 50%, rgba(59, 130, 246, 0.15), transparent 25%),
                      radial-gradient(circle at 85% 30%, rgba(16, 185, 129, 0.15), transparent 25%);
    background-attachment: fixed;
    color: var(--text-color);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.glass-panel {
    background: #1e293b;
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    border-radius: 16px;
}

/* Screens */
.screen {
    display: none;
    flex: 1;
    min-height: 0;
}

.screen.active {
    display: flex;
}

/* Login */
#login-screen {
    justify-content: center;
    align-items: center;
}

.login-card {
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-card h1 {
    margin-bottom: 0.5rem;
    font-size: 1.8rem;
}

.login-card p {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.input-group {
    margin-bottom: 1.5rem;
    text-align: left;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

input, select {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    background: rgba(15, 23, 42, 0.6);
    color: var(--text-color);
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.3s ease;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

/* Hide number input arrows */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
}

/* Custom Number Spinner */
.custom-number-input {
    display: flex;
    align-items: stretch;
    flex: 1;
    min-width: 120px;
}
.custom-number-input input {
    border-radius: 0;
    border-left: none;
    border-right: none;
    text-align: center;
    flex: 1;
    min-width: 0;
}
.custom-number-input .spin-btn {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--glass-border);
    color: var(--text-color);
    padding: 0 0.75rem;
    cursor: pointer;
    font-size: 1.2rem;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.custom-number-input .spin-btn:first-child {
    border-radius: 8px 0 0 8px;
    border-right: 1px solid rgba(255,255,255,0.05);
}
.custom-number-input .spin-btn:last-child {
    border-radius: 0 8px 8px 0;
    border-left: 1px solid rgba(255,255,255,0.05);
}
.custom-number-input .spin-btn:hover {
    background: rgba(59, 130, 246, 0.3);
}

option {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 1rem;
    padding: 0.5rem;
}

/* Custom Select */
.custom-select-container {
    position: relative;
    width: 100%;
}

.custom-select-trigger {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    background: rgba(15, 23, 42, 0.6);
    color: var(--text-color);
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
}

.custom-select-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 1rem;
    color: var(--text-color);
    text-align: left;
}

.custom-select-trigger:after {
    content: "▼";
    font-size: 0.8rem;
    color: var(--text-muted);
    transition: transform 0.3s ease;
}

.custom-select-container.open .custom-select-trigger:after {
    transform: rotate(180deg);
}

.custom-select-container.open {
    z-index: 10000;
}

.custom-select-container.open .custom-select-trigger {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

.custom-options {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    right: 0;
    background: #0f172a;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    z-index: 9999;
    max-height: 250px;
    overflow-y: auto;
    display: none;
}

.custom-select-container.open .custom-options {
    display: block;
    animation: fadeInDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.custom-option {
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background 0.2s ease;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-color);
}

.custom-option:last-child {
    border-bottom: none;
}

.custom-option:hover:not(.disabled), .custom-option.selected {
    background: rgba(59, 130, 246, 0.2);
}

.custom-option.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.custom-options::-webkit-scrollbar {
    width: 6px;
}
.custom-options::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

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

button,
.nav-links li,
.custom-select-trigger,
.match-card,
.bracket-match,
.draggable-item {
    -webkit-tap-highlight-color: transparent;
}

button:focus,
.nav-links li:focus,
.custom-select-trigger:focus,
.match-card:focus,
.bracket-match:focus,
.draggable-item:focus {
    outline: none;
}

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

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

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}
.btn-secondary:hover { background: rgba(255, 255, 255, 0.2); }

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

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    width: auto;
}

.error-msg {
    color: #ef4444;
    margin-top: 1rem;
    font-size: 0.9rem;
}

/* Dashboard Layout */
#dashboard-screen.layout-col {
    flex-direction: column;
}

.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    margin: 1rem 1rem 0 1rem;
}

.top-nav .logo {
    margin-bottom: 0;
    border-bottom: none;
    padding-bottom: 0;
}

.top-nav .btn {
    width: auto;
}

.dashboard-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.sidebar {
    width: 250px;
    margin: 1rem;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}



.sidebar-title {
    margin-bottom: 1.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 0.5rem;
}

.classes-toggle {
    display: none;
}

.sidebar-filters {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
    overflow-y: auto;
    
    /* Hide scrollbar */
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}

.sidebar-filters::-webkit-scrollbar {
    display: none; /* Chrome, Safari and Opera */
}

.sidebar-filters .filter-btn {
    width: 100%;
}

.logo {
    text-align: center;
}

.nav-links {
    list-style: none;
}

.nav-links.horizontal {
    display: flex;
    gap: 1rem;
    margin-bottom: 0;
}

.nav-links li {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    color: var(--text-muted);
    font-weight: 500;
}

.nav-links li:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-color);
}

.nav-links li.active {
    background: rgba(59, 130, 246, 0.2);
    color: var(--primary-color);
}

.btn-logout { margin-top: auto; }

.flex-1 {
    flex: 1;
    overflow-y: auto;
    min-width: 0;
}

.content {
    padding: 1rem 1rem 0 0;
    margin-bottom: 1rem;
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

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

.flex-layout {
    display: none;
    flex: 1;
    min-width: 0;
}

.flex-layout.active {
    display: flex;
}

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

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

.header-action .btn { width: auto; }

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

.class-column {
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem;
}

.class-column h3 {
    margin-bottom: 1rem;
    color: var(--primary-color);
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 0.5rem;
}

.table-container {
    overflow-x: auto;
}

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

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

.data-table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.data-table tbody tr {
    transition: background 0.2s;
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.groups-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.small-table th, .small-table td {
    padding: 0.5rem;
    font-size: 0.85rem;
}

.two-col-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 2rem;
    align-items: start;
}

@media (max-width: 1024px) {
    .two-col-layout {
        grid-template-columns: 1fr;
    }
}

.group-card {
    padding: 1rem;
    border-radius: 12px;
}

.group-card h4 {
    margin-bottom: 1rem;
    text-align: center;
    color: var(--primary-color);
    background: rgba(0,0,0,0.2);
    padding: 0.5rem;
    border-radius: 6px;
}

/* Drag and Drop Lists */
.draggable-list {
    list-style: none;
    min-height: 150px;
    padding: 0.5rem;
    border-radius: 8px;
    background: rgba(0,0,0,0.1);
    transition: background 0.2s;
}

.draggable-list.drag-over {
    background: rgba(59, 130, 246, 0.2);
    border: 1px dashed var(--primary-color);
}

.draggable-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.8rem;
    margin-bottom: 0.5rem;
    border-radius: 6px;
    cursor: grab;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: transform 0.2s;
}

.draggable-item:active {
    cursor: grabbing;
}

.draggable-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.no-matches {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    min-height: 200px;
    color: var(--text-muted);
    font-size: 1.2rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

/* Matches */
.league-filters {
    display: flex;
    gap: 0.5rem;
}

.filter-btn {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    width: 150px; /* Uniform size */
}
.filter-btn.active {
    background: var(--primary-color);
    color: white;
}

.league-content {
    padding: 1.5rem;
}

.actions-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.actions-row .btn { width: auto; }

.two-col-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.leaderboard-section h4, .matches-section h4 {
    margin-bottom: 1rem;
    color: var(--text-muted);
}

/* Match Cards */
.matches-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.match-card {
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.match-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    border-color: rgba(59, 130, 246, 0.5);
}

.match-teams {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-weight: 600;
    font-size: 1.1rem;
}

.match-score {
    background: rgba(0,0,0,0.3);
    padding: 0.3rem 0.8rem;
    border-radius: 6px;
    font-variant-numeric: tabular-nums;
}

.match-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.3rem;
}

.badge {
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge.scheduled { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.badge.finished { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.badge.playoff { background: rgba(168, 85, 247, 0.2); color: #c084fc; border: 1px solid rgba(168, 85, 247, 0.5); }

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

#delete-match-modal {
    z-index: 1100;
}

.modal {
    width: 100%;
    max-width: 400px;
    padding: 2rem;
    transform: translateY(20px);
    transition: transform 0.3s;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal.large-modal {
    max-width: 600px;
}

.modal h3 { margin-bottom: 1.5rem; }

.modal-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}

.modal-actions.right-align {
    justify-content: flex-end;
}

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

.checkbox-group input { width: auto; }
.checkbox-group label { margin-bottom: 0; }

/* Match Details Specifics */
.match-details-header {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--glass-border);
}

.match-score-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: baseline; /* Align text baselines perfectly */
    gap: 1.5rem;
    width: 100%;
}

#details-match-team1 {
    text-align: right;
}

#details-match-team2 {
    text-align: left;
}

.team-name {
    margin: 0;
    padding: 0;
    font-size: 1.5rem;
    white-space: nowrap;
}

.match-details-header .match-score { 
    font-size: 1.5rem; 
    font-weight: bold; 
    white-space: nowrap; 
}

.status-absolute {
    position: absolute;
    top: 0;
    right: 0;
}

.match-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.add-event-form {
    background: rgba(0,0,0,0.2);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.add-event-form h4 { margin-bottom: 0.8rem; font-size: 1rem; color: var(--text-muted); }

.inline-form {
    display: flex;
    gap: 0.5rem;
}
.inline-form select { flex: 2; }
.inline-form input { flex: 1; min-width: 80px; }
.inline-form .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    padding: 0.5rem 1rem;
    font-size: 1.2rem;
    line-height: 1;
}

#event-form .event-submit {
    display: flex;
    flex-basis: 100%;
    justify-content: center;
}

.events-list-container h4 { margin-bottom: 1rem; color: var(--text-muted); }

.events-list {
    list-style: none;
    max-height: 250px;
    overflow-y: auto;
}

.event-item {
    display: flex;
    align-items: center;
    padding: 0.8rem;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    gap: 1rem;
}

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

.event-time {
    font-weight: 600;
    color: var(--primary-color);
    width: 40px;
}

.event-icon { font-size: 1.2rem; }
.event-player { flex: 1; font-weight: 500; }
.event-class { color: var(--text-muted); font-size: 0.9rem; }
.btn-delete-event {
    background: transparent; border: none; color: var(--danger-color); cursor: pointer; font-size: 1.2rem; padding: 0 0.5rem;
}
.btn-delete-event:hover { color: var(--danger-hover); }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,0.1); border-radius: 4px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.3); }

@media (max-width: 768px) {
    #dashboard-screen { flex-direction: column; }
    .sidebar { width: auto; margin: 1rem 1rem 0 1rem; }
    .nav-links { display: flex; gap: 0.5rem; }
    .nav-links li { margin: 0; text-align: center; flex: 1; }
    .two-col-layout { grid-template-columns: 1fr; }
    .inline-form { flex-wrap: wrap; }
    .inline-form select, .inline-form input { flex: 1 1 100%; }
}

.inline-form {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.inline-form .custom-select-container,
.inline-form input {
    flex: 1;
    min-width: 150px;
}
.bracket-wrapper {
    overflow-x: auto;
    padding-bottom: 2rem;
}

.bracket-rounds {
    display: flex;
    position: relative;
    align-items: stretch;
    justify-content: flex-start;
    gap: 3rem;
    min-width: max-content;
    padding: 1rem;
}

.bracket-column {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    gap: 2rem;
    min-width: 220px;
    position: relative;
}

.round-title {
    text-align: center;
    margin: 0 0 1rem 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.bracket-match {
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 0.5rem;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
    position: relative;
    z-index: 2;
}

.bracket-match:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    background: rgba(30, 41, 59, 0.6);
}

.bracket-team {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    border-radius: 4px;
}

.bracket-team.winner {
    background: rgba(59, 130, 246, 0.2);
    font-weight: 600;
}

.bracket-team:first-child {
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.team-score {
    background: rgba(0,0,0,0.3);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.9rem;
}

/* Vertical lines are harder generically without knowing exact heights, but we can do a simplified connecting line */

@media (max-width: 768px) {
    .top-nav {
        flex-wrap: wrap;
        gap: 0.75rem;
        padding: 1rem;
    }

    .top-nav .logo,
    .top-nav .nav-links,
    .top-nav .btn-logout {
        width: 100%;
    }

    .top-nav .btn-logout {
        margin-top: 0;
    }

    .dashboard-body {
        display: block;
        overflow-y: auto;
    }

    .flex-layout.active {
        flex-direction: column;
    }

    .sidebar {
        width: auto;
        margin: 1rem;
        padding: 1rem;
    }

    .sidebar-filters {
        flex-direction: row;
        flex-wrap: wrap;
        overflow: visible;
    }

    .sidebar-filters .filter-btn {
        flex: 1 1 120px;
        width: auto;
    }

    .content {
        padding: 0 1rem;
        margin-bottom: 1rem;
        overflow: visible;
    }

    .header-action,
    .actions-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .header-action .btn,
    .actions-row .btn {
        width: 100%;
    }

    .actions-row > div,
    .bracket-tabs {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem !important;
    }

    .actions-row > div .btn,
    .bracket-tabs .btn {
        flex: 1 1 160px;
    }

    .classes-grid,
    .groups-grid {
        grid-template-columns: 1fr;
    }

    .inline-form .custom-select-container,
    .inline-form input {
        flex: 1 1 100%;
        min-width: 0;
    }

    .modal-overlay {
        align-items: flex-start;
        overflow-y: auto;
        padding: 1rem;
    }

    .modal,
    .modal.large-modal {
        max-width: none;
        max-height: calc(100vh - 2rem);
        margin: auto 0;
        overflow-y: auto;
        padding: 1.25rem;
    }

    .modal-actions {
        flex-direction: column-reverse;
    }

    /* Compact header that always fits a narrow phone screen. */
    .top-nav {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        margin: 0.5rem;
        border-radius: 12px;
    }

    .top-nav .logo h2 {
        font-size: 1.15rem;
        line-height: 1.25;
    }

    .nav-links.horizontal {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.5rem;
    }

    .nav-links li {
        min-width: 0;
        padding: 0.65rem 0.35rem;
        font-size: 0.8rem;
        overflow-wrap: anywhere;
    }

    #dashboard-screen,
    .dashboard-body,
    .tab-content,
    .content {
        min-width: 0;
        max-width: 100%;
    }

    .league-content {
        padding: 1rem;
    }

    .match-score-row {
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
        gap: 0.75rem;
    }

    .team-name,
    .header-action h2,
    .actions-row h3 {
        overflow-wrap: anywhere;
    }

    .sidebar {
        align-self: stretch;
        flex: none;
    }

    #students-sidebar .sidebar-title {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
    }

    #students-sidebar {
        position: relative;
        z-index: 5;
        overflow: visible;
    }

    .classes-toggle {
        display: inline-block;
        flex: none;
        padding: 0.35rem 0.6rem;
        border: 1px solid var(--glass-border);
        border-radius: 6px;
        background: rgba(255, 255, 255, 0.08);
        color: var(--text-color);
        cursor: pointer;
    }

    #students-sidebar.is-collapsed .sidebar-filters {
        display: none;
    }

    #students-sidebar .sidebar-filters {
        position: absolute;
        top: calc(100% + 0.5rem);
        right: 0;
        left: 0;
        z-index: 10;
        flex: none;
        flex-direction: column;
        max-height: min(50vh, 260px);
        overflow-y: auto;
        padding: 0.75rem;
        background: var(--glass-bg);
        border: 1px solid var(--glass-border);
        border-radius: 12px;
        box-shadow: var(--glass-shadow);
    }

    #matches-tab .league-filters {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.35rem;
    }

    #matches-tab .league-filters .filter-btn {
        width: 100%;
        min-width: 0;
        padding: 0.65rem 0.1rem;
        font-size: 0.64rem;
        white-space: nowrap;
    }

    .leaderboard-section .group-card {
        min-width: 0;
        overflow-x: auto;
    }

    .leaderboard-section .group-card .small-table {
        min-width: 360px;
    }

    #students-tab .table-container {
        overflow: visible;
        background: transparent;
        border: none;
        box-shadow: none;
    }

    #students-table,
    #students-table tbody,
    #students-table tr,
    #students-table td {
        display: block;
        width: 100%;
    }

    #students-table thead {
        display: none;
    }

    #students-table tbody {
        display: grid;
        gap: 0.75rem;
    }

    #students-table tbody tr {
        padding: 0.75rem 1rem;
        background: var(--glass-bg);
        border: 1px solid var(--glass-border);
        border-radius: 12px;
        box-shadow: var(--glass-shadow);
    }

    #students-table td {
        display: grid;
        grid-template-columns: minmax(90px, 0.8fr) minmax(0, 1.2fr);
        align-items: center;
        gap: 0.75rem;
        padding: 0.35rem 0;
        border: none;
        text-align: right !important;
    }

    #students-table td::before {
        content: attr(data-label);
        color: var(--text-muted);
        font-size: 0.75rem;
        font-weight: 600;
        text-align: left;
        text-transform: uppercase;
    }

    #students-table td[colspan] {
        display: block;
        text-align: center !important;
    }

    #students-table td[colspan]::before {
        display: none;
    }

    /* Compact student cards: identity, class/league, statistics and actions. */
    #students-table tbody tr {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 0.25rem 0.5rem;
        padding: 0.7rem 0.85rem;
    }

    #students-table td {
        min-width: 0;
    }

    #students-table td:nth-child(1) {
        display: block;
        grid-column: 1 / -1;
        padding-bottom: 0.25rem;
        font-weight: 600;
        text-align: left !important;
    }

    #students-table td:nth-child(1)::before {
        display: none;
    }

    #students-table td:nth-child(2),
    #students-table td:nth-child(3) {
        display: flex;
        grid-column: span 2;
        align-items: center;
        justify-content: center;
        gap: 0.35rem;
        padding: 0.1rem 0;
        text-align: left !important;
    }

    #students-table td:nth-child(n + 4):nth-child(-n + 7) {
        display: flex;
        grid-column: span 1;
        flex-direction: column;
        align-items: center;
        gap: 0.1rem;
        padding: 0.3rem 0;
        text-align: center !important;
    }

    #students-table td:nth-child(n + 4):nth-child(-n + 7)::before {
        font-size: 0.65rem;
        text-align: center;
    }

    #students-table td:nth-child(8) {
        display: block;
        grid-column: 1 / -1;
        padding-top: 0.35rem;
    }

    #students-table td:nth-child(8)::before {
        display: none;
    }

    #students-table td:nth-child(8) > div {
        justify-content: stretch !important;
    }

    #students-table td:nth-child(8) .btn {
        flex: 1;
    }

    #students-table td[colspan] {
        grid-column: 1 / -1;
    }

    /* Use the page as the single scroll area so no content is cut off. */
    html,
    body {
        height: auto;
        min-height: 100%;
        overflow: auto;
    }

    body,
    #dashboard-screen {
        min-height: 100dvh;
    }

    #dashboard-screen,
    .dashboard-body,
    .flex-layout.active,
    .content.flex-1 {
        flex: none;
        overflow: visible;
    }

    /* Keep the classes list inside its sidebar, as in the desktop layout. */
    #students-sidebar .sidebar-title {
        display: block;
    }

    #students-sidebar .sidebar-filters {
        position: static;
        display: flex;
        flex-direction: column;
        max-height: none;
        overflow: visible;
        padding: 0;
        background: none;
        border: none;
        box-shadow: none;
    }

    #matches-tab .league-filters {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    #matches-tab .league-filters .filter-btn {
        padding: 0.7rem 1rem;
        font-size: 0.9rem;
        white-space: normal;
    }

    /* Group standings use the available card width instead of overflowing it. */
    .leaderboard-section .group-card {
        overflow: hidden;
    }

    .leaderboard-section .group-card .small-table {
        width: 100%;
        min-width: 0;
        table-layout: fixed;
    }

    .leaderboard-section .group-card .small-table th,
    .leaderboard-section .group-card .small-table td {
        padding: 0.4rem 0.2rem;
        font-size: 0.72rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .leaderboard-section .group-card .small-table th:nth-child(1),
    .leaderboard-section .group-card .small-table th:nth-child(3),
    .leaderboard-section .group-card .small-table th:nth-child(4) {
        width: 18%;
    }

    /* Collapsible two-column class picker that does not change sidebar height. */
    #students-sidebar {
        position: relative;
        overflow: visible;
        z-index: 5;
    }

    #students-sidebar .sidebar-title {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
    }

    .classes-toggle {
        display: inline-block;
        flex: none;
        padding: 0.35rem 0.6rem;
        border: 1px solid var(--glass-border);
        border-radius: 6px;
        background: rgba(255, 255, 255, 0.08);
        color: var(--text-color);
        cursor: pointer;
    }

    #students-sidebar.is-collapsed .sidebar-filters {
        display: none;
    }

    #students-sidebar .sidebar-filters {
        position: static;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.5rem;
        max-height: none;
        overflow: visible;
        padding: 0;
        background: transparent;
        border: none;
        box-shadow: none;
    }

    #students-sidebar .sidebar-filters .filter-btn {
        width: 100%;
        min-width: 0;
        background: #1e293b;
        border: 1px solid var(--glass-border);
    }

    #students-sidebar .sidebar-filters .filter-btn.active {
        background: var(--primary-color);
        border-color: var(--primary-color);
        color: white;
    }

    /* Every form select opens above its form rather than stretching it. */
    #student-modal .modal,
    #match-modal .modal,
    #match-details-modal .modal {
        overflow: visible;
    }

    .custom-select-container.open {
        z-index: 10001;
    }

    html,
    body,
    .dashboard-body,
    .flex-1 {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    html::-webkit-scrollbar,
    body::-webkit-scrollbar,
    .dashboard-body::-webkit-scrollbar,
    .flex-1::-webkit-scrollbar {
        display: none;
    }
}





/* Vertical lines are harder generically without knowing exact heights, but we can do a simplified connecting line */
