:root {
    --cysa-green: #14663c;
    --cysa-green-dark: #0e4a2b;
    --cysa-sidebar-width: 15rem;
    --bs-primary: var(--cysa-green);
    --bs-primary-rgb: 20, 102, 60;
    --bs-link-color: var(--cysa-green);
    --bs-link-color-rgb: 20, 102, 60;
    --bs-link-hover-color: var(--cysa-green-dark);
    --bs-link-hover-color-rgb: 14, 74, 43;
}

html, body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #f4f6f5;
}

h1:focus {
    outline: none;
}

.btn-primary {
    --bs-btn-bg: var(--cysa-green);
    --bs-btn-border-color: var(--cysa-green);
    --bs-btn-hover-bg: var(--cysa-green-dark);
    --bs-btn-hover-border-color: var(--cysa-green-dark);
    --bs-btn-active-bg: var(--cysa-green-dark);
    --bs-btn-active-border-color: var(--cysa-green-dark);
    --bs-btn-disabled-bg: var(--cysa-green);
    --bs-btn-disabled-border-color: var(--cysa-green);
}

.btn-outline-primary {
    --bs-btn-color: var(--cysa-green);
    --bs-btn-border-color: var(--cysa-green);
    --bs-btn-hover-bg: var(--cysa-green);
    --bs-btn-hover-border-color: var(--cysa-green);
    --bs-btn-active-bg: var(--cysa-green);
    --bs-btn-active-border-color: var(--cysa-green);
}

/* ---------- Shell ---------- */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-sidebar {
    width: var(--cysa-sidebar-width);
    flex-shrink: 0;
    background: var(--cysa-green-dark);
    color: #fff;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.app-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: 1rem 1.25rem;
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    text-decoration: none;
}

.app-brand-mark {
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: #fff;
    color: var(--cysa-green-dark);
}

.app-nav {
    display: flex;
    flex-direction: column;
    padding: .25rem .75rem 1.5rem;
}

.app-nav-heading {
    margin: 1.1rem .5rem .3rem;
    font-size: .72rem;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, .6);
}

.app-nav-link {
    padding: .55rem .75rem;
    border-radius: .4rem;
    color: rgba(255, 255, 255, .9);
    text-decoration: none;
    border-left: 3px solid transparent;
}

.app-nav-link:hover {
    background: rgba(255, 255, 255, .1);
    color: #fff;
}

.app-nav-link.active {
    background: rgba(255, 255, 255, .16);
    border-left-color: #fff;
    color: #fff;
    font-weight: 600;
}

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .6rem 1.5rem;
    background: #fff;
    border-bottom: 1px solid #dee2e6;
}

.app-content {
    padding: 1.5rem;
    max-width: 82rem;
    width: 100%;
}

@media (max-width: 991.98px) {
    .app-sidebar {
        position: fixed;
        z-index: 1040;
        transform: translateX(-100%);
        transition: transform .15s ease-in-out;
    }

    .app-sidebar.open {
        transform: none;
        box-shadow: 0 0 2rem rgba(0, 0, 0, .35);
    }

    .app-content {
        padding: 1rem;
    }
}

/* ---------- Pages ---------- */

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: 1.25rem;
}

.page-header h1 {
    font-size: 1.6rem;
    margin: 0;
}

.panel {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: .5rem;
}

.panel > .table-responsive > .table,
.panel > .table {
    margin-bottom: 0;
}

.panel .table > :not(caption) > * > * {
    padding: .65rem .9rem;
    vertical-align: middle;
}

.panel .table thead th {
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #5c6770;
    background: #f8f9fa;
    white-space: nowrap;
}

.actions {
    display: flex;
    /* Buttons stay on one line in a table; a table that gets too wide turns into cards (see below). */
    flex-wrap: nowrap;
    justify-content: flex-end;
    gap: .35rem;
}

.actions .btn {
    white-space: nowrap;
}

.empty-state {
    padding: 2.5rem 1rem;
    text-align: center;
    color: #5c6770;
}

.stat-card {
    padding: 1rem 1.25rem;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.1;
}

.badge-status {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .25rem .55rem;
    border-radius: 999px;
    border: 1px solid;
    font-size: .8rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-good { color: #0f5132; background: #d1e7dd; border-color: #a3cfbb; }
.badge-info { color: #084298; background: #cfe2ff; border-color: #9ec5fe; }
.badge-warn { color: #664d03; background: #fff3cd; border-color: #ffda6a; }
.badge-bad { color: #842029; background: #f8d7da; border-color: #f1aeb5; }
.badge-muted { color: #41464b; background: #e2e3e5; border-color: #c4c8cb; }

.score {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ---------- Tables that fit their space ----------
   js/tables.js measures each table. When it does not fit, it first hides .col-optional columns
   (data-compact), and if that is not enough shows one card per row (data-stacked). */

.table-responsive {
    /* The script prevents overflow; this is only the fallback while a page is loading. */
    -webkit-overflow-scrolling: touch;
}

table[data-compact] .col-optional {
    display: none;
}

/* With the optional columns gone the rest sit a little closer, which keeps a league table a table on a phone. */
.panel table[data-compact] > :not(caption) > * > * {
    padding-inline: .45rem;
}

table[data-stacked],
table[data-stacked] > tbody,
table[data-stacked] > tbody > tr,
table[data-stacked] > tbody > tr > td {
    display: block;
}

/* Each value shows its own label instead of the heading row. */
table[data-stacked] > thead {
    display: none;
}

.panel table[data-stacked] > tbody > tr {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    padding: .85rem .9rem;
    border-bottom: 1px solid #dee2e6;
}

.panel table[data-stacked] > tbody > tr:last-child {
    border-bottom: 0;
}

.panel table[data-stacked] > tbody > tr > td {
    padding: 0;
    border: 0;
    text-align: left !important;
    white-space: normal !important;
    width: auto !important;
    background: none;
    box-shadow: none;
}

/* Label on the left, the value (however many lines it has) on the right. */
.panel table[data-stacked] > tbody > tr > td[data-label] {
    display: grid;
    grid-template-columns: minmax(6.5rem, 34%) minmax(0, 1fr);
    column-gap: .75rem;
    justify-items: start;
    align-items: baseline;
}

table[data-stacked] > tbody > tr > td[data-label]::before {
    content: attr(data-label);
    grid-column: 1;
    grid-row: 1 / span 12;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #5c6770;
}

table[data-stacked] > tbody > tr > td[data-label] > * {
    grid-column: 2;
}

/* The row's name leads the card, without a label. */
.panel table[data-stacked] > tbody > tr > td[data-primary] {
    display: block;
    order: -1;
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: .1rem;
}

table[data-stacked] > tbody > tr > td[data-primary]::before {
    content: none;
}

table[data-stacked] .actions {
    flex-wrap: wrap;
    justify-content: flex-start;
    margin-top: .35rem;
}

/* ---------- Matches ----------
   A list, not a table. Each match rearranges itself to the width of the list it is in. */

.match-list {
    container-type: inline-size;
}

.match-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "teams" "meta" "status" "actions";
    gap: .5rem 1rem;
    align-items: center;
    padding: .8rem .9rem;
    border-bottom: 1px solid #e9ecef;
}

.match-row:last-child {
    border-bottom: 0;
}

.match-row:hover {
    background: #f8f9fa;
}

.match-teams {
    grid-area: teams;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: .75rem;
    align-items: center;
}

.match-home,
.match-away {
    font-weight: 600;
    overflow-wrap: anywhere;
}

.match-home {
    text-align: right;
}

.match-side {
    display: block;
    font-size: .68rem;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #5c6770;
}

.match-score {
    min-width: 4rem;
    padding: .2rem .55rem;
    border-radius: .4rem;
    background: #eef1f0;
    text-align: center;
    font-size: 1.05rem;
}

.match-meta {
    grid-area: meta;
    font-size: .875rem;
    line-height: 1.35;
    text-align: center;
}

.match-status {
    grid-area: status;
    text-align: center;
}

.match-actions {
    grid-area: actions;
    flex-wrap: wrap;
    justify-content: center;
}

/* Tablet: teams and status on one line, details and buttons on the next. */
@container (min-width: 38rem) {
    .match-row {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas: "teams status" "meta actions";
    }

    .match-meta {
        text-align: left;
    }

    .match-status {
        text-align: right;
    }

    .match-actions {
        justify-content: flex-end;
    }
}

/* Desktop: everything on one line. */
@container (min-width: 66rem) {
    .match-row {
        grid-template-columns: minmax(13.5rem, 1fr) minmax(0, 1.5fr) 8.5rem auto;
        grid-template-areas: "meta teams status actions";
    }

    .match-status {
        text-align: left;
    }

    .match-actions {
        flex-wrap: nowrap;
        min-width: 19.5rem;
    }
}

/* In the "all rounds" view the way to jump to a round stays in reach while the page scrolls:
   the round buttons on a wide screen, a single drop-down on a narrow one. */
.round-picker-sticky,
.round-jump {
    position: sticky;
    top: 0;
    z-index: 5;
    margin-inline: -.5rem;
    padding: .5rem;
    background: #f4f6f5;
    border-bottom: 1px solid #dee2e6;
}

.round-picker-sticky {
    max-height: 9.5rem;
    overflow-y: auto;
}

.round-section {
    scroll-margin-top: 10.5rem;
}

@media (max-width: 767.98px) {
    .round-section {
        scroll-margin-top: 4.75rem;
    }
}

.round-heading {
    background: #f8f9fa;
    border-radius: .5rem .5rem 0 0;
}

/* ---------- Touch ---------- */

/* Fingers need bigger targets than a mouse pointer does. */
@media (pointer: coarse) {
    .btn,
    .form-control,
    .form-select {
        min-height: 2.75rem;
    }

    .btn-sm,
    .form-select-sm {
        min-height: 2.5rem;
        padding-inline: .8rem;
        font-size: .9rem;
    }

    .actions,
    .round-picker {
        gap: .5rem;
    }

    .form-check-input {
        width: 1.3em;
        height: 1.3em;
    }
}

@media (max-width: 575.98px) {
    .page-header h1 {
        font-size: 1.35rem;
    }

    .app-topbar {
        padding: .5rem .75rem;
        gap: .5rem;
    }

    .app-topbar .btn {
        padding: .35rem .6rem;
        font-size: .875rem;
        white-space: nowrap;
    }

    /* The name is on every page; on a phone the room goes to the buttons. */
    .app-topbar .app-user {
        display: none;
    }

    /* The buttons of a page header share the row instead of each taking a line. */
    .page-header > .d-flex > .btn {
        flex: 1 1 auto;
    }
}

/* The approve bar of the round generator stays in view while a long preview is scrolled. */
.schedule-approve-bar {
    position: sticky;
    bottom: .75rem;
    box-shadow: 0 .25rem 1rem rgba(0, 0, 0, .12);
}

.round-picker {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
}

.sign-in {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: var(--cysa-green-dark);
}

.sign-in .card {
    width: 100%;
    max-width: 24rem;
}

.toast-stack {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 1090;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.toast-stack .alert {
    margin: 0;
    box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .15);
}

/* ---------- Forms ---------- */

.field-label {
    display: block;
    margin-bottom: .3rem;
    font-weight: 600;
}

.valid.modified:not([type=checkbox]) {
    outline: none;
}

.invalid {
    border-color: #dc3545;
}

.validation-message {
    color: #b02a37;
    font-size: .875rem;
    margin-top: .25rem;
}

/* ---------- Blazor defaults ---------- */

#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 2000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto 0 auto;
}

.loading-progress circle {
    fill: none;
    stroke: #e0e0e0;
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--cysa-green);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading");
}
