/* FeelYourFood — couleurs du logo Feel Your Food (#52722c, #819a29, #c7d658). */
:root {
  --green-dark: #52722c;
  --green: #819a29;
  --green-light: #c7d658;
  --green-pale: #f3f6e6;
  --ink: #26301c;
  --muted: #6b7461;
  --line: #e3e7d8;
  --bg: #fafbf6;
  --card: #ffffff;
  --danger: #b4462f;
  --radius: 12px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
[hidden] { display: none !important; }
h1 { font-size: 1.7rem; margin: 0 0 .4rem; color: var(--green-dark); }
h2 { font-size: 1.1rem; margin: 0 0 .8rem; color: var(--green-dark); }
h3 { font-size: 1rem; margin: 0 0 .4rem; }
.lead { color: var(--muted); margin: 0 0 1.5rem; }
.hint { color: var(--muted); font-weight: 400; font-size: .85em; }
code { background: var(--green-pale); padding: .1rem .35rem; border-radius: 6px; word-break: break-all; }

/* Boutons et champs */
.btn { border: 1px solid transparent; border-radius: 999px; padding: .6rem 1.2rem; font: inherit; font-weight: 600;
  cursor: pointer; background: var(--green-pale); color: var(--green-dark); }
.btn.primary { background: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.ghost:hover { border-color: var(--green); }
.btn.danger { background: #fbeae6; color: var(--danger); }
.btn.small { padding: .35rem .8rem; font-size: .85rem; }
.btn:disabled { opacity: .6; cursor: wait; }
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .92rem; }
input { font: inherit; padding: .65rem .8rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
input:focus { outline: 2px solid var(--green-light); border-color: var(--green); }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }
.stack { display: flex; flex-direction: column; gap: .9rem; max-width: 420px; }
.inline { display: flex; flex-wrap: wrap; gap: .8rem; align-items: flex-end; }

/* Connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: linear-gradient(160deg, var(--green-pale), #fff 60%); }
.login-card { width: min(380px, 100%); background: var(--card); border-radius: 18px; padding: 2rem 1.8rem;
  box-shadow: 0 10px 40px rgba(82, 114, 44, .12); display: flex; flex-direction: column; gap: 1rem; }
.login-logo { width: 130px; align-self: center; margin-bottom: .5rem; }

/* Application */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar { background: #fff; border-right: 1px solid var(--line); padding: 1.4rem 1rem; display: flex;
  flex-direction: column; gap: 1rem; position: sticky; top: 0; height: 100vh; }
.side-logo { width: 90px; align-self: center; }
nav { display: flex; flex-direction: column; gap: .2rem; }
nav a { padding: .6rem .9rem; border-radius: 10px; color: var(--ink); text-decoration: none; font-weight: 500; }
nav a:hover { background: var(--green-pale); }
nav a.active { background: var(--green); color: #fff; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: .5rem; font-size: .9rem; color: var(--muted); }
.menu-toggle { display: none; }
.content { padding: 2rem clamp(16px, 4vw, 3rem); max-width: 1100px; width: 100%; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }
.card, .panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; }
.card p { color: var(--muted); font-size: .92rem; }
.panel { margin-bottom: 1.2rem; }
.badge { display: inline-block; padding: .2rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: var(--line); color: var(--muted); }
.badge.ok { background: var(--green-pale); color: var(--green-dark); }
.badge.warn { background: #fdf0dc; color: #9a5b00; }

.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.checks li { display: grid; grid-template-columns: 1.6rem 1fr; gap: .1rem .4rem; }
.checks .state { font-weight: 700; color: var(--green); }
.checks .state.bad { color: #c27a00; }
.checks small { grid-column: 2; color: var(--muted); }

.table { width: 100%; border-collapse: collapse; font-size: .9rem; margin-bottom: .8rem; }
.table th { text-align: left; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); padding: .4rem; }
.table td { border-bottom: 1px solid var(--line); padding: .5rem .4rem; vertical-align: top; }
.table tr.alert td { color: var(--danger); }

.totp-setup { display: flex; flex-wrap: wrap; gap: 1.2rem; margin-top: 1rem; align-items: flex-start; }
.totp-setup img { width: 180px; height: 180px; border: 1px solid var(--line); border-radius: 8px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: .7rem 1.2rem; border-radius: 999px; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); max-width: calc(100% - 32px); }

/* Téléphone */
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: .8rem 16px; }
  .side-logo { width: 46px; }
  .menu-toggle { display: block; margin-left: auto; }
  nav, .side-foot { display: none; width: 100%; }
  .sidebar.open nav, .sidebar.open .side-foot { display: flex; }
  .content { padding: 1.2rem 16px; }
  .table.sessions th:nth-child(2), .table.sessions td:nth-child(2) { display: none; }  /* adresse IP */
}

/* -- Phase 1 : aliments et recettes ---------------------------------------------------------- */
.page-head { display: flex; flex-wrap: wrap; gap: .8rem; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: .6rem 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: .8rem; align-items: center; margin-bottom: 1rem; }
.toolbar input[type=search] { flex: 1 1 260px; }
select, textarea { font: inherit; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
textarea { resize: vertical; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: #fff; }
.segmented button { border: 0; background: transparent; padding: .5rem .9rem; font: inherit; cursor: pointer; color: var(--muted); }
.segmented button.on { background: var(--green); color: #fff; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 400px); gap: 1rem; align-items: start; }
.split:has(> .detail-panel[hidden]) { grid-template-columns: minmax(0, 1fr); }
.detail-panel { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow: auto; }
.detail-head { display: flex; justify-content: space-between; gap: .5rem; align-items: flex-start; }
.detail-head h2 { margin: 0; }
.table td small { display: block; color: var(--muted); font-size: .78rem; }
.table.foods tbody tr, #recipe-results tr { cursor: pointer; }
.table.foods tbody tr:hover, #recipe-results tr:hover { background: var(--green-pale); }
.table tr.selected { background: var(--green-pale); }
.table td.star { color: var(--green); width: 1.2rem; }
.table.foods th:nth-child(n+3), .table.foods td:nth-child(n+3),
.table.recipes th:nth-child(n+3), .table.recipes td:nth-child(n+3) { text-align: right; white-space: nowrap; }
.table.compact td { padding: .3rem .4rem; }
.table.compact td:last-child { text-align: right; white-space: nowrap; }
.table.compact tr.sub td:first-child { padding-left: 1.2rem; color: var(--muted); }
.nutrients details { border-top: 1px solid var(--line); padding: .4rem 0; }
.nutrients summary { cursor: pointer; font-weight: 600; color: var(--green-dark); padding: .2rem 0; }
.calc { margin: .8rem 0; align-items: center; }
.calc input { width: 6rem; }
.portions { border-top: 1px solid var(--line); margin-top: .8rem; padding-top: .8rem; }
.portions .inline input:first-child { flex: 1 1 8rem; }
.portions .inline input[type=number] { width: 5.5rem; }
ul.plain { list-style: none; padding: 0; margin: 0 0 .8rem; display: grid; gap: .3rem; }
ul.plain li { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.list-foot { display: flex; flex-wrap: wrap; gap: .8rem; align-items: center; justify-content: space-between; }
.list-foot .hint { margin: 0; }
.pager { display: flex; flex-wrap: wrap; gap: .25rem; align-items: center; }
.pager button { min-width: 2.2rem; height: 2.2rem; border: 0; border-radius: 8px; background: transparent; font: inherit;
  color: var(--ink); cursor: pointer; }
.pager button:hover:not(:disabled) { background: var(--green-pale); }
.pager button.on { background: var(--green-light); color: var(--green-dark); font-weight: 700; }
.pager button:disabled { color: var(--line); cursor: default; }
.pager .gap { color: var(--muted); padding: 0 .3rem; }
.credit { color: var(--muted); font-size: .8rem; margin-top: 1rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .7rem; margin: .6rem 0; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .8rem; margin-top: .9rem; }
.panel > label + label { margin-top: .8rem; }
.form-actions { display: flex; gap: .8rem; align-items: center; margin: 1rem 0; }

/* Fenêtre « mes aliments » */
.dialog { border: 0; border-radius: 16px; padding: 1.4rem; width: min(640px, calc(100% - 32px)); max-height: calc(100vh - 32px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.dialog::backdrop { background: rgba(38, 48, 28, .4); }
.dialog form { display: flex; flex-direction: column; gap: .8rem; }
.dialog details summary { cursor: pointer; font-weight: 600; color: var(--green-dark); }

/* Recherche d'aliment */
.picker { position: relative; margin-top: .6rem; }
.picker input { width: 100%; }
.picker-list { position: absolute; z-index: 10; left: 0; right: 0; top: 100%; margin: .2rem 0 0; padding: .3rem; list-style: none;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .12); max-height: 320px; overflow: auto; }
.picker-list li { padding: .5rem .6rem; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; gap: .8rem; }
.picker-list li small { color: var(--muted); white-space: nowrap; }
.picker-list li.active { background: var(--green-pale); }
.picker-list li.empty { color: var(--muted); cursor: default; }

/* Éditeur de recette */
.recipe-split { grid-template-columns: minmax(0, 1fr) minmax(280px, 360px); }
.table.ingredients input { width: 5.5rem; padding: .4rem .5rem; }
.table.ingredients select { padding: .4rem .5rem; max-width: 12rem; }
.table.ingredients td { vertical-align: middle; }
.table.ingredients td.num { text-align: right; white-space: nowrap; }
.recipe-summary .segmented { margin-bottom: .6rem; }
.macro-box .kcal { font-size: 1.1rem; margin: .4rem 0; }
.macro-box .kcal strong { font-size: 1.8rem; color: var(--green-dark); }
.split-bar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--line); margin: .6rem 0; }
.split-bar .part, .legend .dot { background: var(--green); }
.part.proteines, .dot.proteines { background: #52722c; }
.part.glucides, .dot.glucides { background: #c7d658; }
.part.lipides, .dot.lipides { background: #d9a441; }
.legend { list-style: none; padding: 0; margin: 0 0 .6rem; display: grid; gap: .25rem; font-size: .9rem; }
.legend .dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; margin-right: .4rem; }

@media (max-width: 1100px) {
  .split, .recipe-split { grid-template-columns: 1fr; }
  .detail-panel { position: static; max-height: none; }
}
@media (max-width: 760px) {
  .table.foods th:nth-child(n+4), .table.foods td:nth-child(n+4) { display: none; }
  .table.recipes th:nth-child(n+5), .table.recipes td:nth-child(n+5) { display: none; }
  .segmented button { padding: .45rem .6rem; font-size: .88rem; }
  .pager { gap: 0; flex-wrap: nowrap; }
  .pager button { min-width: 1.9rem; height: 2rem; }
  .pager .gap { padding: 0 .1rem; }
}
