:root {
  --bg: #f4f3f8; --card: #ffffff; --fg: #1c1930; --sub: #6d6a80; --muted: #d9d7e3;
  --line: #e7e5ee; --accent: #5b4bdb; --accent-fg: #fff; --good: #2e9d57; --bad: #d64545;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121019; --card: #1d1a28; --fg: #f1effa; --sub: #9a96ad; --muted: #3a364a;
          --line: #2c2939; --accent: #8a7dff; --accent-fg: #121019; --good: #4cc27a; --bad: #ff6b6b; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  padding: env(safe-area-inset-top) 0 calc(72px + env(safe-area-inset-bottom));
}
main { max-width: 560px; margin: 0 auto; padding: 0 16px 24px; }
a { color: var(--accent); }

.top { padding: 18px 2px 10px; }
h1 { font-size: 30px; font-weight: 800; letter-spacing: -.02em; margin: 0; }
h2 { font-size: 20px; margin: 26px 2px 10px; }
h3 { font-size: 15px; margin: 0 0 12px; color: var(--sub); font-weight: 600; }
.sub { margin: 2px 0 0; color: var(--sub); font-size: 15px; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.label { display: block; font-weight: 600; font-size: 14px; margin: 16px 0 8px; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; }
.label-row .label { margin-top: 0; }
.hint { color: var(--sub); font-weight: 400; font-size: 13px; }

/* Échelle 1-10 */
.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.scale label { position: relative; }
.scale input { position: absolute; opacity: 0; inset: 0; }
.scale span {
  display: flex; align-items: center; justify-content: center; height: 56px; border-radius: 14px;
  font-size: 22px; font-weight: 700; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent);
  border: 2px solid transparent; transition: transform .12s, background .12s;
}
.scale input:checked + span { background: var(--c); color: #fff; transform: scale(1.06); box-shadow: 0 4px 14px color-mix(in srgb, var(--c) 45%, transparent); }
.scale input:focus-visible + span { border-color: var(--fg); }

input[type=text], input[type=datetime-local] {
  width: 100%; font: inherit; font-size: 16px; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; min-height: 48px; -webkit-appearance: none; appearance: none;
}
.when-row { display: flex; gap: 8px; }
.when-row input { flex: 1; min-width: 0; }
button { font: inherit; cursor: pointer; }
.ghost { background: var(--bg); color: var(--accent); border: 1px solid var(--line); border-radius: 12px; padding: 0 14px; font-weight: 600; font-size: 15px; white-space: nowrap; }
.primary {
  display: block; width: 100%; margin-top: 20px; height: 54px; border: 0; border-radius: 14px;
  background: var(--accent); color: var(--accent-fg); font-size: 17px; font-weight: 700;
}
.primary:disabled { opacity: .4; }

.flash { background: color-mix(in srgb, var(--good) 15%, var(--card)); color: var(--good); font-weight: 600; padding: 12px 16px; border-radius: 12px; margin-bottom: 12px; animation: fade 3s forwards 1.5s; }
.flash.bad { background: color-mix(in srgb, var(--bad) 15%, var(--card)); color: var(--bad); }
@keyframes fade { to { opacity: 0; height: 0; padding: 0; margin: 0; } }
.last { color: var(--sub); font-size: 14px; margin: 4px 2px; }
.empty { color: var(--sub); text-align: center; font-size: 14px; margin: 16px 0; }

/* Liste */
.list { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 8px 12px 14px; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.badge { flex: none; width: 38px; height: 38px; border-radius: 50%; background: var(--c); color: #fff; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.meta strong { font-weight: 600; font-size: 15px; }
.meta small { color: var(--sub); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.del { width: 40px; height: 40px; border: 0; background: none; color: var(--sub); font-size: 24px; line-height: 1; border-radius: 50%; }
.del:active { background: var(--bg); color: var(--bad); }

/* Barre d'onglets */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; gap: 0;
  background: color-mix(in srgb, var(--card) 85%, transparent); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { flex: 1; max-width: 200px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; color: var(--sub); text-decoration: none; font-size: 11px; font-weight: 600; }
.tabbar svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.tabbar a.on { color: var(--accent); }

/* Statistiques */
.seg { display: flex; background: var(--muted); border-radius: 10px; padding: 2px; margin-bottom: 14px; }
.seg a { flex: 1; text-align: center; padding: 8px 0; border-radius: 8px; color: var(--fg); text-decoration: none; font-size: 14px; font-weight: 600; }
.seg a.on { background: var(--card); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--card); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; }
.k-label { font-size: 13px; color: var(--sub); font-weight: 600; }
.k-val { font-size: 32px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.k-sub { font-size: 12.5px; color: var(--sub); }
.k-sub.up { color: var(--bad); } .k-sub.down { color: var(--good); }

.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .ax { fill: var(--sub); font-size: 9.5px; font-family: inherit; }
.chart .ax.avg { fill: var(--accent); }
.chart .avgline { fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linejoin: round; opacity: .9; }
.chart .avgdot { fill: var(--card); stroke: var(--accent); stroke-width: 1.6; }
.legend { font-size: 12px; color: var(--sub); margin: 10px 0 0; line-height: 1.7; }
.legend .sw, .legend .ln { display: inline-block; vertical-align: middle; margin-right: 5px; }
.legend .sw { width: 10px; height: 10px; border-radius: 2px; background: linear-gradient(90deg, hsl(130,72%,48%), hsl(40,72%,48%), hsl(0,72%,48%)); }
.legend .ln { width: 14px; height: 2px; background: var(--accent); margin-left: 8px; }

.hbars { display: flex; flex-direction: column; gap: 6px; }
.hb { display: flex; align-items: center; gap: 10px; font-size: 13px; font-variant-numeric: tabular-nums; }
.hb-l { width: 18px; text-align: right; font-weight: 700; }
.hb-t { flex: 1; height: 14px; background: var(--bg); border-radius: 7px; overflow: hidden; }
.hb-t span { display: block; height: 100%; border-radius: 7px; min-width: 0; }
.hb-v { width: 28px; color: var(--sub); }

.tbl { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; color: var(--sub); font-weight: 600; font-size: 12px; padding: 0 4px 6px; }
.tbl td { padding: 8px 4px; border-top: 1px solid var(--line); }
.tbl th:not(:first-child), .tbl td:not(:first-child) { text-align: right; }
.tbl tr.zero td { color: var(--sub); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
