:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #17201c;
  --muted: #5d6a64;
  --line: #dde3e0;
  --accent: #1f6f5c;
  --accent-text: #ffffff;
  --accent-soft: #e2f0ec;
  --warn: #a86400;
  --warn-soft: #fbf0dc;
  --high: #b3261e;
  --high-soft: #fbe5e3;
  --ok: #2b7a3d;
  --band: rgba(31, 111, 92, 0.14);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101413;
    --card: #1a201e;
    --text: #e6ece9;
    --muted: #9aa8a2;
    --line: #2c3532;
    --accent: #5cc3a6;
    --accent-text: #0d1a16;
    --accent-soft: #1d3530;
    --warn: #f0b45a;
    --warn-soft: #3a2d17;
    --high: #f28b82;
    --high-soft: #3d1f1d;
    --ok: #7fd49a;
    --band: rgba(92, 195, 166, 0.16);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #101413;
  --card: #1a201e;
  --text: #e6ece9;
  --muted: #9aa8a2;
  --line: #2c3532;
  --accent: #5cc3a6;
  --accent-text: #0d1a16;
  --accent-soft: #1d3530;
  --warn: #f0b45a;
  --warn-soft: #3a2d17;
  --high: #f28b82;
  --high-soft: #3d1f1d;
  --ok: #7fd49a;
  --band: rgba(92, 195, 166, 0.16);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}

main { max-width: 560px; margin: 0 auto; padding: 0 16px 16px; }

h1 { font-size: 1.4rem; margin: 8px 0 14px; }
h2 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0 0 8px; }
a { color: var(--accent); }
small { color: var(--muted); font-weight: normal; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 560px; margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) 16px 4px;
}
.brand { font-weight: 700; color: var(--accent); letter-spacing: 0.02em; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 14px;
}
.card.narrow { max-width: 420px; margin: 24px auto; }

.muted { color: var(--muted); }
.center { text-align: center; }
.hint { color: var(--muted); font-size: 0.9rem; margin: -4px 0 14px; }

/* Formulaires */
form label { display: block; margin: 0 0 14px; font-weight: 600; font-size: 0.95rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], select {
  display: block; width: 100%;
  margin-top: 6px; padding: 11px 12px;
  font: inherit; font-weight: normal;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px;
  min-height: 46px;
}
input:focus, select:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.big-field input { font-size: 2rem; font-weight: 700; text-align: center; padding: 14px; }
fieldset { border: 0; padding: 0; margin: 0 0 10px; }
legend { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 8px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row > label { min-width: 0; }
.radio-row { margin: 0 0 14px; }
.radio-row .label { display: block; font-weight: 600; font-size: 0.95rem; margin-bottom: 6px; }
label.radio { display: inline-flex; align-items: center; gap: 6px; margin: 0 18px 0 0; font-weight: normal; }
label.radio input { width: 20px; height: 20px; accent-color: var(--accent); }
.field-error { display: block; color: var(--high); font-size: 0.85rem; font-weight: normal; margin-top: 4px; }
.error { background: var(--high-soft); color: var(--high); padding: 10px 12px; border-radius: 10px; }

button, .button {
  display: inline-block;
  font: inherit; font-weight: 600;
  padding: 11px 18px; min-height: 46px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text);
  text-decoration: none; text-align: center; cursor: pointer;
}
button.primary, .button.primary {
  display: block; width: 100%;
  background: var(--accent); color: var(--accent-text); border-color: var(--accent);
  font-size: 1.05rem;
}
button.link {
  background: none; border: 0; color: var(--accent); text-decoration: underline;
  min-height: 0; padding: 6px; font-weight: normal;
}
button.small { font-size: 0.85rem; }
button.icon { min-height: 40px; min-width: 40px; padding: 0; border: 0; background: none; color: var(--muted); }

/* Messages */
.notice { background: var(--accent-soft); padding: 10px 12px; border-radius: 10px; }
.alert { display: block; padding: 14px 16px; border-radius: var(--radius); margin: 0 0 14px; text-decoration: none; }
.alert.alarm { background: var(--high-soft); color: var(--high); border: 2px solid var(--high); font-size: 1.05rem; }
.alert.reminder { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.nudge { background: var(--warn-soft); padding: 10px 12px; border-radius: 10px; margin: 8px 0 0; }
.nudge p { margin: 0 0 8px; }

/* Accueil */
.hello { font-size: 1.25rem; }
.hero .big { font-size: 3rem; font-weight: 750; line-height: 1.05; letter-spacing: -0.02em; }
.unit { font-size: 1.1rem; font-weight: 500; color: var(--muted); }
.stats { list-style: none; padding: 0; margin: 14px 0; }
.stats li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-top: 1px solid var(--line); }
.stats .k { color: var(--muted); }
.stats .v { font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.mid { font-size: 1.8rem; font-weight: 700; }
.status { font-size: 1.2rem; font-weight: 700; margin: 0 0 4px; }
.status-in { color: var(--ok); }
.status-above { color: var(--warn); }
.status-below { color: var(--muted); }
.waist { display: inline-block; font-size: 0.85rem; padding: 2px 8px; border-radius: 99px; margin-top: 4px; }
.waist-ok { background: var(--accent-soft); color: var(--ok); }
.waist-increased { background: var(--warn-soft); color: var(--warn); }
.waist-high { background: var(--high-soft); color: var(--high); }
.small-link { display: inline-block; margin-top: 6px; font-size: 0.9rem; }
.thresholds { padding-left: 0; list-style: none; }
.thresholds li { margin: 6px 0; }

/* Séances */
.workout-line { font-weight: 600; margin: 0 0 10px; }
.workouts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.workout form { margin: 0; }
.tap {
  display: flex; flex-direction: column; align-items: center; width: 100%;
  padding: 12px 8px; background: var(--bg);
}
.tap-label { font-size: 0.9rem; }
.tap-count { font-size: 1.6rem; font-weight: 750; }
.tap-plus { font-size: 0.8rem; color: var(--accent); }
.workout.done .tap { border-color: var(--accent); background: var(--accent-soft); }
.workout .link { display: block; margin: 4px auto 0; }

/* Saisir */
.choices { display: grid; gap: 12px; margin-bottom: 14px; }
.choice {
  display: flex; flex-direction: column; padding: 18px 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; color: var(--text);
}
.choice strong { font-size: 1.15rem; color: var(--accent); }

/* Graphiques */
.segmented { display: flex; gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.segmented a, .segmented button {
  flex: 1; text-align: center; padding: 8px 4px; border-radius: 8px; border: 0;
  text-decoration: none; color: var(--text); background: none; font-weight: 600; min-height: 40px;
}
.segmented .on { background: var(--accent); color: var(--accent-text); }
svg.chart { display: block; width: 100%; height: auto; overflow: visible; }
.c-grid { stroke: var(--line); stroke-width: 1; }
.c-vgrid { stroke-dasharray: 2 3; }
.c-tick { fill: var(--muted); font-size: 10px; }
.c-band { fill: var(--band); }
.c-hline { stroke-width: 1.5; stroke-dasharray: 5 4; }
.c-hlabel { font-size: 10px; font-weight: 600; }
.c-goal { stroke: var(--accent); fill: var(--accent); }
.c-mid { stroke: var(--muted); fill: var(--muted); }
.c-warn { stroke: var(--warn); fill: var(--warn); }
.c-high { stroke: var(--high); fill: var(--high); }
text.c-hlabel { stroke: none; }
.c-line { fill: none; stroke: var(--text); stroke-width: 2; stroke-linejoin: round; opacity: 0.75; }
.c-point { fill: var(--accent); stroke: var(--card); stroke-width: 1.5; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; list-style: none; padding: 0; margin: 10px 0 0; font-size: 0.85rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 16px; height: 10px; border-radius: 3px; }
.sw-point { width: 10px; border-radius: 50%; background: var(--accent); }
.sw-line { height: 3px; background: var(--text); opacity: 0.75; }
.sw-goal { height: 0; border-top: 2px dashed var(--accent); }
.sw-warn { height: 0; border-top: 2px dashed var(--warn); }
.sw-high { height: 0; border-top: 2px dashed var(--high); }
.sw-band { background: var(--band); }

/* Historique */
.history { list-style: none; padding: 0; margin: 0; }
.history li { display: flex; align-items: center; border-top: 1px solid var(--line); }
.history li:first-child { border-top: 0; }
.history .entry { flex: 1; display: flex; flex-wrap: wrap; gap: 2px 12px; padding: 10px 0; color: var(--text); text-decoration: none; min-width: 0; }
.history .date { color: var(--muted); font-variant-numeric: tabular-nums; }
.history .value { font-weight: 650; margin-left: auto; }
.history .note { flex-basis: 100%; color: var(--muted); font-size: 0.9rem; overflow-wrap: anywhere; }
.history form { margin: 0; }
.links { padding-left: 18px; margin: 0; }
.links li { margin: 6px 0; }

/* Barre de navigation */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px 10px; font-size: 0.75rem; color: var(--muted); text-decoration: none;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.on { color: var(--accent); font-weight: 650; }

@media (max-width: 360px) {
  .row, .grid2 { grid-template-columns: 1fr; }
  .hero .big { font-size: 2.5rem; }
}

/* ---- Menus ---------------------------------------------------------------- */
textarea {
  display: block; width: 100%; margin-top: 6px; padding: 11px 12px;
  font: inherit; font-weight: normal; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; resize: vertical;
}
input[type="search"] {
  display: block; width: 100%; padding: 11px 12px; min-height: 46px;
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px;
}
input[type="file"] { display: block; margin: 8px 0 12px; max-width: 100%; }
.subnav { margin-top: 4px; }
.subnav a { font-size: 0.9rem; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.title-row h1 { margin: 8px 0; }
.spaced { margin-top: 16px; }
.tag {
  display: inline-block; font-size: 0.72rem; font-weight: 600; vertical-align: middle;
  padding: 1px 7px; border-radius: 99px; background: var(--warn-soft); color: var(--warn);
}
.week-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.week-head h1 { flex: 1; text-align: center; font-size: 1.1rem; margin: 0; }
.week-head .button { min-width: 46px; padding: 8px 0; font-size: 1.3rem; line-height: 1.2; }
.days { display: grid; gap: 10px; margin-bottom: 14px; }
.day { margin: 0; padding: 10px 12px; }
.day.today { border-color: var(--accent); }
.day h2 { margin: 0; text-transform: none; letter-spacing: 0; font-size: 1rem; color: var(--text); }
.day-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.day-head form { margin: 0; }
.chip {
  min-height: 32px; padding: 4px 10px; font-size: 0.8rem; font-weight: 500;
  border-radius: 99px; color: var(--muted); background: var(--bg);
}
.chip.on { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); font-weight: 650; }
.slot {
  display: flex; align-items: baseline; gap: 10px; padding: 9px 0;
  border-top: 1px solid var(--line); color: var(--text); text-decoration: none;
}
.slot-label { flex: 0 0 44px; font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.slot-value { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.slot-value em { font-weight: 500; }
.slot.empty .slot-value { font-weight: 400; }
.slot-note { display: block; font-weight: 400; color: var(--muted); }
.slot.proposed .slot-value { color: var(--accent); }
.slot .radio { margin: 0; }
.feedback .rating, .rating { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; }
.rating button { min-height: 38px; padding: 6px 12px; font-weight: 500; }
.rating.small button { min-height: 34px; min-width: 40px; padding: 4px 8px; }
.balance .stats { margin: 0; }
.balance .stats .v { white-space: normal; text-align: right; }

/* Sélecteur de plat */
.search { margin-bottom: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chips select { width: auto; min-height: 36px; margin: 0; padding: 4px 8px; font-size: 0.9rem; }
.chip-check {
  display: inline-flex; align-items: center; gap: 5px; margin: 0; padding: 5px 10px;
  font-size: 0.85rem; font-weight: 500; border: 1px solid var(--line); border-radius: 99px; background: var(--card);
}
.chip-check input { accent-color: var(--accent); }
.specials { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.specials button { font-weight: 500; font-size: 0.9rem; }
.specials .on, .pick.on { border-color: var(--accent); background: var(--accent-soft); }
.picker { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; }
.pick {
  display: flex; flex-direction: column; align-items: flex-start; width: 100%;
  text-align: left; padding: 10px 12px; font-weight: 600;
}
.pick-meta { font-size: 0.82rem; font-weight: 400; color: var(--muted); }
.slot-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.dish-list .entry { flex-direction: column; }
.dish-name { font-weight: 600; }
.dish-note { white-space: pre-line; margin: 10px 0 0; }
.dish-title { text-transform: none; letter-spacing: 0; font-size: 1.1rem; color: var(--text); }
.actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; }
.actions form { margin: 0; }
.suggestion { display: flex; align-items: flex-start; gap: 10px; font-weight: normal; padding: 8px 0; }
.suggestion input { margin-top: 4px; flex: 0 0 auto; }
label.card.suggestion { padding: 14px; margin-bottom: 10px; }
.invite-link { background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }
.invite-link .copy { margin: 6px 0 10px; font-size: 0.85rem; }
.ai-wait { text-align: center; color: var(--muted); margin: 8px 0 0; }
.ai-wait::before {
  content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 8px; vertical-align: -1px;
  border: 2px solid var(--accent); border-right-color: transparent; border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }

/* Vue Tableau : lisible de loin, téléphone ou tablette posée dans la cuisine */
.board-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; }
.board { display: grid; gap: 10px; grid-template-columns: 1fr; }
.board-day { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.board-day.today { border: 2px solid var(--accent); }
.board-day h2 { font-size: 1.05rem; text-transform: none; letter-spacing: 0; color: var(--text); margin: 0 0 6px; }
.board-day h2 span { color: var(--muted); font-weight: 500; }
.board-slot { display: flex; align-items: baseline; gap: 12px; padding: 6px 0; border-top: 1px solid var(--line); }
.board-label { flex: 0 0 52px; font-size: 0.85rem; color: var(--muted); text-transform: uppercase; }
.board-dish { font-size: 1.35rem; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
@media (min-width: 700px) {
  main:has(.board) { max-width: 1200px; }
  .board { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
  .board-dish { font-size: 1.5rem; }
}
@media print {
  .tabbar, .top, .no-print, .notice { display: none !important; }
  body { padding: 0; background: #fff; color: #000; }
  main { max-width: none; }
  .board { grid-template-columns: repeat(4, 1fr); }
  .board-day { break-inside: avoid; border-color: #999; }
}
