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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.5;
}

header {
    background: #035848;
    line-height: 0;
    display: flex;
    justify-content: center;
    position: relative;
}

.header-banner {
    display: block;
    width: 100%;
    max-width: 900px;
    height: auto;
}

/* Navigation */
#main-nav {
    background: #054538;
    display: flex;
    justify-content: center;
    gap: 0;
    border-bottom: 2px solid #032f26;
}


#main-nav:empty {
    display: none;
}

.nav-tab {
    padding: 10px 24px;
    color: #aaa;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    border-bottom: 3px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}

.nav-tab:hover {
    color: #fff;
}

.nav-tab.active {
    color: #fff;
    border-bottom-color: #4a90d9;
}

/* Tab content */
.tab-content {
    display: none;
}

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

main {
    max-width: 900px;
    margin: 20px auto;
    padding: 0 15px;
}

/* Group section */
.group-section {
    background: #fff;
    border-radius: 6px;
    margin-bottom: 24px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.group-header {
    background: #054538;
    color: #fff;
    padding: 10px 16px;
    font-size: 1.1rem;
    font-weight: 600;
}

.collapsible {
    cursor: pointer;
    user-select: none;
}

.collapsible::after {
    content: '▾';
    float: right;
    font-size: 0.9rem;
}

.collapsible.collapsed::after {
    content: '▸';
}

.section-content.collapsed {
    display: none;
}

/* Standings table */
.standings-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.standings-table th {
    background: #e8e8e8;
    padding: 6px 8px;
    text-align: center;
    font-weight: 600;
    border-bottom: 2px solid #ccc;
}

.standings-table th:first-child {
    text-align: left;
    padding-left: 16px;
}

.standings-table td {
    padding: 6px 8px;
    text-align: center;
    border-bottom: 1px solid #eee;
}

.standings-table td:first-child {
    text-align: left;
    padding-left: 16px;
    font-weight: 500;
}

.standings-table tr:last-child td {
    border-bottom: none;
}

/* Match list */
.matches-list {
    border-top: 2px solid #e8e8e8;
}

.matches-header {
    background: #065848;
    color: #fff;
    padding: 7px 16px;
    font-size: 0.9rem;
    font-weight: 600;
}

.match-row {
    display: grid;
    grid-template-columns: 40px 1fr auto 1fr 40px;
    align-items: center;
    padding: 10px 16px 0 16px;
    gap: 8px;
}

/* Per-match wrapper: separator sits below the whole match unit (row + info) */
.match-card {
    border-bottom: 1px solid #eee;
}

.match-card:last-child {
    border-bottom: none;
}

/* R32 Manual Override rows have no date/venue line below — keep full padding */
#admin-r32-override .match-row {
    padding: 10px 16px 10px 16px;
}

.match-number {
    font-size: 0.75rem;
    color: #999;
    font-weight: 600;
}

.team-home {
    text-align: right;
    font-weight: 500;
    font-size: 0.9rem;
}

.team-away {
    text-align: left;
    font-weight: 500;
    font-size: 0.9rem;
}

.score-area {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: center;
}

.score-input {
    width: 32px;
    height: 28px;
    text-align: center;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 0.85rem;
    font-weight: 600;
}

.score-input:focus {
    border-color: #4a90d9;
    outline: none;
}

.score-separator {
    font-weight: 700;
    color: #666;
}

.score-display {
    font-weight: 700;
    font-size: 0.95rem;
    padding: 0 6px;
}

.match-info {
    font-size: 0.75rem;
    color: #888;
    text-align: center;
    padding: 4px 16px 10px 16px;
}

/* Bet controls */
.bet-btn {
    background: #4a90d9;
    color: #fff;
    border: none;
    border-radius: 3px;
    padding: 4px 10px;
    font-size: 0.75rem;
    cursor: pointer;
    white-space: nowrap;
}

.bet-btn:hover {
    background: #357abd;
}

.bet-btn.saved {
    background: #5cb85c;
}

/* Result entry (admin) */
.result-section {
    border-top: 1px solid #ddd;
    padding: 8px 16px;
    background: #fafafa;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    font-size: 0.8rem;
}

.result-btn {
    background: #d9534f;
    color: #fff;
    border: none;
    border-radius: 3px;
    padding: 4px 10px;
    font-size: 0.75rem;
    cursor: pointer;
}

.result-btn:hover {
    background: #c9302c;
}

.result-btn.result-btn-save {
    background: #4a90d9;
}

.result-btn.result-btn-save:hover {
    background: #357abd;
}

.result-btn.result-btn-save.saved {
    background: #5cb85c;
}

.result-btn.result-btn-save.saved:hover {
    background: #4cae4c;
}

.completed .score-display {
    color: #16213e;
}

.match-card.completed {
    background: #0458481a;
}

.match-row.completed .score-input {
    background: #e8e8e8;
}

/* Group bet section (drag & drop) */
.group-bet-section {
    border-top: 2px solid #e8e8e8;
    padding: 0 0 12px 0;
    background: #f8fafc;
}

.group-bet-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #16213e;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.lock-badge {
    font-size: 0.7rem;
    background: #e8e8e8;
    color: #555;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
    margin-left: 8px;
}

.lock-badge::before {
    content: '🔒 ';
}

.group-bet-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.group-bet-table th {
    background: #e8e8e8;
    padding: 5px 10px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid #ccc;
}

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

.group-bet-table td {
    padding: 8px 10px;
    border-bottom: 1px solid #ddd;
    background: #fff;
}

.group-bet-table .pos-cell {
    text-align: center;
    font-weight: 700;
    color: #16213e;
    width: 40px;
}

.group-bet-table .team-cell {
    font-weight: 500;
}

.group-bet-table tr[draggable="true"] {
    cursor: grab;
}

.group-bet-table tr[draggable="true"]:active {
    cursor: grabbing;
}

.group-bet-table tr.dragging {
    opacity: 0.4;
}

.group-bet-controls {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    margin-top: 10px;
    padding-left: 16px;
}

/* TBD teams in knockout */
.tbd {
    color: #aaa;
    font-style: italic;
}

/* Knockout stage header */
.knockout-header {
    background: #054538;
}

/* Status messages */
.status-msg {
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 3px;
}

.status-msg.success {
    color: #3c763d;
    background: #dff0d8;
}

.status-msg.error {
    color: #a94442;
    background: #f2dede;
}

/* Knockout winner modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-box {
    background: #fff;
    border-radius: 8px;
    padding: 24px;
    max-width: 360px;
    width: 90%;
}

.modal-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.modal-subtitle {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 16px;
}

.modal-team {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    margin-bottom: 8px;
    cursor: pointer;
    font-weight: 500;
}

.modal-team:hover {
    background: #f0f4ff;
    border-color: #4a90d9;
}

/* System warning banner */
.system-warning-banner {
    background: #f2dede;
    color: #a94442;
    border: 1px solid #ebccd1;
    padding: 12px 20px;
    font-size: 0.85rem;
    line-height: 1.6;
    text-align: center;
}

/* Auto-bet indicator */
.auto-bet-label {
    font-size: 0.7rem;
    color: #c09853;
    font-style: italic;
    margin-left: 6px;
}

.knockout-winner-info {
    font-size: 0.75rem;
    color: #16213e;
    font-weight: 500;
    white-space: nowrap;
}

/* Admin dashboard */
.admin-match-row {
    grid-template-columns: 80px 1fr auto 1fr auto;
}

.admin-stage-badge {
    display: block;
    font-size: 0.65rem;
    font-weight: 600;
    line-height: 1;
    margin-top: 2px;
    color: #fff;
    background: #16213e;
    padding: 2px 5px;
    border-radius: 3px;
    text-align: center;
}

.admin-stage-badge.group { background: #2a6e4e; }
.admin-stage-badge.r32   { background: #4a6fa5; }
.admin-stage-badge.r16   { background: #3a5a8c; }
.admin-stage-badge.qf    { background: #6a4c93; }
.admin-stage-badge.sf    { background: #8b3a62; }
.admin-stage-badge.third { background: #8a6d3b; }
.admin-stage-badge.final { background: #b8860b; }

/* Login form */
.login-form {
    max-width: 340px;
    margin: 60px auto;
    background: #fff;
    border-radius: 8px;
    padding: 32px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.login-form h2 {
    font-size: 1.2rem;
    margin-bottom: 20px;
    color: #16213e;
    text-align: center;
}

.login-field {
    margin-bottom: 14px;
}

.login-field label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 4px;
}

.login-field input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9rem;
}

.login-field input:focus {
    border-color: #4a90d9;
    outline: none;
}

.login-btn {
    width: 100%;
    padding: 10px;
    background: #16213e;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 4px;
}

.login-btn:hover {
    background: #1a2a4e;
}

.login-btn:disabled {
    background: #999;
    cursor: default;
}

/* User header bar */
.modal-cancel {
    display: block;
    text-align: center;
    margin-top: 12px;
    color: #888;
    font-size: 0.8rem;
    cursor: pointer;
}

.edit-user-modal {
    max-width: 400px;
}

.edit-user-modal .login-field {
    margin-bottom: 10px;
}

.edit-user-modal .login-field label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 4px;
}

.edit-user-modal .login-field input[type="checkbox"] {
    width: auto;
}

.edit-user-modal .login-field input[type="text"] {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9rem;
}

.edit-user-modal .login-field input:focus {
    border-color: #4a90d9;
    outline: none;
}

/* Login/Signup form toggle */
.form-toggle {
    text-align: center;
    margin-top: 16px;
    font-size: 0.8rem;
    color: #888;
}

.form-toggle a {
    color: #4a90d9;
    text-decoration: none;
    font-weight: 600;
}

.form-toggle a:hover {
    text-decoration: underline;
}

/* Invitation management */
.inv-controls {
    padding: 12px 16px;
    display: flex;
    align-items: center;
}

.inv-table th:first-child,
.inv-table td:first-child {
    text-align: center;
}

.inv-table th,
.inv-table td {
    font-size: 0.8rem;
}

/* ── Leaderboard ── */

.leaderboard-progress {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: #074438;
    color: #ffffff;
    font-size: 0.8rem;
    border-radius: 6px;
    margin-bottom: 16px;
}

.progress-sep {
    color: #555;
}

.leaderboard-empty {
    text-align: center;
    padding: 32px 16px;
    color: #888;
    font-size: 0.95rem;
}

.leaderboard-table {
    font-size: 0.9rem;
}

.leaderboard-table th {
    font-size: 0.8rem;
}

.leaderboard-table th:nth-child(2) {
    text-align: left;
}

.leaderboard-table td {
    padding: 10px 8px;
}

.leaderboard-table td:first-child {
    text-align: center;
    padding-left: 8px;
}

.leaderboard-row {
    transition: background 0.15s;
}

.leaderboard-row:hover {
    background: #f5f8ff;
}

.leaderboard-row.expanded {
    background: #f0f4ff;
}

/* Rank styling */
.rank-cell {
    font-weight: 700;
    width: 36px;
}

.rank-1 .rank-cell {
    color: #b8860b;
}

.rank-2 .rank-cell {
    color: #888;
}

.rank-3 .rank-cell {
    color: #a0522d;
}

.rank-1 {
    border-left: 3px solid #FFD700;
}

.rank-2 {
    border-left: 3px solid #C0C0C0;
}

.rank-3 {
    border-left: 3px solid #CD7F32;
}

/* Current user highlight */
.leaderboard-me {
    background: #f0f4ff !important;
}

.leaderboard-me td {
    font-weight: 600;
}

/* Total column */
.total-cell {
    font-weight: 700;
    font-size: 1rem;
    color: #16213e;
}

/* Provisional marker */
.provisional-marker {
    color: #c09853;
    font-weight: 700;
    margin-left: 1px;
}

/* Form dots */
.form-dots {
    display: inline-flex;
    gap: 3px;
    align-items: center;
}

.form-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.form-dot.exact {
    background: #5cb85c;
}

.form-dot.partial {
    background: #f0ad4e;
}

.form-dot.wrong {
    background: #d9534f;
}

/* Perfect predictions badge */
.perfect-count {
    display: inline-block;
    background: #fff8e1;
    color: #b8860b;
    font-weight: 700;
    font-size: 0.8rem;
    padding: 1px 7px;
    border-radius: 10px;
    border: 1px solid #f0d060;
}

/* Footnote */
.leaderboard-footnote {
    padding: 8px 16px;
    font-size: 0.75rem;
    color: #999;
    font-style: italic;
}

/* ── Leaderboard detail panel ── */

.leaderboard-detail {
    padding: 12px 16px;
    background: #fafbfd;
    border-top: 1px solid #e8e8e8;
}

.detail-section {
    margin-bottom: 16px;
}

.detail-section:last-child {
    margin-bottom: 0;
}

.detail-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: #16213e;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}

.detail-table th {
    background: #e8ecf0;
    padding: 4px 6px;
    text-align: center;
    font-weight: 600;
    font-size: 0.72rem;
    border-bottom: 1px solid #ccc;
}

.detail-table td {
    padding: 5px 6px;
    text-align: center;
    border-bottom: 1px solid #eee;
}

.detail-teams {
    text-align: left !important;
    font-size: 0.75rem;
    white-space: nowrap;
}

.detail-pts {
    white-space: nowrap;
}

.detail-calc {
    display: block;
    font-size: 0.65rem;
    color: #999;
}

/* Scoring category colors in detail */
.detail-cat-exact {
    background: #f0faf0;
}

.detail-cat-diff {
    background: #fef9ee;
}

.detail-cat-outcome {
    background: #fef9ee;
}

.detail-cat-wrong {
    background: #fdf2f2;
}

/* Group detail */
.detail-group {
    margin-bottom: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
}

.detail-group.detail-provisional {
    border-style: dashed;
    border-color: #d4c080;
}

.detail-group-header {
    padding: 6px 10px;
    background: #f0f0f0;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.detail-group-pts {
    margin-left: auto;
    font-weight: 600;
    color: #16213e;
}

.detail-badge {
    font-size: 0.65rem;
    padding: 1px 6px;
    border-radius: 3px;
    font-weight: 500;
}

.detail-badge.final {
    background: #dff0d8;
    color: #3c763d;
}

.detail-badge.provisional {
    background: #fcf8e3;
    color: #8a6d3b;
}

.detail-pos-table td:first-child {
    font-weight: 600;
    width: 40px;
}

/* Detail collapsible sub-sections */
.detail-collapsible {
    margin-bottom: 6px;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
}

.detail-collapsible .detail-provisional {
    border: none;
}

.detail-collapse-header {
    padding: 6px 10px;
    background: #f0f0f0;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.detail-collapse-header::after {
    content: '\25BE';
    margin-left: auto;
    font-size: 0.75rem;
    color: #888;
}

.detail-collapse-header.collapsed::after {
    content: '\25B8';
}

.detail-collapse-content.collapsed {
    display: none;
}

.detail-collapse-header:hover {
    background: #e8ecf0;
}

.detail-collapsible .detail-provisional {
    border-left: 2px dashed #d4c080;
}

/* ── View Bets modal ── */

.view-bets-btn {
    background: #4a90d9;
    margin-left: 4px;
}

.view-bets-btn:hover {
    background: #357abd;
}

.view-bets-modal {
    max-width: 480px;
}

.view-bets-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    padding: 8px 0;
    margin-bottom: 4px;
    border-bottom: 1px solid #eee;
    font-size: 0.8rem;
    color: #555;
}

.view-bets-legend-item {
    white-space: nowrap;
}

.view-bets-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    margin-top: 12px;
}

.view-bets-table th {
    background: #e8ecf0;
    padding: 6px 8px;
    text-align: center;
    font-weight: 600;
    font-size: 0.75rem;
    border-bottom: 2px solid #ccc;
}

.view-bets-table th:first-child {
    text-align: left;
}

.view-bets-table td {
    padding: 7px 8px;
    text-align: center;
    border-bottom: 1px solid #eee;
    white-space: nowrap;
}

.view-bets-participant {
    text-align: left !important;
    font-weight: 500;
}

.view-bets-auto td {
    color: #999;
    font-style: italic;
}

/* ── Rules page ── */

.rules-body {
    padding: 14px 18px;
    font-size: 0.88rem;
    line-height: 1.7;
    color: #444;
}

.rules-body p {
    margin-bottom: 10px;
}

.rules-body h4 {
    font-size: 0.85rem;
    font-weight: 700;
    color: #16213e;
    margin: 14px 0 6px;
}

.rules-body ul,
.rules-body ol {
    margin: 6px 0 10px 20px;
}

.rules-body li {
    margin-bottom: 4px;
}

.rules-table {
    width: 100%;
    max-width: 500px;
    border-collapse: collapse;
    font-size: 0.83rem;
    margin: 8px 0 12px;
}

.rules-table th {
    background: #e8ecf0;
    padding: 6px 10px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid #ccc;
}

.rules-table td {
    padding: 6px 10px;
    border-bottom: 1px solid #eee;
}

@media (max-width: 480px) {
    .nav-tab {
        padding: 8px 12px;
        font-size: 0.75rem;
    }

    .leaderboard-table {
        font-size: 0.7rem;
    }

    .leaderboard-table th {
        font-size: 0.65rem;
        padding: 4px 3px;
    }

    .leaderboard-table td {
        padding: 6px 3px;
    }

    .standings-table {
        font-size: 0.7rem;
    }

    .standings-table th,
    .standings-table td {
        padding: 4px 3px;
    }

    .standings-table th:first-child,
    .standings-table td:first-child {
        padding-left: 8px;
    }

    .group-bet-table {
        font-size: 0.7rem;
    }

    .group-bet-table th,
    .group-bet-table td {
        padding: 4px 6px;
    }

    .group-header {
        font-size: 0.95rem;
        padding: 8px 12px;
    }

    .matches-header {
        font-size: 0.75rem;
        padding: 5px 10px;
    }

    .match-row {
        padding: 8px 10px 0 10px;
    }

    .team-home,
    .team-away {
        font-size: 0.75rem;
    }

    .match-info {
        font-size: 0.65rem;
        padding: 3px 10px 8px 10px;
    }

    .score-input {
        width: 28px;
        height: 24px;
        font-size: 0.75rem;
    }

    .score-display {
        font-size: 0.8rem;
        padding: 0 4px;
    }

    .rules-body {
        font-size: 0.75rem;
        padding: 12px 14px;
    }

    .rules-body h4 {
        font-size: 0.75rem;
    }

    .rules-table {
        font-size: 0.7rem;
    }

    .rules-table th,
    .rules-table td {
        padding: 4px 6px;
    }

    .inv-table th,
    .inv-table td {
        font-size: 0.7rem;
        padding: 4px 6px;
    }

    .inv-controls {
        padding: 14px 16px;
    }

    .inv-table td button {
        margin-top: 2px;
        margin-bottom: 2px;
    }

    .result-btn,
    .bet-btn {
        padding: 3px 7px;
        font-size: 0.65rem;
    }

    .result-section {
        padding: 6px 12px;
        font-size: 0.7rem;
    }

    .view-bets-legend {
        font-size: 0.7rem;
    }

    .view-bets-table {
        font-size: 0.7rem;
    }

    .view-bets-table th {
        font-size: 0.65rem;
        padding: 4px 3px;
    }

    .view-bets-table td {
        padding: 5px 3px;
    }

    .leaderboard-detail {
        padding: 10px 12px;
    }

    .detail-title {
        font-size: 0.7rem;
    }

    .detail-table {
        font-size: 0.68rem;
    }

    .detail-table th {
        font-size: 0.62rem;
        padding: 3px 4px;
    }

    .detail-table td {
        padding: 4px 4px;
    }

    .detail-teams {
        font-size: 0.65rem;
    }

    .detail-calc {
        font-size: 0.55rem;
    }

    .detail-group-header {
        font-size: 0.7rem;
        padding: 5px 8px;
    }
}

