/* Design tokens : le SEUL endroit où l'on change une couleur, un arrondi, une ombre ou la police. */
:root {
  --bg: #F4F7F5;
  --surface: #FFFFFF;
  --ink: #0F1F17;
  --muted: #6B7A72;
  --line: #E4EAE6;
  --vert: #15803D;
  --vert-fond: #DCFCE7;
  --rouge: #B91C1C;
  --rouge-fond: #FEE2E2;
  --accent: #16A34A;
  --accent-ink: #FFFFFF;
  --radius: 22px;
  --radius-sm: 14px;
  --shadow: 0 8px 28px rgba(15, 31, 23, .07);
  --font: -apple-system, "SF Pro Display", "SF Pro Text", system-ui, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font);
  font-size: 16px; line-height: 1.4; padding: 0 16px calc(32px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.entete { max-width: 720px; margin: 0 auto; padding: calc(18px + env(safe-area-inset-top)) 0 10px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.entete h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.onglets { display: flex; background: #E8EEEA; border-radius: 999px; padding: 3px; }
.onglets button { border: 0; background: transparent; border-radius: 999px; padding: 7px 14px; font-size: 14px; font-weight: 600; color: var(--muted); }
.onglets button.actif { background: var(--surface); color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.08); }

main { max-width: 720px; margin: 0 auto; display: grid; gap: 14px; }
.carte { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 18px 8px; }
.carte h2 { margin: 0 0 4px; font-size: 15px; font-weight: 700; color: var(--muted); text-transform: none; }

/* Le résumé : un seul chiffre qui compte, l'écart depuis les achats. */
.resume { padding: 22px 20px 20px; }
.resume .titre { font-size: 14px; color: var(--muted); font-weight: 600; }
.resume .ecart { font-size: 40px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.resume .sous { font-size: 15px; color: var(--muted); }
.resume .sous b { color: var(--ink); font-weight: 700; }
.resume .pastille { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 14px; font-weight: 700; vertical-align: middle; margin-left: 8px; }
.plus { color: var(--vert); } .moins { color: var(--rouge); }
.pastille.plus { background: var(--vert-fond); } .pastille.moins { background: var(--rouge-fond); }

/* Le tableau : nom · mis · vaut · écart. Les chiffres sont alignés et à chasse fixe. */
table { width: 100%; border-collapse: collapse; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-align: right; padding: 8px 0 6px 10px; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; padding-left: 0; }
td { padding: 10px 0 10px 10px; border-bottom: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; vertical-align: top; white-space: nowrap; }
td:first-child { white-space: normal; padding-right: 10px; }
tr:last-child td { border-bottom: 0; }
td .nom { font-weight: 600; display: block; }
td .detail { font-size: 12px; color: var(--muted); display: block; }
td .pct { display: block; font-size: 12px; font-weight: 600; }
tr.total td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; }
tr.sans td { color: var(--muted); }
.poche-entete { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.poche-entete .ecart { font-weight: 700; font-size: 15px; }

.note { font-size: 13px; color: var(--muted); margin: 2px 2px 0; }
.note.alerte { color: var(--rouge); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 4px; }

/* Boutons */
.btn { border: 0; border-radius: 999px; padding: 11px 18px; font-weight: 700; font-size: 15px; background: var(--accent); color: var(--accent-ink); }
.btn.second { background: #E8EEEA; color: var(--ink); }
.btn.discret { background: transparent; color: var(--muted); padding: 8px 10px; font-weight: 600; }
.btn:disabled { opacity: .5; cursor: default; }

/* Mettre à jour : une carte par position, 2 champs qui comptent. */
.position { display: grid; gap: 10px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.position:last-of-type { border-bottom: 0; }
.position .ligne1 { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.position .ligne1 .nom { font-weight: 700; }
.position .ligne1 .poche { font-size: 12px; color: var(--muted); }
.champs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
.champ label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.champ input, .champ select { width: 100%; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; background: #FAFCFB; font-variant-numeric: tabular-nums; }
.champ input:focus, .champ select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.champ input.calc { background: #F1F5F2; color: var(--muted); }
details.plus-infos summary { font-size: 13px; color: var(--muted); cursor: pointer; font-weight: 600; }
details.plus-infos .champs { margin-top: 8px; }
.ajout { border-top: 1px dashed var(--line); margin-top: 6px; padding-top: 14px; }
.barre-enregistrer { position: sticky; bottom: calc(12px + env(safe-area-inset-bottom)); display: flex; gap: 10px; justify-content: flex-end; align-items: center; background: var(--surface); border-radius: 999px; padding: 8px 8px 8px 16px; box-shadow: 0 10px 28px rgba(15,31,23,.16); }
.barre-enregistrer .etat { font-size: 13px; color: var(--muted); margin-right: auto; }

/* Code d'accès */
.code { max-width: 360px; margin: 10vh auto 0; text-align: center; }
.code input { width: 100%; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 18px; text-align: center; margin: 12px 0; letter-spacing: .08em; }
.code .erreur { color: var(--rouge); font-size: 14px; min-height: 1.4em; }

.vide { text-align: center; color: var(--muted); padding: 40px 0; }
@media (max-width: 420px) {
  .resume .ecart { font-size: 34px; } body { font-size: 15px; } .entete h1 { font-size: 20px; }
  td, th { font-size: 14px; padding-left: 7px; } td .detail { font-size: 11px; } .carte { padding: 16px 14px 6px; }
}
