:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --text: #1d2330;
    --muted: #6b7385;
    --accent: #e4572e;
    --accent-ink: #ffffff;
    --border: #e1e4ea;
    --ok: #1f8a4c;
    --error: #c0392b;
    --radius: 10px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #12151b;
        --surface: #1b2029;
        --text: #e6e9ef;
        --muted: #9aa3b5;
        --border: #2c333f;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--accent); }

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.topbar nav { display: flex; gap: 16px; align-items: center; }
.brand { font-weight: 700; text-decoration: none; color: var(--text); }

.container { max-width: 1100px; margin: 0 auto; padding: 24px 16px; }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-bottom: 16px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}
.card.narrow { max-width: 520px; margin: 40px auto; }
.profile-card { text-decoration: none; color: inherit; }
.profile-card:hover { border-color: var(--accent); }
.card h2 { margin-top: 0; }

.badge {
    display: inline-block;
    font-size: .8rem;
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--accent);
    color: var(--accent-ink);
    vertical-align: middle;
}
.muted { color: var(--muted); }

label { display: block; font-weight: 600; margin: 12px 0 4px; }
label.checkbox { font-weight: 400; display: flex; gap: 8px; align-items: flex-start; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
}
.form-row { margin-bottom: 8px; }
.form-row > div > input[type=radio] + label { display: inline; font-weight: 400; margin-right: 16px; }
.help { color: var(--muted); font-size: .9rem; margin: 4px 0 0; }
.errors { color: var(--error); margin: 4px 0 0; padding-left: 18px; }

.btn {
    display: inline-block;
    margin-top: 16px;
    padding: 10px 18px;
    border: 0;
    border-radius: 8px;
    background: var(--accent);
    color: var(--accent-ink);
    font-size: 1rem;
    text-decoration: none;
    cursor: pointer;
}
.btn-secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
.page-head .btn { margin-top: 0; }

.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; border: 1px solid var(--border); background: var(--surface); }
.flash-success { border-color: var(--ok); }
.flash-error { border-color: var(--error); color: var(--error); }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.btn-block { display: block; text-align: center; }

/* ---------- Mise en page ---------- */
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions form { margin: 0; }
.actions .btn { margin-top: 0; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.crumbs { margin: 0 0 8px; }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; gap: 12px; }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
table.data th { color: var(--muted); font-weight: 600; font-size: .85rem; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tbody tr:hover { background: var(--bg); }

/* ---------- Tuiles de synthèse ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 16px 0; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.tile-label { color: var(--muted); font-size: .85rem; }
.tile-value { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile-sub { color: var(--muted); font-size: .85rem; }

/* ---------- Multisport ---------- */
.multisport { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.multisport a { padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; text-decoration: none; color: var(--text); background: var(--surface); }
.multisport a[aria-current] { border-color: var(--accent); font-weight: 600; }

/* ---------- Carte ---------- */
.map-card { padding: 0; overflow: hidden; }
.map { height: 380px; }
@media (max-width: 600px) { .map { height: 260px; } }

/* ---------- Graphiques (palette de référence dataviz, clair / sombre) ---------- */
.viz-root {
    /* 3 premiers emplacements de la palette catégorielle : seuls validés deux à deux (CVD) */
    --viz-1: #2a78d6;      /* bleu : vitesse */
    --viz-2: #eb6834;      /* orange : fréquence cardiaque */
    --viz-3: #1baf7a;      /* vert d'eau : puissance (contraste < 3:1 → titres et infobulles libellés) */
    --viz-neutral: #898781; /* altitude, cadence (contexte) */
    --viz-grid: #e7e6e2;
    --viz-axis: #6b6a64;
}
@media (prefers-color-scheme: dark) {
    .viz-root {
        --viz-1: #3987e5;
        --viz-2: #d95926;
        --viz-3: #199e70;
        --viz-neutral: #8f8d86;
        --viz-grid: #2c333f;
        --viz-axis: #9aa3b5;
    }
}
.viz-charts { position: relative; }
.viz-chart { margin: 0 0 10px; }
.viz-chart figcaption { font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
.viz-chart svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.viz-grid { stroke: var(--viz-grid); stroke-width: 1; }
.viz-axis { fill: var(--viz-axis); font-size: 11px; font-variant-numeric: tabular-nums; }
.viz-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz-area { opacity: .22; stroke: none; }
.viz-cursor { stroke: var(--text); stroke-width: 1; stroke-dasharray: 3 3; opacity: .6; }
.viz-dot { stroke: var(--surface); stroke-width: 2; }
.viz-tooltip {
    position: absolute; z-index: 5; pointer-events: none; min-width: 170px;
    background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
    padding: 8px 10px; font-size: .85rem; line-height: 1.6; box-shadow: 0 4px 14px rgba(0,0,0,.12);
}
.viz-tooltip .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
details > summary { cursor: pointer; list-style-position: outside; }
h2.inline { display: inline; }
