/* Tokens. Les valeurs sombres sont choisies pour la surface sombre,
   pas obtenues par inversion : c'est ce qui garde les contrastes. */
:root {
    color-scheme: light;
    --surface: #fcfcfb;
    --surface-raised: #ffffff;
    --border: #e4e3de;
    --border-strong: #cfcec8;
    --text: #0b0b0b;
    --text-secondary: #52514e;
    --text-muted: #79776f;
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --accent-soft: #eef4fd;
    --good: #0ca30c;
    --critical: #d03b3b;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --surface: #1a1a19;
        --surface-raised: #232322;
        --border: #353533;
        --border-strong: #4a4a46;
        --text: #ffffff;
        --text-secondary: #c3c2b7;
        --text-muted: #94938a;
        --series-1: #3987e5;
        --series-2: #d95926;
        --accent-soft: #1f2b3c;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--surface);
    color: var(--text);
    font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }

.masthead {
    border-bottom: 1px solid var(--border);
    background: var(--surface-raised);
    position: sticky;
    top: 0;
    z-index: 10;
}

.masthead > div {
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 16px;
    display: flex;
    align-items: center;
    gap: 22px;
    flex-wrap: wrap;
    min-height: 56px;
}

.brand { font-weight: 650; letter-spacing: -0.01em; color: var(--text); }
.brand span { color: var(--text-muted); font-weight: 400; margin-left: 8px; font-size: 13px; }

.menu-toggle { display: none; }
.masthead nav { display: flex; flex-direction: column; gap: 6px; margin-left: auto; flex: 1; }
.masthead .nav-tier { display: flex; gap: 18px; flex-wrap: wrap; align-items: baseline; }
.masthead .nav-user { display: flex; gap: 18px; margin-left: auto; flex-wrap: wrap; }
.masthead nav a { color: var(--text-secondary); font-size: 14px; }
.masthead nav a.is-active { color: var(--text); font-weight: 600; }

main { max-width: 1180px; margin: 0 auto; padding: 28px 16px 64px; }

h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 16px; margin: 32px 0 12px; letter-spacing: -0.01em; }
.lede { color: var(--text-secondary); margin: 0 0 24px; }

/* Tuiles de chiffres */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    background: var(--surface-raised);
}
.tile .label { color: var(--text-secondary); font-size: 13px; }
.tile .value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; }
.tile .value.hero { font-size: 48px; line-height: 1.05; }
.tile .sub { color: var(--text-muted); font-size: 12px; margin-top: 2px; }

.panel {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-raised);
    padding: 16px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

/* Tableaux */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}
tbody tr:hover { background: var(--accent-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.time { font-variant-numeric: tabular-nums; font-weight: 600; }
.muted { color: var(--text-muted); }
.wrap-scroll { overflow-x: auto; }

tr.is-club td { background: var(--accent-soft); }

.badge {
    display: inline-block;
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    color: var(--text-secondary);
    white-space: nowrap;
}
.badge.club { border-color: var(--series-1); color: var(--series-1); }
.badge.status { border-color: var(--critical); color: var(--critical); }

/* Filtres : une seule rangée au-dessus des données */
form.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
/* Formulaire à champs libellés : le libellé au-dessus, le bouton aligné sur le bas des champs. */
form.filters-labeled { align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-secondary); }
.field input { min-width: min(240px, 100%); }
input[type="search"], input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="number"], select {
    font: inherit;
    padding: 7px 10px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: var(--surface-raised);
    color: var(--text);
}
button {
    font: inherit;
    padding: 7px 14px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: var(--series-1);
    color: #fff;
    cursor: pointer;
}
button.ghost { background: transparent; color: var(--text-secondary); border-color: var(--border-strong); }

/* Pastilles d'épreuve */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chips a {
    font-size: 13px;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    color: var(--text-secondary);
}
.chips a:hover { text-decoration: none; border-color: var(--series-1); }
.chips a.is-active { background: var(--series-1); border-color: var(--series-1); color: #fff; }

/* Pagination */
.pager { display: flex; gap: 10px; align-items: center; margin-top: 16px; color: var(--text-secondary); font-size: 14px; }
.pager a, .pager span.disabled {
    padding: 5px 11px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
}
.pager span.disabled { color: var(--text-muted); border-color: var(--border); }

/* Graphiques */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis-text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--series-1); stroke: var(--surface-raised); stroke-width: 2; }
.chart .bar { fill: var(--series-1); }
.chart .hit { fill: transparent; }
.chart .tip { opacity: 0; pointer-events: none; transition: opacity 90ms linear; }
.chart .probe:hover .tip, .chart .probe:focus-visible .tip { opacity: 1; }
.chart .probe:hover .crosshair { opacity: 1; }
.chart .crosshair { stroke: var(--border-strong); stroke-width: 1; opacity: 0; }
.chart .tip-box { fill: var(--surface-raised); stroke: var(--border-strong); }
.chart .tip-text { fill: var(--text); font-size: 12px; }
.chart .tip-sub { fill: var(--text-secondary); font-size: 11px; }
.chart .end-label { fill: var(--text); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }

.chart-note { color: var(--text-secondary); font-size: 13px; margin: 0 0 4px; }
.delta-good { color: var(--good); font-weight: 600; }
.delta-bad { color: var(--critical); font-weight: 600; }

.empty { color: var(--text-muted); padding: 24px 0; }

.nav-sep {
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    min-width: 70px;
}
h3.chart-note { font-size: 13px; font-weight: 600; margin: 18px 0 8px; color: var(--text-secondary); }

td.nowrap, th.nowrap { white-space: nowrap; }

.panel.notice {
    display: flex;
    gap: 10px;
    align-items: baseline;
    flex-wrap: wrap;
    margin-bottom: 16px;
    border-color: var(--critical);
}
td .badge { margin-left: 6px; font-weight: 400; }

.chips-label {
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    align-self: center;
    margin-right: 2px;
}

.runbar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin: 0 0 18px;
}
.runbar form { margin: 0; }
.runbar .muted { font-size: 13px; }
.runlog {
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    margin: 0 0 18px;
    font-size: 12.5px;
    line-height: 1.5;
    overflow-x: auto;
    white-space: pre-wrap;
    color: var(--text-secondary);
}
button[disabled] { opacity: 0.5; cursor: not-allowed; }

.filename { font-size: 11.5px; margin-top: 1px; }

/* Connexion */
.alert {
    border: 1px solid var(--critical);
    border-radius: 8px;
    color: var(--critical);
    padding: 8px 12px;
    margin: 0 0 16px;
}
.login {
    max-width: 380px;
    margin: 48px auto 0;
    padding: 28px 28px 24px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-raised);
}
.login form { display: grid; gap: 16px; }
.login label { display: grid; gap: 6px; font-size: 13px; color: var(--text-secondary); }
.login input { width: 100%; box-sizing: border-box; font-size: 16px; }
.login input:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }
.login button { width: 100%; padding: 10px 14px; font-weight: 600; }

/* Smartphone : on garde les colonnes qui identifient la ligne et on laisse
   le détail aux pages de nage et de meeting. Le reste défile en largeur. */
@media (max-width: 640px) {
    body { font-size: 14px; }
    main { padding: 18px 12px 48px; }
    h1 { font-size: 21px; }
    h2 { margin-top: 26px; }

    /* Menu : hamburger, panneau déroulant en colonne */
    .masthead > div { gap: 0 14px; padding: 8px 12px; min-height: 0; flex-wrap: wrap; }
    .brand { flex: 1; }
    .menu-toggle {
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 5px;
        width: 44px;
        height: 40px;
        padding: 0 10px;
        background: transparent;
        border: 1px solid var(--border-strong);
    }
    .menu-toggle span { display: block; height: 2px; background: var(--text); border-radius: 2px; }
    .masthead nav {
        display: none;
        flex-direction: column;
        margin-left: 0;
        width: 100%;
        gap: 0;
        padding: 6px 0 4px;
    }
    .masthead nav.is-open { display: flex; }
    .masthead nav a { padding: 11px 4px; font-size: 15px; border-bottom: 1px solid var(--border); }
    .masthead .nav-tier, .masthead .nav-user { flex-direction: column; gap: 0; }
    .nav-sep { padding: 12px 4px 2px; }

    /* Cibles tactiles et filtres pleine largeur */
    form.filters > * { flex: 1 1 140px; min-width: 0; }
    input[type="search"], input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="number"], select, button {
        font-size: 16px; /* évite le zoom automatique d'iOS au focus */
        min-height: 40px;
    }
    .chips a { padding: 6px 12px; }
    .pager { flex-wrap: wrap; }
    .pager a, .pager span.disabled { padding: 8px 14px; }

    .tiles { grid-template-columns: repeat(2, 1fr); }
    .tile .value.hero { font-size: 38px; }
    .panel { padding: 12px; }

    /* Tableaux plus denses, défilement à l'intérieur du conteneur */
    th, td { padding: 7px 6px; }
    .wrap-scroll { margin: 0 -12px; padding: 0 12px; -webkit-overflow-scrolling: touch; }
    td.nowrap { white-space: nowrap; }

    .m-rankings :is(th, td):nth-child(n+8),
    .m-rankings :is(th, td):nth-child(4),
    .m-rankings :is(th, td):nth-child(5),
    .m-bests :is(th, td):nth-child(n+5),
    .m-history :is(th, td):nth-child(n+5),
    .m-meet :is(th, td):nth-child(4),
    .m-meet :is(th, td):nth-child(n+7),
    .m-records :is(th, td):nth-child(n+5),
    .m-recent :is(th, td):nth-child(4),
    .m-recent :is(th, td):nth-child(7) { display: none; }
}
