/* ---------- Palettes (docs/decisions-design.md) ---------- */
:root, [data-palette="lavande"] {
  --bg: #F6F3FC; --card: #FFFFFF; --ink: #2D2548; --mute: #756C96;
  --accent: #7C5CD6; --alt: #2FA38A; --alert: #D9507A; --soft: #E6DEF7;
  color-scheme: light;
}
[data-palette="nuit"] {
  --bg: #171C33; --card: #222949; --ink: #ECEEFA; --mute: #9AA1C7;
  --accent: #A99BF0; --alt: #6FC7B5; --alert: #F08A8A; --soft: #343C69;
  color-scheme: dark;
}
[data-palette="peche"] {
  --bg: #FFF6EF; --card: #FFFFFF; --ink: #4A2E22; --mute: #8C6F60;
  --accent: #E07A5F; --alt: #3D9A8B; --alert: #C8553D; --soft: #FBE3D6;
  color-scheme: light;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Instrument Sans", system-ui, -apple-system, sans-serif; font-size: 16px; line-height: 1.45;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1 { font-size: 22px; font-weight: 700; margin: 0; line-height: 1.2; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 10px; }
.muted { color: var(--mute); }
.small { font-size: 13px; }
.error { color: var(--alert); font-size: 14px; min-height: 1em; margin: 0; }
.empty, .loading { color: var(--mute); text-align: center; padding: 32px 0; }
.pre { white-space: pre-wrap; margin: 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row.gap { justify-content: flex-start; flex-wrap: wrap; }

/* ---------- Écran ---------- */
.screen {
  max-width: 520px; margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px;
}

.top { display: flex; align-items: center; gap: 8px; padding: 4px 0 6px; }
.top-text { flex: 1; min-width: 0; }
.top-text p { margin: 2px 0 0; color: var(--mute); font-size: 13px; }
.nav { border: 0; background: none; font-size: 28px; line-height: 1; padding: 0 6px; color: var(--mute); }
.dots { display: flex; gap: 6px; margin-left: 4px; }
.dot {
  width: 14px; height: 14px; padding: 0; border-radius: 50%; border: 0; background: var(--c);
  box-shadow: 0 0 0 2px var(--bg);
}
.dot.on { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--ink); }

.card {
  background: var(--card); border: 1px solid var(--soft); border-radius: 14px; padding: 14px 16px;
}
.card.soft { background: var(--soft); border-color: var(--soft); }

/* ---------- Boutons ---------- */
.btn {
  border: 1px solid var(--soft); background: var(--card); border-radius: 999px;
  padding: 9px 16px; font-size: 14px; font-weight: 600; margin-top: 10px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--card); }
.btn.ghost { background: none; border: 0; padding: 4px 0; margin: 0; }
.btn.wide { width: 100%; padding: 13px; font-size: 15px; }
.link { border: 0; background: none; color: var(--mute); text-decoration: underline; font-size: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--mute); background: none; border-radius: 999px;
  padding: 6px 13px; font-size: 14px; font-weight: 500; display: inline-flex; align-items: center; gap: 4px;
}
.chip.small { padding: 4px 11px; font-size: 13px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--card); }
.chip.on.alert { background: var(--alert); border-color: var(--alert); }
.chip.on.alt { background: var(--alt); border-color: var(--alt); }
.chip.dashed { border-style: dashed; }
.chip .x { margin-right: -4px; }
.lvl { letter-spacing: 1px; }
.pill { border-radius: 999px; padding: 4px 12px; font-size: 13px; font-weight: 600; color: var(--card); }
.pill.alert { background: var(--alert); }
.pill.alt { background: var(--alt); }

.x { border: 0; background: none; color: var(--mute); font-size: 18px; line-height: 1; padding: 0 4px; }

/* ---------- Formulaires ---------- */
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="time"], textarea {
  width: 100%; border: 1px solid var(--soft); background: var(--bg); border-radius: 10px; padding: 9px 11px;
}
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 12px 0 4px; height: 28px; }
.big { font-size: 26px; font-weight: 700; color: var(--accent); }
.add { display: flex; gap: 6px; margin: 4px 0 10px; }
.add input[type="time"] { width: 96px; flex: none; }
input.min { width: 72px; flex: none; }
textarea { resize: vertical; }

.items { list-style: none; margin: 0 0 10px; padding: 0; }
.items li { display: flex; align-items: baseline; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--soft); }
.items .time { color: var(--mute); font-size: 13px; width: 42px; flex: none; }
.grow { flex: 1; min-width: 0; }
.grow small { display: block; color: var(--mute); }

/* ---------- Connexion ---------- */
.login { display: flex; flex-direction: column; gap: 12px; margin-top: 12vh; padding: 24px 20px; }
.login label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 600; }
.login .btn { margin: 0; }

/* ---------- Chronologie ---------- */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before {
  content: ""; position: absolute; left: 58px; top: 8px; bottom: 8px; width: 3px; border-radius: 2px; background: var(--soft);
}
.timeline li { display: grid; grid-template-columns: 44px 18px 1fr; align-items: center; gap: 0 8px; margin-bottom: 10px; }
.timeline .time { color: var(--mute); font-size: 13px; font-weight: 500; }
.timeline .mark { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--bg); position: relative; left: 1px; }
.timeline .card { padding: 10px 14px; }
.timeline strong { display: block; font-size: 15px; }
.timeline small { color: var(--mute); font-size: 14px; }
.k-meal .mark { background: var(--accent); }
.k-act .mark { background: var(--alt); }
.k-sym .mark { background: var(--alert); }
.hint { text-align: left; }
.fab {
  position: fixed; right: max(20px, calc(50% - 240px)); bottom: calc(84px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: var(--card);
  display: grid; place-items: center; font-size: 32px; text-decoration: none; box-shadow: 0 4px 14px rgb(0 0 0 / .18);
}

/* ---------- Semaine ---------- */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { padding: 10px 12px; }
.tile b { display: block; font-size: 22px; }
.tile small { color: var(--mute); font-size: 12px; }
.c-accent { color: var(--accent); }
.c-alert { color: var(--alert); }
.legend { font-size: 12px; color: var(--mute); display: flex; align-items: center; gap: 4px; }
.legend i { display: inline-block; width: 14px; height: 0; border-top: 3px solid var(--accent); margin-left: 6px; }
.legend i.l-fat { border-top: 2px dashed var(--alt); }
.chart { width: 100%; height: auto; display: block; font-family: inherit; }
.chart .grid { stroke: var(--soft); }
.chart .axis { fill: var(--mute); font-size: 9px; text-anchor: end; }
.chart .day { fill: var(--mute); font-size: 10px; font-weight: 600; text-anchor: middle; }
.chart .pain { fill: none; stroke: var(--accent); stroke-width: 2.8; stroke-linejoin: round; stroke-linecap: round; }
.chart .pain-dot { fill: var(--card); stroke: var(--accent); stroke-width: 2; }
.chart .fat { fill: none; stroke: var(--alt); stroke-width: 2; stroke-dasharray: 5 3; stroke-linejoin: round; }
.chart .fat-dot { fill: var(--card); stroke: var(--alt); stroke-width: 2; r: 2.5; }
.chart .val { fill: var(--ink); font-size: 9px; font-weight: 700; text-anchor: middle; }
.chart .hl { fill: var(--alert); opacity: .16; }
.chart .period { fill: var(--alert); opacity: .85; }
.chart .period-label { fill: var(--card); font-size: 8px; font-weight: 700; }
.chart .pill-out { fill: var(--card); stroke: var(--alt); stroke-width: 1.2; }
.chart .pill-in { fill: var(--alt); }
.chart .pill-label { fill: var(--ink); font-size: 8px; font-weight: 600; }
.chart .sport { fill: var(--alt); font-size: 9px; font-weight: 700; text-anchor: middle; }
.bullet { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 8px; vertical-align: middle; }

/* ---------- Réglages ---------- */
.palettes { display: flex; flex-direction: column; gap: 6px; }
.palette {
  display: flex; align-items: center; gap: 8px; text-align: left; border: 1px solid var(--soft);
  background: none; border-radius: 10px; padding: 8px 12px;
}
.palette.on { border-color: var(--ink); font-weight: 600; }
.palette i { width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--soft); }

/* ---------- Barre d'onglets ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center; gap: 4px;
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(10px);
  border-top: 1px solid var(--soft); padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabs[hidden] { display: none; }
.tabs a {
  flex: 1; max-width: 130px; text-align: center; padding: 10px 4px; border-radius: 10px;
  color: var(--mute); text-decoration: none; font-size: 13px; font-weight: 600;
}
.tabs a.on { color: var(--accent); background: var(--soft); }

/* ---------- Message temporaire ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20;
}
#toast.show { opacity: 1; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
