:root {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --surface-2: #f1ebdf;
  --ink: #2a2733;
  --muted: #7b7588;
  --line: #e7dfd0;
  --accent: #5a57d6;
  --accent-ink: #ffffff;
  --accent-soft: #eae9fb;
  --ok: #3d8b67;
  --ok-soft: #e3f1ea;
  --warn: #c07a26;
  --warn-soft: #f8ecdc;
  --bad: #c2483f;
  --bad-soft: #f8e3e0;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(42, 39, 51, .05), 0 8px 24px rgba(42, 39, 51, .06);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--font); }
body { min-height: 100dvh; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: var(--ink); }
h1, h2, h3 { font-family: var(--display); font-weight: 650; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.15rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--bad); min-height: 1.2em; margin: 0; }

/* ---------- structure ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 14px) max(24px, calc((100% - 1180px) / 2 + 24px)) 12px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(10px);
}
.brand { font-family: var(--display); font-size: 1.45rem; font-weight: 650; }
.brand.big { font-size: 2.4rem; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
#view { padding: 4px 24px calc(110px + env(safe-area-inset-bottom)); max-width: 1180px; margin: 0 auto; }

.tabs {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + env(safe-area-inset-bottom));
  display: flex; gap: 4px; padding: 6px; z-index: 20;
  background: var(--surface); border-radius: 999px; box-shadow: var(--shadow);
}
.tabs button {
  display: flex; align-items: center; gap: 8px; border: 0; background: none; cursor: pointer;
  padding: 10px 18px; border-radius: 999px; color: var(--muted); font-weight: 500;
}
.tabs button.active { background: var(--accent); color: var(--accent-ink); }
.tabs .ico { font-size: 1.05rem; }
@media (max-width: 560px) {
  .tabs { left: 12px; right: 12px; transform: none; justify-content: space-between; }
  .tabs button { flex-direction: column; gap: 0; padding: 6px 10px; font-size: .72rem; flex: 1; }
  #view, .topbar { padding-left: 16px; padding-right: 16px; }
}

/* ---------- éléments ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 0 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 0; cursor: pointer;
  background: var(--surface-2); font-weight: 500;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .9rem; border-radius: 10px; }
.btn.icon { width: 44px; padding: 0; }
.btn[disabled] { opacity: .5; pointer-events: none; }

input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--muted); }
label.field > span { font-weight: 500; }
.fields { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); font-size: .8rem; font-weight: 500; white-space: nowrap;
}
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; text-align: center; }

/* ---------- aujourd'hui ---------- */
.daynav { display: flex; align-items: center; gap: 6px; }
.daynav .label { min-width: 170px; text-align: center; font-weight: 600; }
.person-head { display: flex; align-items: center; gap: 18px; }
.ring { position: relative; width: 118px; height: 118px; flex: none; }
.ring svg { transform: rotate(-90deg); }
.ring .center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; line-height: 1.1; }
.ring .num { font-family: var(--display); font-size: 1.6rem; font-weight: 650; }
.macros { flex: 1; display: grid; gap: 8px; }
.macro { display: grid; grid-template-columns: 74px 1fr auto; gap: 8px; align-items: center; font-size: .85rem; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.meals { margin-top: 16px; display: flex; flex-direction: column; gap: 2px; }
.slot-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 12px 0 4px; }
.meal { display: flex; align-items: center; gap: 12px; padding: 8px 6px; border-radius: 12px; cursor: pointer; }
.meal:hover { background: var(--surface-2); }
.meal img { width: 44px; height: 44px; object-fit: cover; border-radius: 10px; flex: none; }
.meal .thumb { width: 44px; height: 44px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; flex: none; color: var(--muted); }
.meal .name { flex: 1; min-width: 0; }
.meal .name div:first-child { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meal .kcal { font-weight: 600; white-space: nowrap; }
.empty { color: var(--muted); padding: 10px 6px; font-size: .9rem; }
.spark { display: flex; align-items: flex-end; gap: 4px; height: 46px; margin-top: 14px; }
.spark span { flex: 1; background: var(--accent-soft); border-radius: 4px 4px 2px 2px; min-height: 3px; position: relative; }
.spark span.over { background: var(--warn-soft); }
.spark span.today { background: var(--accent); }

/* ---------- menus ---------- */
.week { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.dayplan h3 { margin-bottom: 8px; }
.dish { padding: 12px 0; border-top: 1px solid var(--line); }
.dish:first-of-type { border-top: 0; }
.dish .title { font-weight: 600; margin: 4px 0 2px; }
.dish details { margin-top: 6px; font-size: .9rem; }
.dish summary { cursor: pointer; color: var(--accent); }
.dish ol { padding-left: 20px; margin: 6px 0; }
.portions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.config-table { width: 100%; border-collapse: collapse; }
.config-table td, .config-table th { padding: 6px 4px; text-align: left; }
.config-table th { font-size: .8rem; color: var(--muted); font-weight: 500; }
.shopping label { display: flex; gap: 10px; align-items: center; padding: 6px 0; }
.shopping input { width: 22px; min-height: 22px; accent-color: var(--accent); }
.shopping label.done span { text-decoration: line-through; color: var(--muted); }

/* ---------- assistant ---------- */
.chat { display: flex; flex-direction: column; gap: 12px; padding-bottom: 90px; }
.bubble { max-width: min(680px, 88%); padding: 12px 16px; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.bubble.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 6px; }
.bubble.assistant { border-bottom-left-radius: 6px; }
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin: 0; }
.bubble ul { margin: 4px 0 8px; padding-left: 20px; }
.composer {
  position: fixed; left: 50%; transform: translateX(-50%); width: min(900px, calc(100% - 32px));
  bottom: calc(84px + env(safe-area-inset-bottom)); display: flex; gap: 8px; z-index: 15;
  background: var(--surface); padding: 8px; border-radius: 16px; box-shadow: var(--shadow);
}
.composer textarea { min-height: 46px; height: 46px; border: 0; resize: none; }
.suggestions { display: flex; gap: 8px; flex-wrap: wrap; }
.suggestions button { border: 0; cursor: pointer; }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- profils ---------- */
.profile-pick { display: flex; gap: 8px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); font-size: 1.25rem; flex: none; }
.pick { border: 0; background: var(--surface-2); border-radius: 999px; padding: 4px 12px 4px 4px; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.pick .avatar { width: 32px; height: 32px; font-size: 1rem; }
.pick.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.cat { border-top: 1px solid var(--line); padding: 12px 0; }
.cat summary { cursor: pointer; font-weight: 600; display: flex; justify-content: space-between; list-style: none; }
.cat summary::-webkit-details-marker { display: none; }
.foods { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.food { border: 0; cursor: pointer; padding: 8px 12px; border-radius: 999px; background: var(--surface-2); font-size: .9rem; user-select: none; }
.food[data-v="love"] { background: var(--accent); color: var(--accent-ink); }
.food[data-v="like"] { background: var(--accent-soft); color: var(--accent); }
.food[data-v="dislike"] { background: var(--warn-soft); color: var(--warn); }
.food[data-v="never"] { background: var(--bad-soft); color: var(--bad); text-decoration: line-through; }
.target-box { display: flex; gap: 18px; flex-wrap: wrap; padding: 14px 16px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); }
.target-box b { font-family: var(--display); font-size: 1.4rem; display: block; color: var(--ink); }

/* ---------- modal / toast ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(42, 39, 51, .35); display: grid; place-items: center; padding: 16px; }
.sheet { width: min(620px, 100%); max-height: calc(100dvh - 32px); overflow: auto; background: var(--bg); border-radius: 22px; padding: 22px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 16px; }
.sheet .preview { width: 100%; max-height: 300px; object-fit: cover; border-radius: 16px; }
.items { display: flex; flex-direction: column; gap: 8px; }
.item { display: grid; grid-template-columns: 1fr 80px 70px 36px; gap: 6px; align-items: center; }
.item input { min-height: 40px; padding: 6px 10px; }
.loading { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 28px 0; text-align: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 60; background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-size: .95rem; }
