/* ============================================================
   MACROS — design system (sombre, lisible, mobile-first)
   ============================================================ */
:root {
  --bg: #0b0b0d;
  --surface: #141417;
  --surface-2: #1c1c21;
  --surface-3: #26262d;
  --border: rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.16);

  --text: #f5f5f7;
  --muted: #a8a8b2;
  --faint: #8a8a93;

  --kcal: #34d399;
  --prot: #f87171;
  --carb: #fbbf24;
  --fat: #60a5fa;
  --fiber: #c084fc;
  --danger: #fb7185;
  --ok: #34d399;
  --warn: #fbbf24;

  --radius: 16px;
  --radius-sm: 12px;
  --radius-lg: 22px;
  --pad: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 16px; line-height: 1.45; -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none; min-height: 100vh;
}
button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
input { -webkit-appearance: none; appearance: none; }
input:focus { outline: none; }
h1, h2, h3 { font-weight: 600; margin: 0; }
.tap, .btn, .navbtn, .food, .jbody { transition: transform .12s ease, background .15s ease, opacity .15s; }
.btn:active, .food:active, .navbtn:active { transform: scale(0.98); }

#app {
  max-width: 560px; margin: 0 auto;
  padding: calc(var(--safe-top) + 8px) var(--pad) calc(var(--safe-bottom) + 96px);
  min-height: 100vh;
}

/* ---- Barre de date ---- */
.daybar { display: flex; align-items: center; gap: 8px; min-height: 52px; margin-bottom: 14px; }
.daybar.simple { justify-content: space-between; }
.navarrow {
  width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2);
  font-size: 22px; color: var(--text); display: grid; place-items: center; flex: 0 0 auto;
}
.daytitle { flex: 1; text-align: center; display: flex; flex-direction: column; line-height: 1.15; }
.daybar.simple .daytitle { text-align: left; }
.daytitle strong { font-size: 19px; }
.daytitle span { font-size: 12.5px; color: var(--muted); text-transform: capitalize; }

.banner {
  background: rgba(251,191,36,0.12); border: 1px solid rgba(251,191,36,0.25);
  color: #fde68a; border-radius: var(--radius-sm); padding: 9px 12px; font-size: 13.5px; margin-bottom: 12px;
}

/* ---- Anneaux ---- */
.rings-hero { display: grid; place-items: center; margin: 6px 0 2px; }
.ring text { font-family: var(--font); }
.rings-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; justify-items: center; margin-top: 2px; }
.hero-sub { text-align: center; color: var(--muted); font-size: 12.5px; margin: 8px 0 18px; }
.hero-sub span { font-weight: 600; }

/* ---- Journal ---- */
.journal-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.journal-head h2 { font-size: 16px; }
.journal-head span { font-size: 12.5px; color: var(--faint); }
/* Ligne = [ POIGNÉE fixe | ZONE qui swipe (Supprimer derrière + corps) ] */
.jrow { display: flex; align-items: stretch; margin-bottom: 8px; }
.jhandle {
  flex: 0 0 38px; display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); border: 1px solid var(--border); border-right: none;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm); color: var(--muted); font-size: 20px;
  touch-action: none; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; cursor: grab;
}
.jslide { position: relative; flex: 1; min-width: 0; overflow: hidden; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.jdelete { position: absolute; inset: 0; background: var(--danger); display: flex; align-items: center; justify-content: flex-end; padding-right: 22px; color: #3a0f17; font-weight: 650; font-size: 14px; }
.jbody {
  position: relative; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--border); border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0; padding: 10px 12px; display: flex; align-items: center; gap: 10px;
  touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; will-change: transform;
}
.jrow.dragging { z-index: 5; box-shadow: 0 10px 26px rgba(0,0,0,0.45); border-radius: var(--radius-sm); opacity: 0.97; }
.jrow.dragging .jbody, .jrow.dragging .jhandle { background: var(--surface-3); border-color: var(--border-strong); }
.jfav { color: #fbbf24; margin-right: 5px; }
.jtxt { flex: 1; min-width: 0; }
.thumb { width: 40px; height: 40px; border-radius: 10px; background: var(--surface-3); display: grid; place-items: center; font-size: 21px; line-height: 1; flex: 0 0 auto; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.jmain { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.jname { font-weight: 550; font-size: 15px; }
.jkcal { color: var(--kcal); font-weight: 600; font-size: 14px; flex: 0 0 auto; }
.jsub { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 5px; font-size: 12px; color: var(--muted); }
.jsub .dot::before { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--c); margin-right: 4px; vertical-align: middle; }

.empty { text-align: center; color: var(--faint); padding: 32px 16px; font-size: 15px; }
.empty span { font-size: 13px; color: var(--faint); }

.fab {
  position: sticky; bottom: calc(var(--safe-bottom) + 76px); width: 100%;
  background: var(--kcal); color: #04130d; font-weight: 650; font-size: 16px;
  padding: 15px; border-radius: 14px; margin-top: 14px; box-shadow: 0 6px 20px rgba(52,211,153,0.25);
}

/* ---- Barre de navigation ---- */
#nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: flex; justify-content: space-around; gap: 2px;
  background: rgba(15,15,18,0.92); backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 8px 6px calc(var(--safe-bottom) + 8px);
}
.navbtn { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--faint); font-size: 10.5px; padding: 4px; }
.navbtn .navic { font-size: 19px; line-height: 1; }
.navbtn.on { color: var(--kcal); }

/* ---- Recherche & ajout ---- */
.search { margin-bottom: 12px; }
.search input, .gwrap input, .form input, .set input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 13px 14px; font-size: 16px; color: var(--text);
}
.search input:focus, .gwrap input:focus { border-color: var(--border-strong); }
.addtools { display: grid; grid-template-columns: repeat(4,1fr); gap: 8px; margin-bottom: 14px; }
.tool { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 11px 4px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11.5px; color: var(--muted); }
.tool span { font-size: 19px; }

.foodlist { display: flex; flex-direction: column; gap: 7px; }
.search-sep { font-size: 11.5px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.05em; margin: 16px 4px 8px; }
.food { text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; display: flex; align-items: center; gap: 11px; }
.food-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.food-main { display: flex; align-items: baseline; gap: 8px; }
.food-main span { font-weight: 550; font-size: 15px; }
.food-main em { color: var(--faint); font-style: normal; font-size: 12px; }
.food-macros { font-size: 12px; color: var(--muted); }
.food-macros .per { color: var(--faint); }

/* ---- Modale ---- */
.modal-back { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,0.55); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 560px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px 20px 0 0; padding: 20px 18px calc(var(--safe-bottom) + 20px);
  max-height: 92vh; overflow-y: auto; animation: up .2s ease;
}
@keyframes up { from { transform: translateY(30px); } }
.modal h3 { font-size: 18px; margin-bottom: 14px; }
.modal h3 .brand { color: var(--faint); font-weight: 400; font-size: 13px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.btn { flex: 1; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 13px; font-weight: 550; font-size: 15px; color: var(--text); }
.btn.primary { background: var(--kcal); color: #04130d; border-color: transparent; }
.btn.danger { background: rgba(251,113,133,0.14); color: var(--danger); border-color: rgba(251,113,133,0.3); }
.btn.wide { width: 100%; margin-top: 14px; }

/* Éditeur produit (tap dans le récap) */
.ed-top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.ed-titletxt { font-size: 19px; font-weight: 650; }
.ed-fav { width: 38px; height: 38px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--border); color: var(--faint); font-size: 19px; line-height: 1; flex: 0 0 auto; }
.ed-fav.on { color: #fbbf24; border-color: rgba(251,191,36,0.5); background: rgba(251,191,36,0.12); }
.ed-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.ed-photo { width: 64px; height: 64px; flex: 0 0 auto; border-radius: 14px; overflow: hidden; background: var(--surface-3); border: 1px dashed var(--border-strong); color: var(--muted); font-size: 12px; line-height: 1.15; display: grid; place-items: center; padding: 0; }
.ed-photo img { width: 100%; height: 100%; object-fit: cover; }
.ed-photoadd { text-align: center; font-size: 13px; }
.ed-name { flex: 1; min-width: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px; font-size: 16px; color: var(--text); font-weight: 550; }
.ed-toggle { width: 100%; margin-top: 12px; background: none; border: none; color: var(--kcal); font-size: 14px; font-weight: 550; text-align: left; padding: 4px 2px; }
.ed-values { margin-top: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 6px 13px; }
.ed-vrow { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.ed-vrow:last-of-type { border-bottom: none; }
.ed-vrow label { flex: 1; font-size: 14px; color: var(--muted); }
.ed-vrow input { width: 84px; text-align: right; background: var(--surface-3); border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px; font-size: 15px; color: var(--text); }
.ed-vrow span { width: 30px; color: var(--faint); font-size: 13px; }

/* segments cuit/cru, choix de jours */
.seg { display: flex; gap: 8px; margin-bottom: 14px; }
.seg button { flex: 1; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; padding: 11px; font-weight: 550; color: var(--muted); }
.seg button.on { background: var(--surface-3); color: var(--text); border-color: var(--border-strong); }
.seg.big button { flex-direction: column; gap: 3px; padding: 14px 8px; color: var(--text); }
.seg.big button span { font-size: 11.5px; color: var(--muted); font-weight: 400; }

/* éditeur de grammes */
.grams { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.step { width: 56px; height: 48px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); font-weight: 600; color: var(--text); }
.gwrap { flex: 1; display: flex; align-items: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 12px; padding: 0 14px; }
.gwrap input { background: none; border: none; padding: 13px 0; text-align: center; font-size: 22px; font-weight: 650; }
.gwrap span { color: var(--muted); }
.quick-g { display: grid; grid-template-columns: repeat(6,1fr); gap: 6px; margin-bottom: 6px; }
.quick-g button { background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 8px 0; font-size: 13px; color: var(--muted); }

/* aperçu temps réel */
.live { background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 13px; margin-top: 12px; }
.live-head { font-size: 13.5px; color: var(--text); margin-bottom: 10px; font-weight: 550; }
.lv { display: grid; grid-template-columns: 70px 1fr auto; align-items: center; gap: 9px; margin-bottom: 7px; }
.lvk { font-size: 12.5px; color: var(--muted); }
.lvk::before { content:''; display:inline-block; width:8px;height:8px;border-radius:50%;background:var(--c);margin-right:5px; }
.lvbar { height: 7px; background: rgba(255,255,255,0.08); border-radius: 5px; overflow: hidden; }
.lvbar i { display: block; height: 100%; border-radius: 5px; transition: width .2s ease; }
.lvv { display: flex; flex-direction: column; align-items: flex-end; text-align: right; min-width: 96px; line-height: 1.25; }
.lvv b { font-size: 13.5px; font-weight: 600; color: var(--text); }
.lvv small { font-size: 10.5px; color: var(--muted); }
.lvv.over b { color: var(--danger); }

/* scanner */
.scanwrap { position: relative; width: 100%; aspect-ratio: 4/3; background: #000; border-radius: 14px; overflow: hidden; margin-bottom: 12px; }
.scanwrap video { width: 100%; height: 100%; object-fit: cover; }
.scanline { position: absolute; left: 8%; right: 8%; top: 50%; height: 2px; background: var(--kcal); box-shadow: 0 0 12px var(--kcal); }
.scanfail { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: 13px; padding: 20px; text-align: center; }
/* Caméra photo avec cadre de visée */
.camwrap { position: relative; width: 100%; aspect-ratio: 1/1; background: #000; border-radius: 14px; overflow: hidden; margin-bottom: 12px; }
.camwrap video { width: 100%; height: 100%; object-fit: cover; }
.camframe { position: absolute; inset: 8%; border: 2px solid rgba(255,255,255,0.9); border-radius: 16px; box-shadow: 0 0 0 100vmax rgba(0,0,0,0.28); pointer-events: none; }
.camhint { position: absolute; left: 0; right: 0; bottom: 10px; text-align: center; color: #fff; font-size: 13px; font-weight: 550; text-shadow: 0 1px 4px rgba(0,0,0,0.8); pointer-events: none; }
.or { text-align: center; color: var(--faint); font-size: 12px; margin: 4px 0 10px; }

/* photo review */
.plist { display: flex; flex-direction: column; gap: 8px; }
.prow { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border-radius: 11px; padding: 10px 12px; font-size: 14px; }
.prow input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--kcal); }
.prow span { flex: 1; }
.prow .pg { width: 64px; background: var(--surface-3); border: 1px solid var(--border); border-radius: 8px; padding: 7px; text-align: center; }
.prow em { color: var(--kcal); font-style: normal; font-size: 12.5px; }

/* form créer */
.label-scan { width: 100%; margin-bottom: 8px; }
.form label, .set { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* réglages */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 16px; margin-bottom: 6px; }
.hint { font-size: 12.5px; color: var(--faint); margin: 0 0 12px; line-height: 1.5; }
.set { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; color: var(--text); font-size: 15px; }
.set input { width: 110px; text-align: center; padding: 10px; font-weight: 600; }
.set.lock .lockic { margin-left: auto; margin-right: 8px; font-size: 12px; }
.kbar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; margin: 14px 0 8px; background: rgba(255,255,255,0.06); }
.kbar i { display: block; height: 100%; }
.kbar-legend { font-size: 12.5px; color: var(--muted); text-align: center; }
.kbar-legend .ok { color: var(--ok); }
.kbar-legend .warn { color: var(--warn); }
.row-btns { display: flex; gap: 8px; }
.mini-foods { display: flex; flex-direction: column; gap: 5px; max-height: 320px; overflow-y: auto; }
.mini { display: flex; align-items: center; justify-content: space-between; background: var(--surface-2); border-radius: 9px; padding: 9px 12px; font-size: 14px; }
.mini button { color: var(--danger); font-size: 15px; width: 28px; }

/* semaine */
.weeknote { font-size: 12.5px; color: var(--muted); margin-bottom: 12px; line-height: 1.5; }
.week { display: flex; flex-direction: column; gap: 8px; }
.wrow { display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 11px; padding: 10px 12px; }
.wrow.wtoday { border-color: var(--kcal); }
.wd { display: flex; flex-direction: column; line-height: 1.1; }
.wd b { font-size: 14px; } .wd span { font-size: 11px; color: var(--faint); }
.wbar { height: 9px; background: rgba(255,255,255,0.07); border-radius: 5px; overflow: hidden; }
.wbar i { display: block; height: 100%; border-radius: 5px; }
.wv { font-size: 13px; font-weight: 600; text-align: right; } .wv span { display: block; font-size: 10.5px; color: var(--faint); font-weight: 400; }
.legend { display: flex; gap: 16px; justify-content: center; margin-top: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }

/* toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(var(--safe-bottom) + 86px); z-index: 80; max-width: 92%;
  background: var(--surface-3); border: 1px solid var(--border-strong); color: var(--text);
  border-radius: 12px; padding: 12px 16px; font-size: 13.5px; display: flex; align-items: center; gap: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.toast-act { color: var(--kcal); font-weight: 650; }

/* connexion */
.login-back { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 24px; }
.login { width: 100%; max-width: 340px; text-align: center; }
.login-logo { font-size: 46px; color: var(--kcal); line-height: 1; margin-bottom: 8px; }
.login h1 { font-size: 28px; margin-bottom: 6px; }
.login p { color: var(--muted); font-size: 14px; margin: 0 0 20px; }
.login input { width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 14px; font-size: 16px; color: var(--text); margin-bottom: 10px; }
.login input:focus { border-color: var(--border-strong); }
.login .btn { margin-top: 6px; }
.login-msg { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }
