:root {
  color-scheme: light;
  --bg: #E9EEF2;
  --surface: #FFFFFF;
  --ink: #17202B;
  --muted: #5E6B78;
  --line: #CDD6DF;
  --busy: #C3CCD5;
  --accent: #17202B;
  --on-accent: #FFFFFF;
  --sport: #1F8F5F;
  --pro: #2459C9;
  --music: #7B45C9;
  --language: #C77700;
  --startup: #C8364F;
  --other: #6B7785;
  --danger: #B3261E;
  --radius-s: 6px;
  --radius-l: 16px;
  --font: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #10151B;
    --surface: #19212A;
    --ink: #E6ECF1;
    --muted: #93A1AE;
    --line: #2A3540;
    --busy: #34414E;
    --accent: #E6ECF1;
    --on-accent: #10151B;
    --sport: #43C08A;
    --pro: #6F9BFF;
    --music: #B48CF2;
    --language: #F0A43A;
    --startup: #F2667E;
    --other: #93A1AE;
    --danger: #FF8A80;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #10151B; --surface: #19212A; --ink: #E6ECF1; --muted: #93A1AE; --line: #2A3540; --busy: #34414E;
  --accent: #E6ECF1; --on-accent: #10151B;
  --sport: #43C08A; --pro: #6F9BFF; --music: #B48CF2; --language: #F0A43A; --startup: #F2667E; --other: #93A1AE; --danger: #FF8A80;
}

* { box-sizing: border-box; }
:root { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
main { max-width: 640px; margin: 0 auto; padding: 16px 16px 112px; }
h1, h2 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; font-weight: 750; line-height: 1.1; }
h2 { font-size: 1.125rem; font-weight: 600; }
.muted { color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--pro); outline-offset: 2px; }

/* --- boutons --- */
.btn {
  border: 0; border-radius: 999px; padding: 10px 18px; cursor: pointer;
  background: var(--accent); color: var(--on-accent); font-weight: 600;
}
.btn-quiet { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn-danger { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 1.5px currentColor; }
.btn:disabled { opacity: .5; cursor: progress; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--surface); font-size: 1.4rem; line-height: 1;
}

/* --- semaine --- */
.week-head { display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; gap: 8px; margin-bottom: 20px; }
.week-head h1 { text-align: center; font-size: 1.35rem; }

/* La "partition" : chaque jour est une portée, chaque séance une note posée sur le temps. */
.score { display: grid; gap: 6px; }
.stave {
  display: grid; grid-template-columns: 2.6rem 1fr; align-items: center; gap: 10px;
  border: 0; background: none; padding: 0; cursor: pointer; text-align: left;
}
.stave-label { font-weight: 600; color: var(--muted); font-size: .9rem; }
.stave[aria-selected="true"] .stave-label { color: var(--ink); }
.stave-track {
  position: relative; height: 28px; border-radius: var(--radius-s);
  background:
    linear-gradient(var(--line), var(--line)) 0 50% / 100% 1px no-repeat,
    var(--surface);
  overflow: hidden;
}
.stave[aria-selected="true"] .stave-track { box-shadow: inset 0 0 0 2px var(--ink); }
.busy {
  position: absolute; top: 0; bottom: 0;
  background: repeating-linear-gradient(135deg, var(--busy) 0 3px, transparent 3px 7px);
}
.note { position: absolute; top: 5px; bottom: 5px; border-radius: 4px; background: var(--c, var(--other)); }
.note.is-done { opacity: .35; }
.note.is-fixed { top: 2px; bottom: 2px; }
.now-line { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--danger); }
.score-scale {
  display: flex; justify-content: space-between; margin: 6px 0 28px calc(2.6rem + 10px);
  font-size: .75rem; color: var(--muted);
}

.day-head .btn { white-space: nowrap; padding: 8px 14px; font-size: .9rem; }
.day-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.sessions { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.session {
  background: var(--surface); border-radius: var(--radius-l); padding: 14px 16px;
  display: grid; grid-template-columns: 3.4rem 1fr; gap: 4px 12px;
  border-left: 5px solid var(--c, var(--other));
}
.session time { font-weight: 750; font-size: 1.05rem; }
.session .dur { font-size: .8rem; color: var(--muted); }
.session h3 { margin: 0; font-size: 1.05rem; font-weight: 600; }
.session .goal-name { font-size: .85rem; color: var(--muted); }
.session.is-unplaced { padding: 10px 16px; }
.session.is-unplaced .badge { display: none; }
.subhead { margin-top: 14px; font-weight: 600; color: var(--muted); font-size: .92rem; }
.session details { grid-column: 2; font-size: .92rem; }
.session summary { cursor: pointer; color: var(--muted); }
.session .actions { grid-column: 2; display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.session .actions button { padding: 6px 14px; font-size: .9rem; }
.session.is-done h3 { text-decoration: line-through; text-decoration-thickness: 1.5px; }
.session.is-skipped { opacity: .55; }
.badge { font-size: .8rem; color: var(--muted); }
.empty { background: var(--surface); border-radius: var(--radius-l); padding: 18px; color: var(--muted); }

.plan-actions { display: flex; gap: 10px; margin-top: 24px; flex-wrap: wrap; }
.hint { font-size: .85rem; margin-top: 10px; max-width: 60ch; }

/* --- objectifs --- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.goals { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.goal {
  background: var(--surface); border-radius: var(--radius-l); padding: 14px 16px; cursor: pointer;
  display: grid; gap: 6px; border: 0; width: 100%; text-align: left;
}
.goal-top { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.goal-title { font-weight: 600; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--other)); flex: none; }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--c, var(--other)); }
.goal.is-inactive { opacity: .55; }

/* --- réglages --- */
.panel { background: var(--surface); border-radius: var(--radius-l); padding: 16px; margin-bottom: 14px; display: grid; gap: 12px; justify-items: start; }
.panel p { margin: 0; max-width: 60ch; font-size: .92rem; }

/* --- formulaires --- */
.field { display: grid; gap: 6px; font-size: .92rem; font-weight: 600; width: 100%; border: 0; padding: 0; margin: 0; }
.field legend { padding: 0; margin-bottom: 6px; }
.field .muted { font-weight: 400; }
input:not([type="checkbox"]):not([type="range"]):not([type="file"]), select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--line);
  background: var(--bg); font-weight: 400;
}
input[type="range"] { width: 100%; accent-color: var(--ink); }
.field, .row > *, #goal-form > *, #measure-form > *, #app-form > * { min-width: 0; }
.field[hidden] { display: none; }
input, select, textarea { min-width: 0; max-width: 100%; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row:has(> :nth-child(3)) { grid-template-columns: 1.3fr 1.2fr .8fr; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips label {
  font-weight: 400; display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px; box-shadow: inset 0 0 0 1.5px var(--line); cursor: pointer;
}
.chips label:has(input:checked) { background: var(--ink); color: var(--bg); box-shadow: none; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips label:has(input:focus-visible) { outline: 2px solid var(--pro); outline-offset: 2px; }
.check { display: flex; gap: 8px; align-items: center; }

dialog {
  width: min(560px, 100vw); max-width: 100vw; overflow-x: hidden; max-height: 92vh; margin: auto auto 0; padding: 0; border: 0;
  border-radius: 20px 20px 0 0; background: var(--surface); color: var(--ink);
}
@media (min-width: 640px) { dialog { margin: auto; border-radius: 20px; } }
dialog::backdrop { background: rgb(10 15 20 / .45); }
#goal-form, #event-form, #measure-form, #problem-form, #app-form { display: grid; gap: 14px; padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px)); }
.dialog-actions { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }

/* --- navigation --- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabs button { border: 0; background: none; padding: 14px 0; cursor: pointer; color: var(--muted); font-weight: 600; }
.tabs button[aria-current="page"] { color: var(--ink); box-shadow: inset 0 3px 0 var(--ink); }

#toast {
  position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: .92rem;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw;
}
#toast.show { opacity: 1; }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

/* --- engagements perso --- */
.engagement { position: absolute; top: 3px; bottom: 3px; border-radius: 4px; background: var(--ink); opacity: .7; }
.event-item {
  background: transparent; border-radius: var(--radius-l); padding: 12px 16px;
  display: grid; grid-template-columns: 3.4rem 1fr auto; gap: 12px; align-items: center;
  box-shadow: inset 0 0 0 1.5px var(--line);
}
.event-item time { font-weight: 750; }
.event-item .until { font-size: .8rem; color: var(--muted); }
.event-item h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.event-item button { padding: 6px 12px; font-size: .85rem; }

/* --- bilan --- */
.summary { margin-bottom: 28px; max-width: 34ch; }
.summary p { margin: 0; }
.summary .lead { font-size: 1.45rem; font-weight: 600; line-height: 1.25; letter-spacing: -0.01em; }
.summary .lead strong { font-weight: 750; }
.summary .rest { margin-top: 8px; color: var(--muted); }
.section-title { margin: 0 0 12px; }
.chart { margin: 0; background: var(--surface); border-radius: var(--radius-l); padding: 16px 12px 10px; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .due { fill: var(--line); }
.chart .done { fill: var(--ink); }
.chart .lbl { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .lbl.is-current { fill: var(--ink); font-weight: 750; }
.chart .rate { fill: var(--ink); font-size: 11px; font-weight: 600; font-family: var(--font); }
.caption { font-size: .82rem; margin: 8px 0 28px; }
.rev-goals { list-style: none; margin: 0 0 24px; padding: 0; display: grid; gap: 10px; }
.rev-goal { background: var(--surface); border-radius: var(--radius-l); padding: 14px 16px; display: grid; gap: 8px; }
.rev-goal .top { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.rev-goal .name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.rev-goal .meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .85rem; color: var(--muted); }
.spark { display: flex; align-items: flex-end; gap: 3px; height: 28px; }
.spark span { flex: 1; background: var(--c, var(--other)); border-radius: 2px 2px 0 0; min-height: 2px; opacity: .45; }
.spark span:last-child { opacity: 1; }
.coach p { white-space: pre-line; }

/* ---------- Mesures (Bilan) ---------- */
.section-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.mchart { margin-top: 12px; }
.mchart figcaption { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 8px; }
.mtitle { font-weight: 600; color: var(--muted); font-size: .9rem; }
.hero { font-size: 1.5rem; font-weight: 750; color: var(--ink); font-variant-numeric: tabular-nums; }
.hero small { font-size: .8rem; font-weight: 400; color: var(--muted); }
.delta { font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 10px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--c, var(--ink)); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--muted); opacity: .55; }
.chart .end { fill: var(--c, var(--ink)); stroke: var(--surface); stroke-width: 2; }
.chart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; opacity: 0; pointer-events: none; }
.chart svg { touch-action: pan-y; }
.legend { display: flex; align-items: center; gap: 6px; font-size: .8rem; margin-top: 4px; }
.key-line { display: inline-block; width: 16px; height: 2px; background: var(--ink); border-radius: 1px; }
.key-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); opacity: .55; margin-left: 10px; }
.values { margin-top: 8px; font-size: .85rem; }
.values summary { cursor: pointer; color: var(--muted); }
.values table { width: 100%; border-collapse: collapse; margin-top: 6px; font-variant-numeric: tabular-nums; }
.values th, .values td { text-align: right; padding: 3px 6px; border-bottom: 1px solid var(--line); }
.values th:first-child, .values td:first-child { text-align: left; }
.hbars { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.hbars li { display: grid; grid-template-columns: minmax(80px, 30%) 1fr auto; align-items: center; gap: 10px; font-size: .9rem; }
.hbars .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbars .track { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.hbars .track span { display: block; height: 100%; background: var(--c); border-radius: 4px; }
.hbars .val { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 4.5em; text-align: right; }
.hbars .val small { font-weight: 400; color: var(--muted); }
.multiples { list-style: none; margin: 12px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.mult { background: var(--surface); border-radius: var(--radius-l); padding: 12px; }
.mult .hero { font-size: 1.2rem; margin: 2px 0 6px; }
.mult svg { display: block; width: 100%; height: auto; }
.mult .grid { stroke: var(--line); stroke-width: 1; }
.mult .tick { fill: var(--muted); font-size: 9px; font-family: var(--font); }
.mult .line { fill: none; stroke: var(--c); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.mult .end { fill: var(--c); stroke: var(--surface); stroke-width: 2; }
.mult .dot { display: none; }
.mult .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; opacity: 0; pointer-events: none; }
.chart-tip {
  position: absolute; transform: translate(-50%, calc(-100% - 12px)); z-index: 20; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 6px 10px; border-radius: 8px; font-size: .8rem; line-height: 1.35;
  white-space: nowrap; font-variant-numeric: tabular-nums;
}

/* ---------- QRT ---------- */
.qrt-next {
  display: grid; gap: 2px; padding: 14px 16px; margin-bottom: 8px; border-radius: var(--radius-l);
  background: var(--surface); box-shadow: inset 4px 0 0 var(--pro);
}
.qrt-next .lbl { font-size: .8rem; font-weight: 600; color: var(--muted); }
.qrt-next .count { font-size: 1.4rem; font-weight: 750; color: var(--ink); font-variant-numeric: tabular-nums; }
.qrt-list, .qrt-topics, .qrt-apps { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.qrt-pb { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface); border-radius: var(--radius-l); padding: 12px 14px; }
.qrt-pb .name, .qrt-topic .name { font-weight: 600; }
.qrt-pb .actions { display: flex; gap: 6px; }
.small { font-size: .82rem; }
.qrt-upcoming { margin-top: 10px; }
.qrt-upcoming summary { cursor: pointer; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.qrt-topic { background: var(--surface); border-radius: var(--radius-l); padding: 12px 14px; display: grid; gap: 6px; }
.qrt-topic .top, .qrt-topic .meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; font-size: .9rem; }
.qrt-topic .pct { font-weight: 750; font-variant-numeric: tabular-nums; }
.qrt-topic .bar span { display: block; height: 100%; background: var(--pro); border-radius: 3px; }
.qrt-topic .level { display: flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--muted); }
.qrt-topic .level select { width: auto; padding: 4px 8px; }
.qrt-app { display: grid; gap: 4px; width: 100%; text-align: left; background: var(--surface); border: 0; color: var(--ink);
  border-radius: var(--radius-l); padding: 12px 14px; cursor: pointer; font: inherit; box-shadow: inset 4px 0 0 var(--pro); }
.qrt-app.is-closed { box-shadow: inset 4px 0 0 var(--line); opacity: .7; }
.qrt-app .top { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.qrt-app .stage { font-size: .9rem; font-weight: 600; }
.qrt-app .due { font-size: .9rem; font-weight: 600; color: var(--danger); }
.qrt-app span.muted { font-size: .85rem; }
.tabs button { font-size: .88rem; min-width: 0; padding-left: 2px; padding-right: 2px; }
