:root {
  --bg: #0f1411;
  --panel: #161d18;
  --panel-2: #1f2a22;
  --text: #eef3ec;
  --muted: #9fb0a4;
  --line: #2c3a31;
  --green: #6cc28f;
  --teal: #58b3a6;
  --gold: #d9b15f;
  --red: #d77a7a;
  --blue: #6fa8c9;
  --shadow: 0 20px 60px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top left, #1c2a22 0, var(--bg) 40rem);
  min-height: 100vh;
}
button, input, textarea, select { font: inherit; }
button {
  border: 0; border-radius: 12px; padding: .7rem 1rem; cursor: pointer;
  background: var(--green); color: #0c1a11; font-weight: 700;
}
button:hover { filter: brightness(1.06); }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.danger { background: #3a2024; color: #ffb3b3; border: 1px solid #6c3239; }
button.icon { background: transparent; color: var(--muted); font-size: 1.5rem; padding: .2rem .6rem; }
input, textarea, select {
  width: 100%; background: #0c120e; color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: .7rem .8rem; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(108,194,143,.16); }
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: 1.2rem clamp(1rem, 3vw, 2.5rem); border-bottom: 1px solid rgba(255,255,255,.06);
  position: sticky; top: 0; background: rgba(15,20,17,.85); backdrop-filter: blur(18px); z-index: 10;
  flex-wrap: wrap;
}
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.8rem, 5vw, 3rem); letter-spacing: -.05em; }
h2 { letter-spacing: -.03em; }
.eyebrow { color: var(--green); text-transform: uppercase; letter-spacing: .14em; font-size: .72rem; font-weight: 800; margin-bottom: .35rem; }
.muted { color: var(--muted); }
.top-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.top-actions input[type=date] { width: auto; }
main { padding: clamp(1rem, 3vw, 2.5rem); max-width: 1100px; margin: 0 auto; }
.hero { display: grid; grid-template-columns: 1.1fr 1.4fr; gap: 1rem; margin-bottom: 1rem; }
.day-card, .stats, .quick-add, .view { background: rgba(22,29,24,.9); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); }
.day-card { padding: 1.3rem; display: flex; flex-direction: column; justify-content: center; min-height: 140px; }
.day-card h2 { font-size: clamp(1.3rem, 3vw, 2rem); margin-bottom: .4rem; }
.stats { padding: 1rem; display: grid; grid-template-columns: repeat(3,1fr); gap: .6rem; }
.stat { background: #0c120e; border-radius: 16px; padding: .8rem; border: 1px solid rgba(255,255,255,.05); }
.stat .ico { font-size: 1.1rem; }
.stat strong { display: block; font-size: 1.5rem; line-height: 1.1; }
.stat span { color: var(--muted); font-size: .8rem; }

.quick-add { padding: 1rem; margin-bottom: 1rem; }
.cat-pills { display: flex; flex-wrap: wrap; gap: .5rem; margin: .6rem 0 1rem; }
.cat-pill {
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  border-radius: 999px; padding: .5rem .85rem; font-weight: 700; white-space: nowrap;
}
.cat-pill.active { background: var(--panel-2); color: var(--text); border-color: var(--green); }
.quick-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; align-items: end; }
.quick-form .field { display: grid; gap: .35rem; }
.quick-form .field.wide { grid-column: 1 / -1; }
.quick-form label, .field-label { color: var(--muted); font-size: .82rem; }
.quick-form .submit { grid-column: 1 / -1; }
.quick-form .submit button { width: 100%; padding: .85rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  background: #0c120e; color: var(--text); border: 1px solid var(--line);
  border-radius: 999px; padding: .4rem .7rem; font-size: .85rem; font-weight: 600;
}
.chip:hover { border-color: var(--green); }
.rating-row { display: flex; gap: .4rem; flex-wrap: wrap; }
.rating-btn {
  background: #0c120e; color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: .55rem .8rem; font-weight: 700; min-width: 2.6rem;
}
.rating-btn.active { background: var(--green); color: #0c1a11; border-color: var(--green); }

/* Repas (nutrition) : sélecteur de type + aliments multiples. */
.meal-types .meal-type.active { background: var(--green); color: #0c1a11; border-color: var(--green); }
.meal-items { display: grid; gap: .5rem; }
.meal-item {
  display: grid; grid-template-columns: 1fr 4.5rem 4.5rem auto; gap: .4rem; align-items: center;
}
.meal-item input { padding: .55rem .6rem; }
.meal-item .mi-del {
  background: #0c120e; color: var(--muted); border: 1px solid var(--line);
  border-radius: 10px; padding: .45rem .65rem; font-size: 1.1rem; line-height: 1;
}
.meal-item .mi-del:hover { color: #ffb3b3; border-color: #6c3239; }
.add-item {
  margin-top: .5rem; background: transparent; color: var(--green);
  border: 1px dashed var(--line); border-radius: 12px; width: 100%; padding: .6rem;
}
.add-item:hover { border-color: var(--green); }
.meal-builder { display: grid; gap: .4rem; }
.meal-builder[hidden] { display: none; }

.section-title { display: flex; justify-content: space-between; align-items: end; gap: 1rem; margin-bottom: 1rem; }
.view { display: none; padding: 1rem; }
.view.active { display: block; }
.entries { display: grid; gap: 1rem; }
.cat-group h3 { margin: 0 0 .6rem; font-size: 1rem; display: flex; align-items: center; gap: .45rem; }
.cat-group h3 .count { color: var(--muted); font-weight: 600; font-size: .85rem; }
.entry-list { display: grid; gap: .55rem; }
.entry {
  background: linear-gradient(180deg, #1f2a22, #161d18); border: 1px solid var(--line);
  border-radius: 16px; padding: .75rem .9rem; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; gap: .8rem;
}
.entry:hover { border-color: rgba(108,194,143,.7); transform: translateY(-1px); }
.entry-main { display: grid; gap: .2rem; min-width: 0; }
.entry-title { font-weight: 700; }
.entry-sub { color: var(--muted); font-size: .82rem; }
.entry-val { text-align: right; white-space: nowrap; }
.entry-val strong { font-size: 1.05rem; }
.entry-time { color: var(--muted); font-size: .75rem; }

.empty { padding: 1.6rem 1rem; text-align: center; border: 1px dashed var(--line); border-radius: 16px; }
.empty-title { font-weight: 700; margin-bottom: .3rem; }

dialog { border: 1px solid var(--line); border-radius: 24px; background: var(--panel); color: var(--text); width: min(640px, 94vw); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0,0,0,.65); backdrop-filter: blur(4px); }
.modal { display: grid; gap: .9rem; }
.modal header, menu { display: flex; justify-content: space-between; align-items: center; gap: .7rem; padding: 0; margin: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2,1fr); gap: .8rem; }
label { display: grid; gap: .35rem; color: var(--muted); font-size: .9rem; }

.toasts { position: fixed; bottom: 1.2rem; right: 1.2rem; display: grid; gap: .5rem; z-index: 50; max-width: min(360px, 92vw); }
.toast {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-left: 4px solid var(--green); border-radius: 12px; padding: .75rem 1rem;
  box-shadow: var(--shadow); font-size: .9rem; animation: toast-in .22s ease;
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.out { opacity: 0; transform: translateY(8px); transition: all .3s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* Bouton d'ajout bas de page (tous formats) */
.add-entry-row { margin-top: 1rem; }
.add-entry-btn { width: 100%; padding: .85rem; font-size: 1rem; }

/* Bouton flottant + (mobile uniquement via media query) */
.fab {
  position: fixed; bottom: 5rem; right: 1.5rem; z-index: 30;
  width: 3.5rem; height: 3.5rem; border-radius: 50%;
  font-size: 1.8rem; padding: 0;
  display: none; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,0,.5);
}

/* Modale d'ajout */
.add-cat-label { margin: .2rem 0 .5rem; }
#addDialog { width: min(720px, 96vw); max-height: 90vh; overflow-y: auto; }
.add-modal { display: grid; gap: .9rem; }

/* Réglages : toggles de métriques */
.metrics-toggles { display: flex; flex-wrap: wrap; gap: .6rem; }
.metric-toggle {
  background: #0c120e; color: var(--muted); border: 1px solid var(--line);
  border-radius: 12px; padding: .6rem .9rem; font-size: .9rem; font-weight: 600;
}
.metric-toggle.active { background: var(--panel-2); color: var(--text); border-color: var(--green); }
.settings-hint { font-size: .85rem; margin-top: -.3rem; }
.settings-footer { display: flex; justify-content: flex-end; }

/* Graphe tendance 7 jours */
.hero-right { display: flex; flex-direction: column; gap: .75rem; }
.trend-chart {
  background: rgba(22,29,24,.9); border: 1px solid var(--line);
  border-radius: 24px; padding: .9rem 1rem .6rem; box-shadow: var(--shadow);
}
.trend-header {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: .5rem; margin-bottom: .35rem;
}
.trend-title { font-weight: 700; font-size: .9rem; }
.trend-sub { font-size: .72rem; color: var(--muted); }
.trend-svg { width: 100%; height: auto; display: block; }
.trend-bar { fill: var(--blue); opacity: .7; }
.trend-bar.today { fill: var(--green); opacity: 1; }
.trend-val { font-size: 6.5px; fill: var(--muted); font-family: inherit; }
.trend-label { font-size: 8px; fill: var(--muted); font-family: inherit; }
.trend-label.today { fill: var(--green); font-weight: bold; }
.trend-empty-msg { text-align: center; color: var(--muted); font-size: .8rem; padding: .5rem 0 .1rem; }
.stat { cursor: pointer; transition: border-color .15s; }
.stat.active { border-color: var(--blue); background: rgba(111,168,201,.1); }

@media (max-width: 820px) {
  .hero, .grid2 { grid-template-columns: 1fr; }
  .hero-right { gap: .6rem; }
  .stats { grid-template-columns: repeat(3,1fr); }
  /* Header sticky compact sur mobile : sinon il enflait (~200px, titre + 5
     contrôles sur plusieurs lignes) et recouvrait la rangée de catégories
     dès qu'on scrollait — les taps sur les pastilles tombaient alors sur un
     bouton du header au lieu de changer de catégorie. */
  .topbar { align-items: center; padding: .6rem clamp(1rem, 3vw, 2.5rem); gap: .4rem .6rem; }
  .topbar .eyebrow { display: none; }
  .topbar h1 { font-size: 1.5rem; }
  .top-actions { gap: .35rem; }
  .top-actions button.ghost { padding: .5rem .55rem; }
  .toasts { left: 1rem; right: 1rem; bottom: 1rem; max-width: none; }
  .fab { display: flex; }
  main { padding-bottom: 6rem; }
}
