@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,700&family=Nunito+Sans:wght@400;600;700&display=swap');

/* ---------- Jetons ---------- */
:root {
  --white: #ffffff;
  --leaf: #eef4ea;        /* surface secondaire : vert très pâle */
  --line: #d9e2d3;
  --ink: #16211b;
  --ink-2: #4e5d54;       /* texte secondaire */
  --awning: #1f6f4f;      /* vert auvent : la seule couleur forte */
  --awning-deep: #164f39;
  --saffron: #d99a1e;     /* dépassement */
  --tomato: #bf3a2b;      /* manque / danger */
  --tomato-soft: #fbe9e6;
  --saffron-soft: #fbf1d8;
  --serif: Fraunces, Georgia, serif;
  --sans: "Nunito Sans", system-ui, -apple-system, sans-serif;
  --r: 10px;
  --nav-h: 3.5rem;
}
* { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--white); color: var(--ink);
  font-family: var(--sans); line-height: 1.5;
}
a { color: var(--awning); }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; line-height: 1.1; margin: 0 0 .5rem; letter-spacing: -.005em; }
h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); }
h2 { font-size: 1.35rem; margin-top: 1.75rem; }
h3 { font-size: 1.05rem; }
p { margin: .4rem 0 .9rem; }
.muted { color: var(--ink-2); }
small { color: var(--ink-2); }

/* ---------- En-tête / navigation ---------- */
header.top {
  border-bottom: 3px solid var(--awning);
  background: var(--white);
  padding: .8rem 1rem;
  display: flex; align-items: center; gap: 1.5rem;
}
header.top .brand {
  font-family: var(--serif); font-weight: 700; font-size: 1.35rem; color: var(--ink);
  text-decoration: none; display: inline-flex; align-items: center; gap: .5rem;
}
header.top .brand svg { width: 26px; height: 26px; }
header.top nav { display: flex; gap: .25rem; margin-left: auto; }
header.top nav a {
  color: var(--ink-2); text-decoration: none; font-weight: 600; padding: .35rem .7rem; border-radius: 999px;
}
header.top nav a[aria-current="page"] { background: var(--leaf); color: var(--awning-deep); }
header.top nav a:hover { color: var(--awning-deep); }

main { max-width: 1180px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }

.flash {
  background: var(--leaf); border-left: 4px solid var(--awning);
  padding: .55rem .8rem; margin-bottom: .6rem; border-radius: 6px; font-size: .95rem;
}

/* ---------- Formulaires ---------- */
form label { display: block; font-weight: 700; margin: 1rem 0 .3rem; }
input[type=text], input[type=number], select, textarea {
  width: 100%; padding: .6rem .7rem; border: 1.5px solid var(--line); border-radius: 8px;
  font: inherit; background: var(--white); color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--awning); box-shadow: 0 0 0 3px rgba(31,111,79,.18); }
textarea { min-height: 8rem; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .35rem .9rem; }
.checks label {
  font-weight: 400; margin: 0; display: flex; gap: .5rem; align-items: center;
  padding: .35rem .5rem; border-radius: 8px; border: 1.5px solid transparent;
}
.checks label:has(input:checked) { background: var(--leaf); border-color: var(--line); }
.checks input { accent-color: var(--awning); width: 1.1rem; height: 1.1rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

button, .btn {
  font: inherit; font-weight: 700; padding: .6rem 1.1rem; border-radius: 999px;
  border: 1.5px solid var(--awning); background: var(--awning); color: #fff;
  cursor: pointer; text-decoration: none; display: inline-block; line-height: 1.2;
}
button:hover, .btn:hover { background: var(--awning-deep); border-color: var(--awning-deep); }
button.ghost, .btn.ghost { background: transparent; color: var(--awning-deep); }
button.ghost:hover, .btn.ghost:hover { background: var(--leaf); }
button.small, .btn.small { padding: .3rem .7rem; font-size: .85rem; }
button.danger { background: transparent; color: var(--tomato); border-color: var(--tomato); }
button.danger:hover { background: var(--tomato-soft); }
button:disabled { opacity: .55; cursor: wait; }
:focus-visible { outline: 3px solid var(--saffron); outline-offset: 2px; }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1.5px solid var(--line); border-radius: var(--r); }
table { width: 100%; border-collapse: collapse; background: var(--white); }
th, td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th { font-weight: 700; color: var(--ink-2); font-size: .85rem; background: var(--leaf); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.tag { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; background: var(--leaf); color: var(--awning-deep); margin-right: .25rem; }
.tag.warn { background: var(--tomato-soft); color: var(--tomato); }
.tag.draft { background: var(--saffron-soft); color: #7a5300; }

/* ---------- Plan : en-tête de semaine ---------- */
.week-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .5rem 1.5rem; margin-bottom: 1rem; }
.week-head h1 { margin: 0; }
.week-head .targets { font-variant-numeric: tabular-nums; color: var(--ink-2); }
.week-head .targets b { color: var(--ink); font-weight: 700; }
.week-actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: 1.25rem; }

/* ruban des jours : visible sur mobile uniquement */
.day-tabs { display: none; }
.focus-title { display: block; }

/* ---------- Plan : vue d'ensemble (Mac) ---------- */
.overview { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .5rem; margin-bottom: 1.5rem; }
.overview .col { border: 1.5px solid var(--line); border-radius: var(--r); overflow: hidden; min-width: 0; background: var(--white); }
.overview .col[aria-current="true"] { border-color: var(--awning); box-shadow: 0 0 0 2px rgba(31,111,79,.18); }
.col-head {
  width: 100%; border: 0; border-radius: 0; background: var(--leaf); color: var(--awning-deep);
  padding: .45rem .6rem; text-align: left; font-family: var(--serif); font-size: .95rem;
  display: flex; justify-content: space-between; align-items: baseline;
}
.col-head small { font-family: var(--sans); font-weight: 600; font-size: .7rem; color: var(--ink-2); }
.col.today .col-head, .col[aria-current="true"] .col-head { background: var(--awning); color: #fff; }
.col.today .col-head small, .col[aria-current="true"] .col-head small { color: rgba(255,255,255,.8); }
.col-head:hover { background: var(--awning-deep); color: #fff; }
.cell { padding: .45rem .6rem; border-top: 1px dashed var(--line); }
.cell-slot { font-size: .68rem; font-weight: 700; color: var(--ink-2); }
.cell-name { font-family: var(--serif); font-size: .92rem; line-height: 1.2; margin: .1rem 0; overflow-wrap: anywhere; }
.cell.gap .cell-name { color: var(--tomato); }
.cell-portions { font-size: .7rem; color: var(--ink-2); font-variant-numeric: tabular-nums; display: flex; gap: .5rem; flex-wrap: wrap; }

.focus-title { margin-top: 0; }

/* ---------- Plan : le jour sélectionné (détail) ---------- */
.week { display: block; }
.day { border: 1.5px solid var(--line); border-radius: var(--r); background: var(--white); min-width: 0; overflow: hidden; display: none; }
.day.active { display: block; }
.day > h3 {
  margin: 0; padding: .5rem .8rem; background: var(--awning); color: #fff;
  font-size: 1rem; display: flex; justify-content: space-between; align-items: baseline;
}
.day > h3 small { color: rgba(255,255,255,.75); font-family: var(--sans); font-weight: 600; font-size: .75rem; }
.day.today > h3 { background: var(--awning-deep); }
.day-body { padding: .6rem .8rem .8rem; display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: .6rem; }

.meal { padding: .6rem .7rem; border: 1.5px solid var(--line); border-radius: 8px; font-size: .9rem; }
.meal .slot { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; color: var(--ink-2); font-size: .78rem; font-weight: 600; }
.meal .slot .target { font-weight: 400; }
.meal .name { font-family: var(--serif); font-weight: 500; font-size: 1.08rem; line-height: 1.25; margin: .2rem 0 .3rem; }
.meal .name a { color: var(--ink); text-decoration: none; }
.meal .name a:hover { color: var(--awning-deep); text-decoration: underline; }
.meal .macros { color: var(--ink-2); font-size: .8rem; font-variant-numeric: tabular-nums; }
.meal.gap { border-style: dashed; }
.meal.gap .name { color: var(--tomato); font-family: var(--sans); font-size: .9rem; }
.meal form { display: inline; }
.meal details { margin-top: .35rem; }
.meal summary { cursor: pointer; color: var(--ink-2); font-size: .78rem; list-style: none; }
.meal summary::before { content: "✎ "; }
.meal details form { display: grid; gap: .3rem; margin-top: .3rem; }
.meal details select, .meal details input { padding: .35rem .5rem; font-size: .85rem; }

/* jauges : la lecture d'un coup d'œil du jour */
.bars { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: .2rem 1.5rem; padding-top: .5rem; border-top: 1.5px solid var(--line); }
.bars-who { grid-column: 1 / -1; }
.bar { display: grid; grid-template-columns: 2rem 1fr 3rem; align-items: center; gap: .35rem; font-size: .74rem; margin: .15rem 0; }
.bar .k { font-weight: 700; color: var(--ink-2); }
.bar .track { height: .55rem; background: var(--leaf); border-radius: 999px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--awning); border-radius: 999px; }
.bar .fill.over { background: var(--saffron); }
.bar .fill.under { background: var(--tomato); }
.bar .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
@media (prefers-reduced-motion: no-preference) { .bar .fill { transition: width .35s ease; } }

/* ---------- Sélecteur d'aliments ---------- */
.picker { position: relative; }
.picker ul {
  position: absolute; z-index: 5; left: 0; right: 0; list-style: none; margin: .2rem 0 0; padding: .25rem;
  background: var(--white); border: 1.5px solid var(--line); border-radius: 8px; max-height: 15rem; overflow: auto;
  box-shadow: 0 8px 24px rgba(22,33,27,.12);
}
.picker li { padding: .5rem .6rem; cursor: pointer; font-size: .92rem; border-radius: 6px; }
.picker li:hover { background: var(--leaf); }
.picker li small { display: block; color: var(--ink-2); }

/* ---------- Écrans vides ---------- */
.empty { border: 1.5px dashed var(--line); border-radius: var(--r); padding: 1.5rem; text-align: center; color: var(--ink-2); }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  main { padding-bottom: calc(var(--nav-h) + 1.5rem); }
  header.top nav { display: none; }
  .bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; height: var(--nav-h); z-index: 10;
    display: grid; grid-template-columns: repeat(3, 1fr);
    background: var(--white); border-top: 1.5px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .1rem; text-decoration: none; color: var(--ink-2); font-size: .72rem; font-weight: 700; }
  .bottom-nav a svg { width: 22px; height: 22px; }
  .bottom-nav a[aria-current="page"] { color: var(--awning-deep); }
  .row { grid-template-columns: 1fr; }

  .day-tabs { display: flex; gap: .35rem; overflow-x: auto; padding: .2rem 0 .6rem; scrollbar-width: none; }
  .day-tabs::-webkit-scrollbar { display: none; }
  .day-tabs button { flex: 0 0 auto; padding: .4rem .8rem; background: var(--white); color: var(--ink); border-color: var(--line); font-weight: 700; }
  .day-tabs button[aria-selected="true"] { background: var(--awning); color: #fff; border-color: var(--awning); }
  .overview { display: none; }
  .focus-title { display: none; }
  .day-body { grid-template-columns: 1fr; }
  .bars { grid-template-columns: 1fr; }
}
@media (min-width: 901px) { .bottom-nav { display: none; } }

/* ---------- Personnes ---------- */
details.person { border: 1.5px solid var(--line); border-radius: var(--r); padding: .6rem .9rem; margin: .6rem 0; }
details.person summary { cursor: pointer; font-size: 1.05rem; }
details.person.add { border-style: dashed; }
label.inline { display: flex; align-items: center; gap: .5rem; font-weight: 400; margin-top: .8rem; }
label.inline input { accent-color: var(--awning); width: 1.1rem; height: 1.1rem; }
.portions { margin: .2rem 0; }
.portion { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; font-size: .8rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.portion .who { display: inline-grid; place-items: center; width: 1.3rem; height: 1.3rem; border-radius: 50%; background: var(--leaf); color: var(--awning-deep); font-weight: 700; font-size: .7rem; }
.bars-who { font-weight: 700; font-size: .75rem; color: var(--ink-2); margin-top: .35rem; grid-column: 1 / -1; }
