/* ============================================================
   Calorie Tracker — thème sombre, mobile-first
   Encodage couleur : chaud = entrée (repas), froid = sortie (activité)
   ============================================================ */

:root {
  --bg:        #14130F;
  --surface:   #1E1C17;
  --surface-2: #272420;
  --line:      #37322A;
  --text:      #F3EFE7;
  --muted:     #9A9384;
  --intake:    #FF8A3D;   /* repas / calories consommées */
  --burn:      #2FD3B8;   /* activité / calories brûlées  */
  --protein:   #C792FF;   /* protéines                    */
  --danger:    #E5604D;
  --radius:    18px;
  --safe-b:    env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  overscroll-behavior-y: none;
}

.num { font-family: "Space Grotesk", monospace; font-variant-numeric: tabular-nums; }

button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
input, select { font: inherit; color: var(--text); }

/* ---------- Layout ---------- */
.app { max-width: 540px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ---------- Barre supérieure ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; position: sticky; top: 0; z-index: 5;
  background: linear-gradient(var(--bg) 70%, transparent);
}
.datenav { display: flex; align-items: center; gap: 4px; }
.datenav button {
  width: 38px; height: 38px; border-radius: 12px; font-size: 20px;
  color: var(--muted); transition: background .15s;
}
.datenav button:active { background: var(--surface-2); }
.datelabel { min-width: 130px; text-align: center; font-weight: 600; letter-spacing: -.01em; }
.datelabel small { display: block; color: var(--muted); font-weight: 400; font-size: .72rem; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  color: var(--muted); transition: background .15s;
}
.icon-btn:active { background: var(--surface-2); }

/* ---------- Résumé / anneau ---------- */
.summary { padding: 8px 16px 20px; }
.ring-wrap { position: relative; width: 230px; height: 230px; margin: 6px auto 4px; }
.ring-wrap svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.ring-track { fill: none; stroke: var(--surface-2); stroke-width: 16; }
.ring-fill  { fill: none; stroke: var(--intake); stroke-width: 16; stroke-linecap: round;
              transition: stroke-dashoffset .5s ease, stroke .3s; }
.ring-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
}
.ring-center .big { font-size: 3.1rem; font-weight: 600; letter-spacing: -.03em; line-height: 1; }
.ring-center .big.over { color: var(--danger); }
.ring-center .unit { color: var(--muted); font-size: .8rem; margin-top: 6px; letter-spacing: .03em; }

/* ---------- Stats sous l'anneau ---------- */
.stats { display: flex; justify-content: center; gap: 10px; margin-top: 14px; }
.stat {
  flex: 1; max-width: 150px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px; text-align: center;
}
.stat .label { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; }
.stat .val { font-size: 1.4rem; font-weight: 600; margin-top: 4px; }
.stat.intake .val { color: var(--intake); }
.stat.burn .val   { color: var(--burn); }

/* ---------- Barre de protéines ---------- */
.protein { margin: 16px auto 0; max-width: 320px; }
.protein .row { display: flex; justify-content: space-between; font-size: .82rem; margin-bottom: 6px; }
.protein .row span:last-child { color: var(--muted); }
.protein .track { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.protein .bar { height: 100%; background: var(--protein); border-radius: 99px; transition: width .5s ease; }

/* Bouton suggestion */
.suggest-btn {
  display: block; margin: 18px auto 0; padding: 11px 20px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  font-weight: 500; font-size: .92rem; transition: background .15s, transform .1s;
}
.suggest-btn:active { background: var(--surface-2); transform: scale(.97); }

/* Repas suggérés */
.sugg {
  background: var(--surface-2); border-radius: 14px; padding: 14px; margin-bottom: 10px;
}
.sugg .head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.sugg .name { font-weight: 600; }
.sugg .macros { color: var(--intake); font-size: .82rem; white-space: nowrap; }
.sugg .macros .p { color: var(--protein); }
.sugg .desc { color: var(--muted); font-size: .85rem; margin: 6px 0 12px; }
.sugg .add {
  width: 100%; padding: 10px; border-radius: 10px; background: var(--intake);
  color: #2a1400; font-weight: 600; font-size: .9rem;
}
.sugg .add:disabled { opacity: .5; }

/* ---------- Liste des entrées ---------- */
.entries { flex: 1; padding: 4px 16px calc(96px + var(--safe-b)); }
.group-title { color: var(--muted); font-size: .78rem; text-transform: uppercase;
               letter-spacing: .06em; margin: 18px 4px 8px; }
.entry {
  display: flex; align-items: center; gap: 12px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px;
}
.entry .dot { width: 8px; height: 8px; border-radius: 99px; flex: none; }
.entry.meal .dot { background: var(--intake); }
.entry.activity .dot { background: var(--burn); }
.entry .body { flex: 1; min-width: 0; }
.entry .name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .meta { color: var(--muted); font-size: .78rem; margin-top: 2px; }
.entry .kcal { font-weight: 600; }
.entry.meal .kcal { color: var(--intake); }
.entry.activity .kcal { color: var(--burn); }
.entry .del { color: var(--muted); padding: 6px; font-size: 18px; }
.entry .del:active { color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; font-size: .9rem; }

/* ---------- Barre d'action ---------- */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; gap: 10px; padding: 12px 16px calc(12px + var(--safe-b));
  max-width: 540px; margin: 0 auto;
  background: linear-gradient(transparent, var(--bg) 30%);
}
.actionbar button {
  flex: 1; padding: 15px; border-radius: 14px; font-weight: 600; font-size: 1rem;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-meal { background: var(--intake); color: #2a1400; }
.btn-act  { background: var(--burn); color: #002a25; }
.actionbar button:active { transform: scale(.97); }

/* ---------- Feuilles modales ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .2s ease;
}
.sheet {
  width: 100%; max-width: 540px; background: var(--surface);
  border-radius: 22px 22px 0 0; border-top: 1px solid var(--line);
  padding: 8px 18px calc(22px + var(--safe-b)); max-height: 92dvh; overflow-y: auto;
  animation: slideup .26s cubic-bezier(.2,.8,.2,1);
}
.sheet .grip { width: 40px; height: 4px; background: var(--line); border-radius: 99px; margin: 8px auto 14px; }
.sheet h2 { font-size: 1.2rem; margin-bottom: 14px; letter-spacing: -.01em; }
@keyframes fade { from { opacity: 0; } }
@keyframes slideup { from { transform: translateY(100%); } }

.field { margin-bottom: 14px; }
.field label { display: block; color: var(--muted); font-size: .8rem; margin-bottom: 6px; }
.field input, .field select {
  width: 100%; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 13px 14px; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--intake); }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.sheet-actions { display: flex; gap: 10px; margin-top: 8px; }
.sheet-actions button { flex: 1; padding: 14px; border-radius: 12px; font-weight: 600; }
.btn-primary { background: var(--intake); color: #2a1400; }
.btn-primary.burn { background: var(--burn); color: #002a25; }
.btn-ghost { background: var(--surface-2); color: var(--text); }

/* Choix Photo / Manuel */
.toggle { display: flex; gap: 8px; margin-bottom: 16px; }
.toggle button {
  flex: 1; padding: 12px; border-radius: 12px; background: var(--surface-2);
  border: 1px solid var(--line); font-weight: 500; color: var(--muted);
}
.toggle button.active { background: var(--intake); color: #2a1400; border-color: transparent; }

/* Photo */
.photo-zone {
  border: 1.5px dashed var(--line); border-radius: 14px; padding: 26px 16px; text-align: center;
  color: var(--muted); margin-bottom: 14px;
}
.photo-zone img { max-width: 100%; border-radius: 12px; max-height: 240px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--surface-2);
           border-top-color: var(--intake); border-radius: 50%; margin: 16px auto;
           animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Résultats analyse */
.food-row {
  display: flex; align-items: center; gap: 8px; background: var(--surface-2);
  border-radius: 12px; padding: 10px; margin-bottom: 8px;
}
.food-row input.fname { flex: 2; min-width: 0; background: transparent; border: none; padding: 4px; }
.food-row input.fnum  { width: 62px; background: var(--surface); border: 1px solid var(--line);
                        border-radius: 8px; padding: 6px; text-align: center; font-size: .9rem; }
.food-row .tag { color: var(--muted); font-size: .7rem; }
.food-row .rm { color: var(--muted); padding: 4px 6px; }

/* Estimation activité */
.estimate { background: var(--surface-2); border-radius: 12px; padding: 14px; text-align: center; margin-bottom: 14px; }
.estimate .val { font-size: 1.8rem; font-weight: 600; color: var(--burn); }
.estimate .lbl { color: var(--muted); font-size: .78rem; }

/* ---------- Connexion ---------- */
.login { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; gap: 16px; }
.login h1 { font-size: 1.6rem; letter-spacing: -.02em; }
.login p { color: var(--muted); text-align: center; }
.login input { width: 100%; max-width: 320px; background: var(--surface); border: 1px solid var(--line);
               border-radius: 12px; padding: 14px; outline: none; text-align: center; }
.login button { background: var(--intake); color: #2a1400; padding: 14px 28px; border-radius: 12px; font-weight: 600; }
.login .err { color: var(--danger); font-size: .85rem; min-height: 1.2em; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: calc(100px + var(--safe-b)); left: 50%; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  padding: 10px 18px; border-radius: 99px; font-size: .88rem; z-index: 50;
  animation: fade .2s; white-space: nowrap;
}
