:root {
  color-scheme: light;
  --bg: #f5f5f3;
  --surface: #fcfcfb;
  --border: #e4e3de;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-pace: #2a78d6;
  --series-hr: #e34948;
  --series-fatigue: #eb6834;
  --pos: #2a78d6; --neg: #e34948;
  --series-alt: #8b8a84;
  --grid: #ecebe6;
  --ok-bg: #e5f4ea; --ok-ink: #1d5e33;
  --err-bg: #fbe9e8; --err-ink: #8f2020;
  --warn-bg: #fdf1dc; --warn-ink: #7a4a00;
  --band: rgba(42, 120, 214, 0.07);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --border: #2e2e2b;
    --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8e86;
    --accent: #3987e5; --series-pace: #3987e5; --series-hr: #e66767; --series-alt: #9a998f;
    --series-fatigue: #d95926; --pos: #3987e5; --neg: #e66767;
    --grid: #2a2a27;
    --ok-bg: #16311f; --ok-ink: #9fdcb3; --err-bg: #3a1a19; --err-ink: #f2aaa8;
    --warn-bg: #362810; --warn-ink: #f1c77e; --band: rgba(57, 135, 229, 0.12);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --border: #2e2e2b;
  --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8e86;
  --accent: #3987e5; --series-pace: #3987e5; --series-hr: #e66767; --series-alt: #9a998f;
  --series-fatigue: #d95926; --pos: #3987e5; --neg: #e66767;
  --grid: #2a2a27;
  --ok-bg: #16311f; --ok-ink: #9fdcb3; --err-bg: #3a1a19; --err-ink: #f2aaa8;
  --warn-bg: #362810; --warn-ink: #f1c77e; --band: rgba(57, 135, 229, 0.12);
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0.4rem 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.8rem; }
h3 { font-size: 0.9rem; margin: 1rem 0 0.3rem; color: var(--text-2); font-weight: 600; }
code { font-size: 0.85em; background: var(--grid); padding: 1px 5px; border-radius: 4px; }

.topbar {
  display: flex; align-items: center; gap: 1.5rem; padding: 0.7rem 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1000;
}
.brand { font-weight: 700; color: var(--text); }
.topbar nav { display: flex; gap: 1rem; }
.topbar nav a { color: var(--text-2); }
.topbar nav a[aria-current="page"] { color: var(--text); font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 1rem 16px 3rem; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 1rem 1.1rem; margin-bottom: 1rem; min-width: 0;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.grid-2 > * { min-width: 0; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.8rem 1rem; display: flex; flex-direction: column;
}
.tile-label { color: var(--text-2); font-size: 0.8rem; }
.tile-value { font-size: 1.6rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile-value small { font-size: 0.85rem; font-weight: 500; color: var(--text-2); }
.tile-sub { color: var(--muted); font-size: 0.8rem; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--border); }
thead th { font-size: 0.78rem; color: var(--text-2); font-weight: 600; }
tbody th { font-weight: 500; color: var(--text-2); }
tr:last-child td, tr:last-child th { border-bottom: none; }
table.compact td, table.compact th { padding: 0.3rem 0.5rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.tag { font-size: 0.72rem; border: 1px solid var(--border); border-radius: 999px; padding: 0 6px; color: var(--text-2); }

.bar-cell { width: 40%; }
.bar { display: block; height: 8px; width: var(--w); min-width: 4px; max-width: 100%; background: var(--series-pace); border-radius: 0 4px 4px 0; }

.chart-box { position: relative; width: 100%; }
.chart-md { height: 240px; }
.chart-sm { height: 170px; }
.chart-xs { height: 110px; }
.map { height: 320px; border-radius: 8px; }

details summary { cursor: pointer; color: var(--text-2); margin-top: 0.5rem; }

.btn {
  display: inline-block; font: inherit; font-weight: 550; cursor: pointer;
  padding: 0.5rem 0.9rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.actions-row { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.actions-row form { margin: 0; }

.flash { padding: 0.7rem 1rem; border-radius: 8px; margin-bottom: 1rem; background: var(--grid); }
.flash-success { background: var(--ok-bg); color: var(--ok-ink); }
.flash-error { background: var(--err-bg); color: var(--err-ink); }

.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 0.8rem; }
.show-sm { display: none; }
@media (max-width: 600px) {
  .hide-sm { display: none; }
  .show-sm { display: initial; }
  td .show-sm, th .show-sm { display: block; }
  th, td, table.compact th, table.compact td { padding-left: 0.3rem; padding-right: 0.3rem; }
  .topbar { gap: 0.9rem; }
  .topbar nav { gap: 0.75rem; }
  .brand-text { display: none; }
}
.empty p { color: var(--text-2); }

.form { display: flex; flex-direction: column; gap: 1rem; align-items: flex-start; }
.field { display: flex; flex-direction: column; gap: 0.3rem; width: 100%; }
.field label { font-weight: 600; font-size: 0.9rem; }
.field input, .field select {
  font: inherit; padding: 0.45rem 0.6rem; border-radius: 8px; width: 11rem; max-width: 100%;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.hint { margin: 0; font-size: 0.82rem; color: var(--text-2); }
.hint.ok { color: var(--ok-ink); }
button.link {
  font: inherit; background: none; border: none; padding: 0; cursor: pointer;
  color: var(--accent); text-decoration: underline;
}
button.link.danger { color: var(--err-ink); }
.explain dt { font-weight: 600; margin-top: 0.7rem; }
.explain dt:first-child { margin-top: 0; }
.explain dd { margin: 0.2rem 0 0; color: var(--text-2); font-size: 0.9rem; }
.zone-chip {
  display: inline-block; min-width: 2.2rem; text-align: center; font-size: 0.78rem; font-weight: 650;
  border-radius: 999px; padding: 1px 6px; color: #0b0b0b;
}
/* Rampe séquentielle bleue : intensité croissante de Z1 à Z5. */
.zone-1 { background: #cde2fb; }
.zone-2 { background: #9ec5f4; }
.zone-3 { background: #6da7ec; }
.zone-4 { background: #2a78d6; color: #fff; }
.zone-5 { background: #184f95; color: #fff; }

/* Répartition du temps par zone (barre empilée) */
.zone-bar { display: flex; gap: 2px; height: 14px; margin: 0.2rem 0 0.8rem; }
.zone-bar span { display: block; height: 100%; min-width: 0; }
.zone-bar span:first-child { border-radius: 4px 0 0 4px; }
.zone-bar span:last-child { border-radius: 0 4px 4px 0; }
.zone-0 { background: var(--grid); color: var(--text-2); }
.zone-row-bar { width: 35%; }
.zone-row-bar .bar { background: var(--series-pace); }
.metric-note { color: var(--text-2); font-size: 0.85rem; margin: 0.2rem 0 0; }
.legend { display: flex; flex-wrap: wrap; gap: 1rem; font-size: 0.82rem; color: var(--text-2); margin: 0 0 0.4rem; }
.legend .key { display: inline-block; width: 16px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 6px; }
.legend .key.dashed { border-top-style: dashed; }
.state { font-weight: 650; }
.tiles-inline { margin-bottom: 0.3rem; }
.tiles-inline .tile { background: var(--bg); border: none; }

/* Objectifs */
.section-title { margin: 1.6rem 0 0.8rem; }
.goal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.goal-head h2 { margin-bottom: 0.15rem; }
.goal-head p { margin: 0 0 0.8rem; }
.countdown {
  font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap;
  background: var(--accent); color: var(--accent-ink); border-radius: 8px; padding: 0.2rem 0.6rem;
}
.tone-ok { color: var(--ok-ink); }
.tone-warn { color: var(--warn-ink); }
.tone-bad { color: var(--err-ink); }
.tile-value.tone-ok, .tile-value.tone-warn, .tile-value.tone-bad { font-size: 1.25rem; line-height: 1.6; }
.goal-edit { margin-top: 0.8rem; }
.goal-edit[open] > summary { margin-bottom: 0.8rem; }
.goal-delete { margin-top: 0.8rem; }
.field textarea {
  font: inherit; padding: 0.45rem 0.6rem; border-radius: 8px; width: 100%; max-width: 22rem;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); resize: vertical;
}
.field textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field input.wide { width: 100%; max-width: 22rem; }
.habit { margin-bottom: 0.9rem; }
.habit-row { display: flex; justify-content: space-between; gap: 0.5rem; }
.progress { height: 6px; background: var(--grid); border-radius: 999px; overflow: hidden; margin: 0.35rem 0 0.25rem; }
.progress span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.progress span.full { background: var(--ok-ink); }

/* Plan */
.prewrap { white-space: pre-line; }
.phases { margin: 0.6rem 0 0; padding-left: 1.3rem; }
.phases li { margin-bottom: 0.4rem; }
pre.code {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 0.7rem;
  font-size: 0.8rem; white-space: pre-wrap; overflow-wrap: anywhere;
}
.past-weeks > summary { margin: 0 0 1rem; }
.week-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.week-head h2 { margin-bottom: 0.3rem; }
.week-current { border-color: var(--accent); }
.phase-chip {
  font-size: 0.72rem; font-weight: 600; color: var(--text-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 8px; vertical-align: middle; white-space: nowrap;
}
.workouts { list-style: none; margin: 0; padding: 0; }
.workout {
  display: grid; grid-template-columns: 4.6rem minmax(0, 1fr) auto; gap: 0.3rem 0.7rem;
  padding: 0.65rem 0; border-bottom: 1px solid var(--border);
}
.workout:last-child { border-bottom: none; }
.w-day { font-weight: 600; font-size: 0.85rem; line-height: 1.3; }
.w-dow { display: block; font-weight: 500; color: var(--muted); }
.w-title { font-weight: 550; }
.kind-chip.zone-4, .kind-chip.zone-5 { color: #fff; }
.kind-chip {
  display: inline-block; font-size: 0.72rem; font-weight: 650; border-radius: 999px;
  padding: 0 7px; margin-right: 0.2rem; color: #0b0b0b; vertical-align: 1px; white-space: nowrap;
}
.w-details summary { margin-top: 0.2rem; }
.w-steps { margin: 0.3rem 0; padding-left: 1.1rem; color: var(--text-2); }
.w-details p { margin: 0.3rem 0; color: var(--text-2); }
.w-run { margin-top: 0.3rem; display: flex; flex-wrap: wrap; gap: 0.15rem 0.7rem; }
.check.ok { color: var(--ok-ink); }
.check.ko { color: var(--warn-ink); }
.status-missed .w-title, .status-missed .w-day { color: var(--muted); }
.badge {
  align-self: start; font-size: 0.72rem; font-weight: 650; white-space: nowrap;
  border-radius: 999px; padding: 1px 8px; border: 1px solid transparent;
}
.badge-done { background: var(--ok-bg); color: var(--ok-ink); }
.badge-partial { background: var(--warn-bg); color: var(--warn-ink); }
.badge-missed { background: var(--err-bg); color: var(--err-ink); }
.badge-today { background: var(--accent); color: var(--accent-ink); }
.badge-planned { border-color: var(--border); color: var(--muted); }
.badge-extra { background: var(--grid); color: var(--text-2); }
.legend .key.band { height: 10px; border: none; background: var(--band); outline: 1px solid var(--border); }
@media (max-width: 600px) {
  .workout { grid-template-columns: minmax(0, 1fr) auto; }
  .w-dow { display: inline; }
  .workout .badge { grid-column: 2; grid-row: 1; }
  .workout .w-main { grid-column: 1 / -1; grid-row: 2; }
}

/* Tableau de bord : en-tête de carte avec sélecteurs de période et de pas */
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.6rem 1rem; margin-bottom: 0.8rem; }
.card-head h2 { margin: 0; }
.controls { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.segmented {
  display: inline-flex; flex-wrap: wrap; border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden; background: var(--bg);
}
.segmented a, .segmented span {
  padding: 0.25rem 0.6rem; font-size: 0.82rem; color: var(--text-2); border-left: 1px solid var(--border);
  white-space: nowrap;
}
.segmented > :first-child { border-left: none; }
.segmented a:hover { text-decoration: none; color: var(--text); background: var(--grid); }
.segmented a[aria-current="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.segmented span[aria-disabled="true"] { color: var(--muted); opacity: 0.5; cursor: not-allowed; }

/* Compte (barre du haut) et page de connexion */
.account { margin-left: auto; position: relative; }
.account summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 0.45rem; }
.account summary::-webkit-details-marker { display: none; }
.avatar {
  display: inline-grid; place-items: center; width: 1.8rem; height: 1.8rem; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 0.85rem;
}
.account-name { color: var(--text-2); font-size: 0.9rem; }
.account-menu {
  position: absolute; right: 0; top: calc(100% + 0.5rem); min-width: 13rem; z-index: 1001;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.7rem 0.9rem;
  display: flex; flex-direction: column; gap: 0.5rem; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
}
.account-menu p { margin: 0; overflow-wrap: anywhere; }
.account-menu form { margin: 0; }
.login-page main.login { max-width: 26rem; padding-top: 12vh; }
.login h1 { margin-top: 0; }
.btn-block { display: block; text-align: center; margin: 1rem 0 0.6rem; }
@media (max-width: 600px) { .account-name { display: none; } }
.accounts { list-style: none; margin: 0; padding: 0; }
.accounts li { display: flex; align-items: flex-start; gap: 0.7rem; padding: 0.7rem 0; border-bottom: 1px solid var(--border); }
.accounts li:last-child { border-bottom: none; }
.account-info { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.hint.spaced { margin-top: 0.9rem; }
.spaced-top { margin-top: 0.8rem; }
/* Coach IA et consentement */
.consent { max-width: 34rem; margin: 2rem auto 0; }
.consent h1 { font-size: 1.4rem; }
.steps-list { padding-left: 1.2rem; margin: 0; }
.steps-list li { margin-bottom: 0.7rem; }
.copy-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 0.3rem; }
.copy-row code { overflow-wrap: anywhere; padding: 0.3rem 0.5rem; }
.btn-small { padding: 0.25rem 0.6rem; font-size: 0.82rem; }
.consent .hint + .hint { margin-top: 0.6rem; }
/* Pages légales et pied de page */
.legal { max-width: 46rem; margin: 0 auto; }
.legal h2 { margin: 1.8rem 0 0.6rem; font-size: 1.1rem; }
.legal p, .legal li { line-height: 1.6; }
.legal ul { padding-left: 1.2rem; }
.legal li { margin-bottom: 0.35rem; }
.legal-summary { margin-top: 1rem; }
.legal-summary h2 { margin-top: 0; }
.legal-table td { vertical-align: top; }
.site-footer { max-width: 1100px; margin: 0 auto; padding: 0 16px 2rem; text-align: center; color: var(--muted); }
.site-footer a { color: var(--text-2); }
.legal-links { text-align: center; }
@media (max-width: 600px) {
  /* Tableau des données en fiches empilées sur petit écran. */
  .legal-table thead { display: none; }
  .legal-table tr { display: block; padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
  .legal-table td { display: block; border: none; padding: 0.15rem 0; }
  .legal-table td::before { content: attr(data-label) " : "; font-weight: 600; color: var(--text-2); }
}
/* Notes du coureur (profil) */
.notes { list-style: none; margin: 0.6rem 0; padding: 0; }
.notes li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.3rem 0.6rem; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.notes li:last-child { border-bottom: none; }
.note-text { flex: 1 1 14rem; min-width: 0; overflow-wrap: anywhere; }
.notes form { margin: 0; }
.note-form { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.6rem; }
.note-form select, .note-form input {
  font: inherit; padding: 0.4rem 0.6rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); min-width: 0;
}
.note-form input { flex: 1 1 14rem; }
/* Guide « Coach IA » pas à pas */
.lead { color: var(--text-2); max-width: 46rem; margin-top: -0.4rem; }
.guide { list-style: none; margin: 1rem 0 0; padding: 0; }
.guide-step { display: flex; gap: 1.5rem; align-items: flex-start; justify-content: space-between; }
.guide-text { flex: 1 1 22rem; min-width: 0; }
.guide-text h2 { display: flex; align-items: center; gap: 0.6rem; }
.guide-text p { margin: 0.4rem 0; }
.step-number {
  display: inline-grid; place-items: center; flex: none; width: 1.8rem; height: 1.8rem; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: 0.95rem;
}
.menu-path { display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; }
.menu-path span {
  border: 1px solid var(--border); background: var(--bg); border-radius: 6px; padding: 0.15rem 0.55rem;
  font-weight: 600; font-size: 0.88rem;
}
.menu-path span + span::before { content: "›"; margin-right: 0.4rem; color: var(--muted); font-weight: 400; }
.fields { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.3rem 0.7rem; margin: 0.4rem 0; }
.fields dt { font-weight: 600; }
.fields dd { margin: 0; overflow-wrap: anywhere; }
.examples { margin: 0.4rem 0; padding-left: 1.2rem; }
.examples li { margin-bottom: 0.3rem; font-style: italic; }
.phone { flex: none; width: min(260px, 100%); }
.phone img {
  display: block; width: 100%; height: auto; border-radius: 16px;
  border: 5px solid #2b2b2e; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}
@media (max-width: 700px) {
  .guide-step { flex-direction: column; gap: 0.8rem; }
  .guide-text { flex: none; width: 100%; }  /* en colonne, 22rem deviendrait une hauteur */
  .phone { align-self: center; width: min(280px, 90%); }
}
