/* Santé : clair ou sombre selon le réglage du téléphone */
:root {
  --fond: #f3f6f4;
  --carte: #ffffff;
  --texte: #17221d;
  --discret: #64736b;
  --bord: #dde5e0;
  --accent: #14805a;
  --accent-doux: #dff1e8;
  --sur-accent: #ffffff;
  --rouge: #c8402e;
  --orange: #d98a12;
  --piste: #e6ece8;
  --ombre: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
  --c-prot: #3b78d8;
  --c-gluc: #d98a12;
  --c-lip: #c0559a;
  --c-fibres: #5b9a2f;
  --c-sel: #7a7f86;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #0f1613;
    --carte: #18221d;
    --texte: #e7efea;
    --discret: #95a59c;
    --bord: #2a3731;
    --accent: #3cc48b;
    --accent-doux: #1b3a2c;
    --sur-accent: #06150e;
    --rouge: #f07462;
    --orange: #f0aa43;
    --piste: #26322c;
    --ombre: none;
    --c-prot: #6ea2f2;
    --c-gluc: #f0aa43;
    --c-lip: #e07fbe;
    --c-fibres: #8cc95f;
    --c-sel: #a3a9b0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--fond);
  color: var(--texte);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
a { color: var(--accent); }
.discret { color: var(--discret); font-size: .9rem; margin: .25rem 0; }
.nombre { font-variant-numeric: tabular-nums; }

button, .bouton {
  font: inherit; border: 0; border-radius: 12px; cursor: pointer; color: inherit; background: none;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
}
button:disabled { opacity: .5; cursor: default; }
.principal, .bouton {
  background: var(--accent); color: var(--sur-accent); padding: .8rem 1.2rem; font-weight: 600; width: 100%;
}
.secondaire { background: var(--piste); padding: .7rem 1rem; width: 100%; font-weight: 500; }
.danger { color: var(--rouge); background: none; padding: .7rem 1rem; width: 100%; }
.petit { background: var(--accent-doux); color: var(--accent); padding: .45rem .8rem; font-weight: 600; font-size: .9rem; }
.icone { width: 44px; height: 44px; font-size: 1.6rem; border-radius: 50%; flex: none; }
.icone:hover { background: var(--piste); }

input, select, textarea {
  font: inherit; color: inherit; background: var(--carte); border: 1px solid var(--bord); border-radius: 10px;
  padding: .65rem .75rem; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label { display: block; font-size: .9rem; color: var(--discret); }
label > input, label > select, label > textarea { margin-top: .25rem; color: var(--texte); }
textarea { resize: vertical; min-height: 5rem; }

.carte { background: var(--carte); border-radius: 16px; padding: 1rem; box-shadow: var(--ombre); margin-bottom: .9rem; }
.erreur { color: var(--rouge); min-height: 1.2em; margin: .5rem 0; font-size: .9rem; }

/* --- Connexion --- */
.connexion { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.connexion form { width: min(360px, 100%); text-align: center; display: grid; gap: .6rem; padding: 2rem 1.5rem; }
.connexion label { text-align: left; }
.logo { font-size: 3rem; }

/* --- Structure --- */
#appli { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
.vue { max-width: 640px; margin: 0 auto; }
.contenu { padding: 0 1rem 1rem; }
.barre-titre, .barre-date {
  display: flex; align-items: center; gap: .5rem; padding: .75rem 1rem; position: sticky; top: 0; z-index: 5;
  background: var(--fond);
}
.barre-titre h2 { flex: 1; }
.barre-date { justify-content: space-between; }
.barre-date .date { font-weight: 700; font-size: 1.1rem; padding: .5rem .8rem; text-transform: capitalize; }
.cache-date { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; }

.onglets {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; justify-content: center;
  background: var(--carte); border-top: 1px solid var(--bord); padding-bottom: env(safe-area-inset-bottom);
}
.onglets button {
  flex: 1; max-width: 160px; flex-direction: column; gap: 0; padding: .45rem 0 .5rem; font-size: .75rem; color: var(--discret);
  border-radius: 0;
}
.onglets button span { font-size: 1.3rem; filter: grayscale(1); opacity: .7; }
.onglets button.actif { color: var(--accent); font-weight: 600; }
.onglets button.actif span { filter: none; opacity: 1; }

/* --- Bilan du jour --- */
.bilan { display: grid; grid-template-columns: auto 1fr; gap: 1rem 1.2rem; align-items: center; }
.anneau { position: relative; width: 128px; height: 128px; }
.anneau svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.anneau circle { fill: none; stroke-width: 11; }
.anneau .piste { stroke: var(--piste); }
.anneau .jauge { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .4s; }
.anneau.depasse .jauge { stroke: var(--rouge); }
.anneau .milieu { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.anneau .gros { font-size: 1.6rem; font-weight: 700; }
.anneau .sous { font-size: .75rem; color: var(--discret); }
.macros { display: grid; gap: .55rem; }
.jauge-ligne .haut { display: flex; justify-content: space-between; font-size: .85rem; gap: .5rem; }
.jauge-ligne .haut b { font-weight: 600; }
.jauge-ligne.sous-ligne { padding-left: .8rem; }
.jauge-ligne.sous-ligne .haut { font-size: .8rem; color: var(--discret); }
.barre { height: 7px; border-radius: 4px; background: var(--piste); overflow: hidden; margin-top: 3px; }
.barre > i { display: block; height: 100%; border-radius: 4px; background: var(--c, var(--accent)); transition: width .4s; }
.barre.depasse > i { background: var(--rouge); }
.bilan .reste > div { flex: 1; }
.bilan .reste { grid-column: 1 / -1; display: flex; gap: 1rem; justify-content: space-around; text-align: center; border-top: 1px solid var(--bord); padding-top: .8rem; font-size: .85rem; color: var(--discret); }
.bilan .reste b { display: block; font-size: 1.05rem; color: var(--texte); }
.bilan .details { grid-column: 1 / -1; display: grid; gap: .55rem; }
@media (max-width: 400px) {
  .bilan { grid-template-columns: 1fr; }
  .bilan .anneau { justify-self: center; }
}

/* --- Repas --- */
.repas { padding: .4rem 0 .2rem; }
.repas-tete { display: flex; align-items: center; justify-content: space-between; padding: .5rem 1rem; gap: .5rem; }
.repas-tete h3 { flex: 1; }
.repas-tete .kcal { color: var(--discret); font-size: .9rem; }
.entree { display: flex; align-items: center; gap: .75rem; padding: .6rem 1rem; border-top: 1px solid var(--bord); width: 100%; text-align: left; border-radius: 0; }
.entree:hover { background: var(--fond); }
.entree .nom { flex: 1; min-width: 0; }
.entree .nom div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entree .qte { font-size: .82rem; color: var(--discret); }
.entree .val { text-align: right; font-weight: 600; white-space: nowrap; }
.repas-pied { display: flex; gap: .5rem; padding: .5rem 1rem .6rem; border-top: 1px solid var(--bord); flex-wrap: wrap; }
.repas.carte { padding: 0; overflow: hidden; }
.lien { color: var(--accent); background: none; padding: .45rem .3rem; font-size: .9rem; font-weight: 500; }

/* --- Listes d'aliments --- */
.recherche { font-size: 1.05rem; padding: .8rem 1rem; border-radius: 14px; margin-bottom: .6rem; }
.liste { list-style: none; margin: 0; padding: 0; background: var(--carte); border-radius: 16px; box-shadow: var(--ombre); overflow: hidden; }
.liste:empty { display: none; }
.liste li + li { border-top: 1px solid var(--bord); }
.liste button { width: 100%; text-align: left; justify-content: flex-start; padding: .7rem 1rem; border-radius: 0; gap: .75rem; }
.liste button:hover { background: var(--fond); }
.liste .nom { flex: 1; min-width: 0; }
.liste .nom div:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.liste .info { font-size: .8rem; color: var(--discret); }
.liste .val { font-size: .85rem; color: var(--discret); white-space: nowrap; text-align: right; }
.etiquette { font-size: .7rem; padding: .1rem .4rem; border-radius: 6px; background: var(--piste); color: var(--discret); margin-left: .3rem; vertical-align: 1px; }
.etiquette.off { background: #fff1d6; color: #8a5a00; }
.etiquette.ia { background: #ece4ff; color: #5b3cc4; }
@media (prefers-color-scheme: dark) {
  .etiquette.off { background: #3a2d10; color: #f0c56b; }
  .etiquette.ia { background: #2c2347; color: #c4b2ff; }
}
.groupe-titre { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--discret); margin: 1rem .2rem .4rem; font-weight: 600; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-bottom: .6rem; }
.actions button { background: var(--carte); box-shadow: var(--ombre); flex-direction: column; padding: .7rem .3rem; font-size: .82rem; font-weight: 500; gap: .15rem; border: 1px solid var(--bord); }
.actions button span { font-size: 1.3rem; }
.ligne-boutons { display: flex; gap: .5rem; flex-wrap: wrap; margin: .6rem 0; }
.ligne-boutons .secondaire, .ligne-boutons .petit { width: auto; flex: 1 1 auto; }
.chargement { text-align: center; color: var(--discret); padding: 1rem; }

/* --- Panneau plein écran --- */
.panneau { position: fixed; inset: 0; z-index: 20; background: var(--fond); overflow-y: auto; overscroll-behavior: contain; }
.panneau .barre-titre, .panneau .contenu { max-width: 640px; margin: 0 auto; }
.panneau .contenu { padding-bottom: 2rem; }

/* Quantité */
.quantite { display: flex; gap: .5rem; align-items: end; }
.quantite label { flex: 1; }
.quantite input { font-size: 1.4rem; font-weight: 600; text-align: center; }
.quantite .unite { padding-bottom: .8rem; color: var(--discret); }
.puces { display: flex; gap: .4rem; flex-wrap: wrap; margin: .6rem 0; }
.puces button { background: var(--piste); padding: .4rem .75rem; border-radius: 20px; font-size: .88rem; }
.puces button.actif { background: var(--accent); color: var(--sur-accent); font-weight: 600; }
.tableau { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tableau td { padding: .4rem 0; border-top: 1px solid var(--bord); }
.tableau tr:first-child td { border-top: 0; }
.tableau td:last-child { text-align: right; font-weight: 600; }
.tableau td.sous { padding-left: .8rem; color: var(--discret); }
.tableau .apres { color: var(--discret); font-weight: 400; font-size: .82rem; }
.titre-aliment { margin-bottom: .2rem; }

/* Formulaire aliment */
.grille { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.grille .large { grid-column: 1 / -1; }
form.carte { display: grid; gap: .7rem; }
.note { font-size: .85rem; background: var(--accent-doux); color: var(--texte); padding: .6rem .75rem; border-radius: 10px; margin: .4rem 0; }
.note.alerte { background: #fde9e5; }
@media (prefers-color-scheme: dark) { .note.alerte { background: #3a1e19; } }

/* IA : repas décrit */
.ingredient { display: grid; grid-template-columns: auto 1fr 84px; gap: .6rem; align-items: center; padding: .6rem 1rem; border-top: 1px solid var(--bord); }
.ingredient:first-child { border-top: 0; }
.ingredient input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
.ingredient input[type=number] { padding: .4rem; text-align: right; }

/* Scanner */
.camera { position: relative; border-radius: 16px; overflow: hidden; background: #000; aspect-ratio: 3 / 4; max-height: 60vh; margin: 0 auto .8rem; }
.camera video { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera .viseur { position: absolute; left: 10%; right: 10%; top: 38%; height: 24%; border: 3px solid rgba(255, 255, 255, .85); border-radius: 12px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .35); }

/* Historique */
.graphe { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding-top: 1rem; position: relative; }
.graphe .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; min-width: 0; }
.graphe .col i { display: block; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.graphe .col.depasse i { background: var(--orange); }
.graphe .col.vide i { background: var(--piste); }
.graphe .objectif { position: absolute; left: 0; right: 0; border-top: 2px dashed var(--discret); opacity: .6; }
.graphe-dates { display: flex; gap: 3px; font-size: .7rem; color: var(--discret); margin-top: .3rem; }
.graphe-dates span { flex: 1; text-align: center; min-width: 0; overflow: hidden; }
.choix { display: flex; background: var(--piste); border-radius: 10px; padding: 3px; }
.choix button { padding: .35rem .7rem; border-radius: 8px; font-size: .85rem; }
.choix button.actif { background: var(--carte); font-weight: 600; box-shadow: var(--ombre); }

/* Message en bas */
.message {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--texte); color: var(--fond); padding: .7rem 1.1rem; border-radius: 12px; max-width: calc(100% - 2rem);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .2); font-size: .92rem;
}
.message.erreur-msg { background: var(--rouge); color: #fff; }
