:root {
  --choco: #5a3320; --choco-2: #7a4a2c; --cuivre: #c9823f; --creme: #fbf3e6; --creme-2: #f3e5cf;
  --vert: #5e8f41; --vert-clair: #e5f0dc; --ink: #2b1a10; --ink-2: #6b5546; --ligne: #e6d6bf;
  --surface: #fffaf2; --alerte: #b5452b; --alerte-clair: #f8e1da; --ok: #3f7a2c;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--creme);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.err { color: var(--alerte); min-height: 1.2em; }
.hidden { display: none !important; }

/* En-tête */
header.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--choco); color: var(--creme);
}
header.top img { width: 40px; height: 40px; border-radius: 10px; background: #000; }
header.top .titre { font-weight: 700; font-size: 1.15rem; }
header.top .sous { font-size: .8rem; opacity: .85; }
header.top .spacer { flex: 1; }

main.app { max-width: 760px; margin: 0 auto; padding: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--ligne); border-radius: var(--radius);
  padding: 14px; margin-bottom: 14px;
}
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }

/* Tuiles */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--surface); border: 1px solid var(--ligne); border-radius: var(--radius); padding: 10px 12px; }
.tile .v { font-size: 1.5rem; font-weight: 700; color: var(--ink); }
.tile .l { font-size: .78rem; color: var(--ink-2); }

/* Boutons & champs */
.btn {
  appearance: none; border: 1px solid var(--ligne); background: var(--surface); color: var(--ink);
  border-radius: 10px; padding: 9px 14px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--choco); color: var(--creme); border-color: var(--choco); }
.btn.vert { background: var(--vert); color: #fff; border-color: var(--vert); }
.btn.danger { color: var(--alerte); }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; border-color: rgba(255,255,255,.4); color: var(--creme); }
label { display: block; font-size: .85rem; color: var(--ink-2); margin-bottom: 8px; }
input[type=range] { accent-color: var(--choco); padding: 0; border: 0; background: none; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 9px 10px; font: inherit; color: var(--ink);
  background: #fff; border: 1px solid var(--ligne); border-radius: 10px;
}
textarea { min-height: 60px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--cuivre); outline-offset: 1px; }

/* Filtres segmentés */
.seg { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.seg button {
  flex: 0 0 auto; border: 1px solid var(--ligne); background: var(--surface); border-radius: 999px;
  padding: 6px 12px; font: inherit; font-size: .9rem; cursor: pointer; color: var(--ink);
}
.seg button.on { background: var(--choco); color: var(--creme); border-color: var(--choco); }

/* Navigation basse */
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; background: var(--surface);
  border-top: 1px solid var(--ligne); padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs button {
  flex: 1; border: 0; background: none; padding: 8px 2px 9px; font: inherit; font-size: .72rem;
  color: var(--ink-2); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
nav.tabs button .ico { width: 24px; height: 24px; }
nav.tabs button.on { color: var(--choco); font-weight: 700; }
.fab {
  position: fixed; right: 16px; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 21;
  width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--vert); color: #fff;
  font-size: 2rem; line-height: 1; box-shadow: 0 6px 18px rgba(60,35,20,.3); cursor: pointer;
}

/* Graphiques */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--ligne); stroke-width: 1; }
.chart .axis text { fill: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--cuivre); }
.chart .bar.vide { fill: var(--creme-2); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + .bar, .chart g.on .bar { fill: var(--choco-2); }
.chart .cible { stroke: var(--vert); stroke-width: 2; stroke-dasharray: 6 4; }
.chart .cible-lbl { fill: var(--ok); font-size: 11px; font-weight: 600; }
.chart .ligne { fill: none; stroke: var(--choco-2); stroke-width: 2; }
.chart .aire { fill: url(#grad-poids); }
.chart .tete-ring { fill: var(--surface); stroke: var(--choco-2); stroke-width: 2.5; }
.chart .tete-lbl { fill: var(--ink); font-size: 12px; font-weight: 700; paint-order: stroke; stroke: var(--surface); stroke-width: 4px; }
.chart .tete { cursor: pointer; }
.chart .pt { fill: var(--choco-2); stroke: var(--surface); stroke-width: 2; }
.tip {
  position: absolute; pointer-events: none; background: var(--ink); color: var(--creme); font-size: .8rem;
  padding: 6px 9px; border-radius: 8px; white-space: nowrap; transform: translate(-50%, -110%); z-index: 5;
}

/* Listes de repas */
.jour { margin-bottom: 12px; }
.jour-tete { display: flex; justify-content: space-between; align-items: baseline; font-weight: 700;
  padding: 6px 2px; border-bottom: 1px solid var(--ligne); }
.jour-tete .k { font-weight: 600; font-size: .9rem; color: var(--ink-2); }
.repas { display: flex; gap: 10px; padding: 9px 2px; border-bottom: 1px dashed var(--ligne); cursor: pointer; }
.repas:last-child { border-bottom: 0; }
.repas .m { width: 70px; flex: 0 0 auto; font-size: .82rem; color: var(--ink-2); text-transform: capitalize; }
.repas .d { flex: 1; font-size: .92rem; }
.repas .k { font-weight: 700; white-space: nowrap; }
.badge { display: inline-block; font-size: .72rem; padding: 1px 7px; border-radius: 999px; margin-left: 4px;
  background: var(--alerte-clair); color: var(--alerte); font-weight: 600; }
.badge.ok { background: var(--vert-clair); color: var(--ok); }
.mois-tete { margin: 18px 0 6px; display: flex; justify-content: space-between; align-items: baseline; }
.mois-tete h3 { margin: 0; text-transform: capitalize; }

table.t { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.t th, table.t td { text-align: left; padding: 7px 4px; border-bottom: 1px solid var(--ligne); }
table.t td.n, table.t th.n { text-align: right; font-variant-numeric: tabular-nums; }
.vide-msg { text-align: center; color: var(--ink-2); padding: 18px 6px; }

/* Ration */
.ration-res .ligne-r { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--ligne); }
.ration-res .ligne-r b { font-variant-numeric: tabular-nums; }
.ration-res .tot { font-weight: 700; border-bottom: 0; }

/* Feuille modale */
dialog.sheet {
  border: 0; padding: 0; width: min(560px, 100%); max-height: 92vh; border-radius: 18px 18px 0 0;
  margin: auto auto 0; background: var(--creme); color: var(--ink);
}
@media (min-width: 600px) { dialog.sheet { border-radius: 18px; margin: auto; } }
dialog.sheet::backdrop { background: rgba(43,26,16,.45); }
dialog .sheet-in { padding: 16px; overflow-y: auto; max-height: 92vh; }
.item-row { display: grid; grid-template-columns: 1fr 86px 36px; gap: 6px; align-items: end; margin-bottom: 8px; }
.item-row input, .item-row select { margin-top: 0; }
.item-row .x { height: 40px; }
.total-repas { font-weight: 700; font-size: 1.1rem; text-align: right; margin: 6px 0 12px; }

/* Connexion */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card { width: min(380px, 100%); text-align: center; background: var(--surface);
  border: 1px solid var(--ligne); border-radius: 20px; padding: 26px 22px; }
.login-card img { border-radius: 24px; }
.login-card h1 { color: var(--choco); margin-top: 8px; }
.login-card form { text-align: left; margin-top: 16px; }
.login-card .btn { width: 100%; margin-top: 6px; }

/* CMV */
.cmv-box { border: 1px solid var(--ligne); border-radius: 12px; padding: 10px 12px 12px; margin: 4px 0 12px; background: var(--creme); }
.cmv-box legend { font-size: .85rem; font-weight: 700; color: var(--choco); padding: 0 4px; }
.cmv-grid { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; gap: 6px; align-items: end; }
.cmv-grid label { margin-bottom: 6px; }
.cmv-grid .pour { padding-bottom: 16px; color: var(--ink-2); font-size: .85rem; }
.ration-res .ligne-r.cmv { border-bottom: 0; }
.ration-res .cmv-txt { margin: 0 0 10px; padding: 8px 10px; background: var(--vert-clair); border-radius: 10px; }
