/* Plan Transfo — mobile first, compact et carré. Thème clair/sombre par tokens. */
:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #ecebe7;
  --border: #d9d8d3;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #0a7d3b;
  --bad: #c0362c;
  --warn: #9a6500;
  --series-1: #2a78d6;
  --series-muted: #9b9a95;
  --grid: #e3e2de;
  --radius: 4px;
  --tabbar-h: 56px;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #101113;
    --surface: #1a1a19;
    --surface-2: #252524;
    --border: #34342f;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e88;
    --accent: #3987e5;
    --good: #3cb371;
    --bad: #e66767;
    --warn: #e0a030;
    --series-1: #3987e5;
    --series-muted: #6d6c67;
    --grid: #2b2b29;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101113; --surface: #1a1a19; --surface-2: #252524; --border: #34342f;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e88; --accent: #3987e5;
  --good: #3cb371; --bad: #e66767; --warn: #e0a030;
  --series-1: #3987e5; --series-muted: #6d6c67; --grid: #2b2b29;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h1 { font-size: 20px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); }
h3 { font-size: 15px; }
p { margin: 4px 0; }
button, input, textarea, select { font: inherit; color: inherit; }

.view {
  max-width: 640px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 10px) 12px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 64px);
  display: flex; flex-direction: column; gap: 8px;
}
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.right { text-align: right; }
.error { color: var(--bad); }
.danger { color: var(--bad) !important; }
.grow { flex: 1; }

/* Cartes */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }

/* Navigation de date */
.datenav { display: flex; align-items: center; gap: 6px; }
.datenav-label { flex: 1; text-align: center; display: flex; flex-direction: column; text-transform: capitalize; }
.subhead { color: var(--text-2); font-size: 13px; text-align: center; }
.save-status { color: var(--muted); font-size: 12px; margin-left: 4px; }

/* Boutons */
.btn {
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 8px 12px; font-weight: 600; cursor: pointer; min-height: 38px;
}
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.small { padding: 4px 8px; min-height: 34px; }
.btn.full { width: 100%; }
.icon-btn {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  width: 38px; height: 38px; font-size: 20px; line-height: 1; cursor: pointer;
}
.icon-btn.small { width: 30px; height: 34px; font-size: 16px; }
.link { background: none; border: 0; padding: 2px 4px; color: var(--accent); cursor: pointer; font-size: 13px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 8px; display: flex; flex-direction: column; }
.kpi-value { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-label { font-size: 11.5px; color: var(--muted); }
.kpi.good .kpi-value { color: var(--good); }
.kpi.bad .kpi-value { color: var(--bad); }

/* Champs */
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 8px; }
.field { display: flex; flex-direction: column; gap: 2px; }
.field-label { font-size: 12px; color: var(--text-2); margin-top: 4px; }
.field-input { display: flex; align-items: center; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); }
.field-input:focus-within { border-color: var(--accent); }
.field-input input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 7px 8px; font-size: 16px; outline: none; font-variant-numeric: tabular-nums; }
.unit { padding-right: 8px; color: var(--muted); font-size: 13px; }
textarea { width: 100%; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); padding: 7px 8px; font-size: 16px; resize: vertical; }
textarea:focus { outline: none; border-color: var(--accent); }

/* Contrôle segmenté */
.seg { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.seg button { flex: 1; border: 0; border-right: 1px solid var(--border); background: transparent; padding: 8px 4px; cursor: pointer; min-height: 36px; white-space: nowrap; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg.scroll { overflow-x: auto; }
.seg.scroll button { min-width: 44px; }

/* Repas */
.meal { border-top: 1px solid var(--border); }
.meal:first-of-type { border-top: 0; }
.meal summary { display: flex; align-items: center; gap: 8px; padding: 7px 0; cursor: pointer; list-style: none; }
.meal summary::-webkit-details-marker { display: none; }
.meal-check input, .checklist input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.meal-name { flex: 1; }
.meal-macro { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.items { list-style: none; margin: 0 0 6px 28px; padding: 0; font-size: 13px; }
.items li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.total-bar { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 13px; padding: 2px 2px; }

/* Tableaux */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th, .tbl td { padding: 5px 4px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.tbl tr:last-child th, .tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl thead th { font-size: 12px; color: var(--text-2); font-weight: 600; }
.tbl-scroll { overflow-x: auto; margin: 0 -4px; }
.tbl.report th:first-child { position: sticky; left: 0; background: var(--surface); white-space: nowrap; font-weight: 500; }
.tbl tr.clickable { cursor: pointer; }
.tbl.history td:first-child { white-space: nowrap; }
.checklist { list-style: none; margin: 6px 0; padding: 0; }
.checklist li { border-bottom: 1px solid var(--border); }
.checklist label { display: flex; align-items: center; gap: 10px; padding: 8px 0; cursor: pointer; }
.checklist input:checked ~ .grow { text-decoration: line-through; color: var(--muted); }

/* Séance */
.warmup { padding: 0 2px; }
.ex-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px; }
.ex-head h3 { flex: 1 1 100%; margin: 0; }
.chip { font-size: 12px; border: 1px solid var(--border); border-radius: var(--radius); padding: 1px 6px; background: var(--surface-2); }
.chip.ghost { background: transparent; color: var(--muted); }
.advice { font-size: 13.5px; border-left: 3px solid var(--muted); padding: 3px 8px; margin: 8px 0; background: var(--surface-2); }
.advice.up { border-color: var(--good); }
.advice.down { border-color: var(--bad); }
.advice.keep, .advice.ok { border-color: var(--accent); }
.setrows { display: flex; flex-direction: column; gap: 6px; }
.setrow { display: grid; grid-template-columns: 26px 1fr 1fr 1fr 40px 30px; gap: 5px; align-items: center; }
.setrow.head { margin-bottom: -2px; }
.setrow.head span { text-align: center; }
.setrow input {
  width: 100%; min-width: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg);
  padding: 7px 4px; text-align: center; font-size: 16px; font-variant-numeric: tabular-nums;
}
.setrow input:focus { outline: none; border-color: var(--accent); }
.setrow input:disabled { opacity: .4; }
.setrow.done input { border-color: var(--good); }
.set-no { font-weight: 600; font-size: 13px; color: var(--text-2); }
.set-hint { grid-column: 2 / -1; margin-top: -3px; }

/* Graphiques */
.chart-block { display: flex; flex-direction: column; gap: 4px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 14px; height: 2px; background: var(--series-1); }
.key.dots { width: 6px; height: 6px; border-radius: 50%; }
.key.bars { width: 8px; height: 10px; border-radius: 1px; }
.key.s-muted { background: var(--series-muted); }
.chart { position: relative; width: 100%; min-height: 190px; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.chart .ref { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 4 3; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.s-1 { stroke: var(--series-1); }
.chart .dot.s-muted { fill: var(--series-muted); stroke: var(--surface); stroke-width: 1.5; }
.chart .bar.s-1 { fill: var(--series-1); }
.chart .cross { stroke: var(--text-2); stroke-width: 1; }
.chart .empty { padding: 60px 0; text-align: center; }
.chart-tip {
  position: absolute; top: 4px; width: 184px; pointer-events: none; font-size: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 5px 7px; box-shadow: 0 2px 8px rgb(0 0 0 / .12);
}
.tip-date { color: var(--text-2); margin-bottom: 2px; text-transform: capitalize; }
.tip-row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }

/* Photos */
.poses { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 6px 0; }
.pose { display: flex; flex-direction: column; gap: 2px; }
.pose img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--border); display: block; }
.pose.empty .btn { aspect-ratio: 3 / 4; width: 100%; font-weight: 500; font-size: 13px; }
.pose-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0 2px; }
.phase { border-left: 3px solid var(--border); padding: 4px 8px; margin: 6px 0; }
.phase.current { border-color: var(--accent); background: var(--surface-2); }

/* Login */
.login { margin-top: 18vh; display: flex; flex-direction: column; gap: 10px; }
.login input { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; font-size: 16px; background: var(--bg); }

/* Barres flottantes */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar[hidden] { display: none; }
.tabbar a {
  flex: 1; height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 11px;
}
.tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a[aria-current="page"] { color: var(--accent); font-weight: 600; }
.restbar {
  position: fixed; left: 0; right: 0; z-index: 11; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  display: flex; justify-content: space-between; align-items: center; padding: 8px 14px;
  background: var(--accent); color: var(--accent-ink); font-size: 15px;
}
.restbar[hidden] { display: none; }
.restbar .link { color: var(--accent-ink); text-decoration: underline; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 12;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 52px);
  background: var(--text); color: var(--bg); padding: 8px 12px; border-radius: var(--radius); font-size: 13.5px; max-width: 90vw;
}
.toast[data-tone="error"] { background: var(--bad); color: #fff; }
.toast[hidden] { display: none; }

@media (min-width: 700px) {
  .view { padding-top: 20px; }
  .tabbar { justify-content: center; }
  .tabbar a { flex: 0 0 110px; }
}
