:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --grid: #e9e8e4;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --swim: #2a78d6;
  --bike: #1baf7a;
  --run: #eb6834;
  --strength: #6250d6;
  --race: #d03b3b;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --good-ink: #006300;
  --warn-ink: #8a5a00;
  --crit-ink: #a52626;
  --ph-prep: #86b6ef;
  --ph-base: #5598e7;
  --ph-build: #2a78d6;
  --ph-peak: #1c5cab;
  --ph-taper: #0d366b;
  --ph-race: #d03b3b;
  --ph-post: #b9b8b1;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 2px 8px rgba(0, 0, 0, .04);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2f2f2c;
    --grid: #2a2a28;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #3987e5;
    --swim: #3987e5;
    --bike: #199e70;
    --run: #d95926;
    --strength: #9085e9;
    --good-ink: #5ccc5c;
    --warn-ink: #fab219;
    --crit-ink: #ef7d7d;
    --ph-prep: #104281;
    --ph-base: #1c5cab;
    --ph-build: #2a78d6;
    --ph-peak: #5598e7;
    --ph-taper: #9ec5f4;
    --ph-post: #4a4a46;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
p { margin: .25rem 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.tnum { font-variant-numeric: tabular-nums; }

/* ---------- en-tête */
header.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.top-inner { max-width: 1240px; margin: 0 auto; display: flex; align-items: center; gap: 1rem; padding: .5rem 16px; }
.brand { font-weight: 700; color: var(--text); white-space: nowrap; display: flex; align-items: center; gap: .4rem; }
.brand .dots span { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 2px; }
nav.main { display: flex; gap: .15rem; overflow-x: auto; flex: 1; min-width: 0; scrollbar-width: none; }
nav.main a {
  color: var(--text-2); padding: .4rem .65rem; border-radius: 8px; white-space: nowrap; font-size: .92rem;
}
nav.main a:hover { background: var(--surface-2); text-decoration: none; }
nav.main a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }

main { max-width: 1240px; margin: 0 auto; padding: 20px 16px 60px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap;
  margin-bottom: 1rem; }

/* ---------- cartes et grilles */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); min-width: 0;
}
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
@media (max-width: 900px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .span2 { grid-column: auto; } }
@media (max-width: 640px) {
  .g2, .g3 { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .top-inner { gap: .5rem; }
  .brand .name, .sync-label { display: none; }
  .stat .value { font-size: 1.4rem; }
  .card { padding: 14px; }
}
.stack > * + * { margin-top: 16px; }

.stat .label { color: var(--text-2); font-size: .85rem; }
.stat .value { font-size: 1.7rem; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: .82rem; }

/* ---------- formulaires */
form.inline { display: inline; }
label { display: block; font-size: .85rem; color: var(--text-2); margin-bottom: .2rem; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: .45rem .6rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { width: auto; margin-right: .4rem; }
textarea { min-height: 70px; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 16px; }
.field .help { color: var(--muted); font-size: .78rem; margin-top: .15rem; }
.check { display: flex; align-items: center; gap: .3rem; font-size: .92rem; color: var(--text); }
.checks { display: flex; flex-wrap: wrap; gap: .4rem 1rem; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px 16px; margin: 0 0 16px; }
legend { font-weight: 600; padding: 0 .3rem; }

.btn {
  display: inline-flex; align-items: center; gap: .35rem; font: inherit; font-weight: 550; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: .45rem .85rem; border-radius: 8px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--crit-ink); }
.btn.sm { padding: .25rem .55rem; font-size: .85rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ---------- messages */
.flash { padding: .7rem 1rem; border-radius: 10px; margin-bottom: 16px; border: 1px solid var(--border);
  background: var(--surface); display: flex; gap: .6rem; align-items: flex-start; }
.flash.ok { border-left: 4px solid var(--good); }
.flash.err { border-left: 4px solid var(--critical); }
.note { background: var(--surface-2); border-radius: 10px; padding: .65rem .85rem; font-size: .9rem; }

/* ---------- badges, puces sport */
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 99px;
  background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.key { background: transparent; border: 1px solid var(--text-2); }
.badge.est { color: var(--warn-ink); border: 1px solid currentColor; background: transparent; }
.badge.done { color: var(--good-ink); }
.badge.skipped { color: var(--crit-ink); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.sport-swim { --sc: var(--swim); } .sport-bike { --sc: var(--bike); } .sport-run { --sc: var(--run); }
.sport-strength { --sc: var(--strength); } .sport-race { --sc: var(--race); } .sport-other { --sc: var(--muted); }
.dot.sport { background: var(--sc); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; padding: 1px 7px 1px 5px;
  border-radius: 99px; background: var(--surface); color: var(--text-2); white-space: nowrap; }
.chip .dot { width: 8px; height: 8px; }

/* ---------- séances */
.session {
  display: flex; gap: .65rem; align-items: flex-start; padding: .55rem .7rem; border-radius: 10px;
  background: var(--surface-2); border-left: 4px solid var(--sc, var(--muted)); color: var(--text);
}
.session:hover { text-decoration: none; filter: brightness(.98); }
.session + .session { margin-top: 6px; }
.session .t { font-weight: 600; font-size: .9rem; line-height: 1.3; }
.session .m { color: var(--text-2); font-size: .8rem; }
.session.status-done { opacity: .75; }
.session.status-done .t::after { content: " ✓"; color: var(--good-ink); }
.session.status-skipped .t { text-decoration: line-through; color: var(--muted); }

.week-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.day { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px; min-height: 120px; }
.day.today { outline: 2px solid var(--accent); outline-offset: -1px; }
.day .dh { font-size: .8rem; color: var(--text-2); margin-bottom: 6px; display: flex; justify-content: space-between; }
.day .rest { color: var(--muted); font-size: .8rem; font-style: italic; }
@media (max-width: 900px) { .week-grid { grid-template-columns: 1fr; } .day { min-height: 0; } }

/* ---------- frise des phases */
.timeline { display: flex; gap: 2px; overflow-x: auto; padding-bottom: 4px; }
.timeline a { flex: 1 0 22px; min-width: 22px; height: 34px; border-radius: 4px; position: relative;
  background: var(--ph); display: block; }
.timeline a.rec { opacity: .45; }
.timeline a.sel { outline: 2px solid var(--text); outline-offset: 1px; }
.timeline a.cur::after { content: ""; position: absolute; left: 50%; bottom: -7px; width: 6px; height: 6px;
  border-radius: 50%; background: var(--text); transform: translateX(-50%); }
.ph-prep { --ph: var(--ph-prep); } .ph-base { --ph: var(--ph-base); } .ph-build { --ph: var(--ph-build); }
.ph-peak { --ph: var(--ph-peak); } .ph-taper { --ph: var(--ph-taper); } .ph-race { --ph: var(--ph-race); }
.ph-post, .ph-transition { --ph: var(--ph-post); }
.legend { display: flex; flex-wrap: wrap; gap: .3rem 1rem; font-size: .82rem; color: var(--text-2); margin-top: .6rem; }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; background: var(--ph, var(--sc)); }

/* ---------- tableaux */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .45rem .55rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-2); font-weight: 600; font-size: .8rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }

/* ---------- forme du jour */
.ready { display: flex; gap: 1rem; align-items: center; }
.ready .score { font-size: 2.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.ready-vert .score { color: var(--good-ink); }
.ready-orange .score { color: var(--warn-ink); }
.ready-rouge .score { color: var(--crit-ink); }
.ready .icon { font-size: 1.6rem; }
ul.reasons { margin: .4rem 0 0; padding-left: 1.1rem; color: var(--text-2); font-size: .88rem; }

/* ---------- séance détaillée */
.steps { list-style: none; padding: 0; margin: 0; }
.steps li { padding: .5rem .7rem; border-left: 3px solid var(--sc); background: var(--surface-2); border-radius: 6px; }
.steps li + li { margin-top: 6px; }
.steps .rep { border-left-style: double; border-left-width: 5px; }
.steps .rep ul { list-style: none; padding: 0; margin: .4rem 0 0; }
.steps .rep ul li { background: var(--surface); }
.steps .kind { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
pre.desc { white-space: pre-wrap; font: inherit; margin: 0; color: var(--text-2); }

/* ---------- graphiques */
.chart { position: relative; height: 260px; }
.chart.tall { height: 320px; }
.chart.short { height: 160px; }
.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 99px; }
details > summary { cursor: pointer; color: var(--text-2); font-size: .9rem; }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { display: flex; gap: .5rem; padding: .3rem 0; align-items: center; }
.checklist .ok { color: var(--good-ink); font-weight: 700; }
.checklist .todo { color: var(--muted); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; font-size: .92rem; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; }

/* Page de connexion */
.card.access { max-width: 380px; margin: 10vh auto 0; }
