:root {
  --bg: #f4f3ef;
  --surface: #fbfaf7;
  --ink: #161615;
  --ink-2: #4a4945;
  --mute: #8d8b85;
  --line: rgba(22, 22, 21, 0.09);
  --line-strong: rgba(22, 22, 21, 0.16);
  --good: #2f6b50;
  --warn: #b4532f;
  --press: rgba(22, 22, 21, 0.05);
  --on-ink: #f4f3ef;

  --gutter: 20px;
  --radius: 16px;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", system-ui, sans-serif;
  --tabbar: 58px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --surface: #1a1a19;
    --ink: #edebe6;
    --ink-2: #bdbbb5;
    --mute: #85837d;
    --line: rgba(237, 235, 230, 0.08);
    --line-strong: rgba(237, 235, 230, 0.16);
    --good: #7cb596;
    --warn: #e48c68;
    --press: rgba(237, 235, 230, 0.06);
    --on-ink: #121211;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Structure ---------- */
#view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) var(--gutter)
           calc(env(safe-area-inset-bottom, 0px) + var(--tabbar) + 32px);
  min-height: 100dvh;
}
#view.bare { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 32px); }

.screen { animation: enter 0.32s var(--ease) both; }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  color: var(--mute);
  font-size: 15px;
}
.top-brand { display: flex; align-items: center; gap: 10px; }
.top-brand img { width: 28px; height: 28px; border-radius: 7px; flex: none; }
.top .nav { display: flex; gap: 2px; }
.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--ink);
  transition: background 0.15s, opacity 0.15s;
}
.icon-btn:active { background: var(--press); }
.icon-btn:disabled { opacity: 0.25; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

h1 {
  font: 700 34px/1.1 var(--font-display);
  letter-spacing: -0.02em;
  margin: 4px 0 28px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  color: var(--mute);
  margin: 36px 0 10px;
}
.section-title button { color: var(--ink); font-size: 15px; font-weight: 500; }

/* ---------- Héros du jour ---------- */
.hero-label { font-size: 15px; color: var(--ink-2); }
.hero-value {
  font: 300 76px/1 var(--font-display);
  letter-spacing: -0.035em;
  margin: 6px 0 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.hero-value small { font: 400 17px var(--font); letter-spacing: 0; color: var(--mute); }
.hero-sub { margin-top: 8px; font-size: 14px; color: var(--mute); }
.is-warn { color: var(--warn); }
.is-good { color: var(--good); }

.meter {
  position: relative;
  height: 6px;
  margin: 26px 0 0;
  border-radius: 3px;
  background: var(--line);
}
.meter .fill {
  position: absolute; inset: 0 auto 0 0;
  border-radius: 3px;
  background: var(--ink);
  transform-origin: left;
  transition: width 0.5s var(--ease), background 0.2s;
}
.meter .fill.over { background: var(--warn); }
.meter .mark {
  position: absolute; top: -5px; bottom: -5px;
  width: 2px; margin-left: -1px;
  background: var(--bg);
  border-left: 1px solid var(--ink-2);
}
.meter-legend {
  display: flex; justify-content: space-between;
  margin-top: 8px;
  font-size: 12px; color: var(--mute);
}

.trio {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 28px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.trio > div { padding: 14px 0; }
.trio > div + div { padding-left: 14px; border-left: 1px solid var(--line); }
.trio dt { font-size: 13px; color: var(--mute); }
.trio dd { margin: 3px 0 0; font: 500 21px/1.2 var(--font-display); letter-spacing: -0.01em; }

/* ---------- Jeûne ---------- */
.fast-top { padding: 18px 16px 16px; }
.fast-label { font-size: 14px; color: var(--ink-2); }
.fast-count {
  font: 300 46px/1.1 var(--font-display);
  letter-spacing: -0.02em;
  margin-top: 4px;
}
.fast .meter { margin: 14px 0 0; }
.fast .meter .fill.good { background: var(--good); }
.fast .meter .fill.warn { background: var(--warn); }
.fast-sub { margin-top: 10px; font-size: 13px; color: var(--mute); line-height: 1.4; }
.fast-times {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  box-shadow: inset 0 1px 0 var(--line);
}
.ftime {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 4px;
  padding: 12px 14px;
  min-height: 70px;
  cursor: pointer;
  transition: background 0.15s;
}
.ftime:active { background: var(--press); }
.ftime + .ftime { box-shadow: inset 1px 0 0 var(--line); }
.ftime span { font-size: 12px; line-height: 1.25; color: var(--mute); }
.ftime strong { font: 500 19px var(--font-display); }
.ftime strong.unset { color: var(--mute); font-weight: 400; }
.ftime input {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: 0;
  border: 0;
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}
.fast-action { padding: 12px 16px 16px; box-shadow: inset 0 1px 0 var(--line); }
.fast-action .btn { height: 46px; font-size: 16px; }
.chart .bar-mute { fill: var(--mute); opacity: 0.45; }

/* ---------- Listes ---------- */
.list {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px var(--line);
  overflow: hidden;
}
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 10px 16px;
  text-align: left;
  transition: background 0.15s;
}
.row + .row { box-shadow: inset 0 1px 0 var(--line); }
button.row:active { background: var(--press); }
.row .main { flex: 1; min-width: 0; }
.row .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { font-size: 13px; color: var(--mute); margin-top: 1px; }
.row .value { font-weight: 500; white-space: nowrap; }
.row .value small { font-weight: 400; color: var(--mute); font-size: 13px; margin-left: 2px; }
.empty { padding: 22px 16px; color: var(--mute); font-size: 15px; }

/* ---------- Boutons ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  height: 54px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--on-ink);
  font-weight: 600;
  font-size: 17px;
  transition: transform 0.12s var(--ease), opacity 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.35; }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-strong); }
.btn.text { background: transparent; color: var(--warn); height: 44px; font-weight: 500; }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.add-btn { margin-top: 12px; }

/* ---------- Segmenté ---------- */
.seg {
  display: flex;
  padding: 3px;
  border-radius: 11px;
  background: var(--line);
}
.seg button {
  flex: 1;
  height: 34px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-2);
  transition: background 0.2s, color 0.2s;
}
.seg button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 0 0 0.5px var(--line);
}

/* ---------- Évolution ---------- */
.big-weight { font: 300 60px/1 var(--font-display); letter-spacing: -0.03em; display: flex; align-items: baseline; gap: 6px; }
.big-weight small { font: 400 17px var(--font); color: var(--mute); letter-spacing: 0; }
.chart { margin: 22px calc(var(--gutter) * -1) 0; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { font: 11px var(--font); fill: var(--mute); font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .goal { stroke: var(--good); stroke-width: 1; stroke-dasharray: 3 4; }
.chart .raw { fill: var(--mute); opacity: 0.55; }
.chart .avg { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .bar-pos { fill: var(--good); }
.chart .bar-neg { fill: var(--warn); }
.chart .target { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 4; }
.chart-legend { display: flex; gap: 16px; padding: 10px var(--gutter) 0; font-size: 12px; color: var(--mute); }
.chart-legend i { display: inline-block; width: 14px; height: 2px; background: var(--ink); vertical-align: middle; margin-right: 6px; }
.chart-legend i.dot { width: 5px; height: 5px; border-radius: 50%; background: var(--mute); opacity: 0.6; }
.chart-legend i.dash { background: none; border-top: 1px dashed var(--good); }
.chart-legend i.dash-ink { background: none; border-top: 1px dashed var(--ink-2); }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 6px;
  border-top: 1px solid var(--line);
}
.stats > div { padding: 16px 0; border-bottom: 1px solid var(--line); }
.stats > div:nth-child(even) { padding-left: 16px; border-left: 1px solid var(--line); }
.stats dt { font-size: 13px; color: var(--mute); }
.stats dd { margin: 4px 0 0; font: 500 22px/1.2 var(--font-display); letter-spacing: -0.01em; }
.stats dd small { font: 400 13px var(--font); color: var(--mute); margin-left: 3px; }
.note { font-size: 13px; color: var(--mute); margin-top: 12px; line-height: 1.5; }

/* ---------- Formulaires ---------- */
.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 6px 16px;
}
.field + .field, .field + .stack, .stack + .field { box-shadow: inset 0 1px 0 var(--line); }
.field label { color: var(--ink); }
.field input, .field select {
  width: 0;
  flex: 1;
  max-width: 55%;
  text-align: right;
  border: 0;
  background: transparent;
  outline: none;
  font-size: 17px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  -webkit-appearance: none;
  appearance: none;
}
.field input::placeholder { color: var(--mute); opacity: 0.7; }
.field .unit { color: var(--mute); font-size: 15px; margin-left: -6px; }
.stack { padding: 12px 16px 14px; }
.stack > label { display: block; margin-bottom: 10px; }
.choice { display: grid; gap: 2px; }
.choice button {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0;
  text-align: left;
}
.choice button span:last-child { font-size: 13px; color: var(--mute); }
.choice button .check { width: 18px; height: 18px; flex: none; margin-left: 12px; opacity: 0; color: var(--ink); }
.choice button[aria-pressed="true"] .check { opacity: 1; }
.check svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.form-hint { font-size: 13px; color: var(--mute); padding: 8px 16px 0; line-height: 1.5; }
.summary-line {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}
.summary-line:first-child { border-top: 1px solid var(--line); }
.summary-line span:first-child { color: var(--ink-2); }
.summary-line strong { font: 500 19px var(--font-display); }

/* ---------- Monogramme ---------- */
.wordmark {
  display: flex; align-items: center; gap: 12px;
  font: 700 34px/1.1 var(--font-display);
  letter-spacing: -0.02em;
  margin-bottom: 10px;
}
.wordmark img { width: 44px; height: 44px; border-radius: 10px; }
.wordmark.small { font-size: 17px; gap: 8px; margin: 8px 0 6px; letter-spacing: 0; }
.wordmark.small img { width: 28px; height: 28px; border-radius: 7px; }

/* ---------- Interrupteur ---------- */
.switch {
  position: relative;
  flex: none;
  width: 51px; height: 31px;
  border-radius: 16px;
  background: var(--line-strong);
  transition: background 0.25s var(--ease);
}
.switch span {
  position: absolute; top: 2px; left: 2px;
  width: 27px; height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.18);
  transition: transform 0.3s var(--ease);
}
.switch[aria-checked="true"] { background: var(--good); }
.switch[aria-checked="true"] span { transform: translateX(20px); }

/* ---------- Connexion ---------- */
.login {
  min-height: calc(100dvh - 140px);
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.login h1 { margin-bottom: 8px; }
.login p { color: var(--mute); margin: 0 0 32px; }
.login .input {
  width: 100%;
  height: 54px;
  padding: 0 16px;
  border-radius: 14px;
  border: 0;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line-strong);
  outline: none;
  font-size: 17px;
  margin-bottom: 12px;
}
.login .input:focus { box-shadow: inset 0 0 0 1.5px var(--ink); }
.error { color: var(--warn); font-size: 14px; min-height: 20px; margin: 4px 0 8px; }

/* ---------- Tab bar ---------- */
#tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: space-around;
  padding: 6px 12px env(safe-area-inset-bottom, 0px);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(18px);
  backdrop-filter: saturate(1.4) blur(18px);
  border-top: 1px solid var(--line);
}
#tabs button {
  flex: 1;
  max-width: 120px;
  height: var(--tabbar);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 500;
  color: var(--mute);
  transition: color 0.2s;
}
#tabs button[aria-current="page"] { color: var(--ink); }
#tabs svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Feuille (bottom sheet) ---------- */
#sheet { position: fixed; inset: 0; z-index: 20; }
#sheet .scrim {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.32);
  opacity: 0;
  transition: opacity 0.35s var(--ease);
}
#sheet .panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  max-height: calc(100dvh - env(safe-area-inset-top, 0px) - 24px);
  overflow-y: auto;
  background: var(--bg);
  border-radius: 22px 22px 0 0;
  padding: 8px var(--gutter) calc(env(safe-area-inset-bottom, 0px) + 16px);
  transform: translateY(100%);
  transition: transform 0.42s var(--ease);
  overscroll-behavior: contain;
}
#sheet.open .scrim { opacity: 1; }
#sheet.open .panel { transform: translateY(0); }
#sheet.dragging .panel { transition: none; }
.grip { width: 36px; height: 5px; border-radius: 3px; background: var(--line-strong); margin: 0 auto 14px; touch-action: none; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.sheet-head h2 { font: 600 17px var(--font); margin: 0; }
.sheet-head button { color: var(--mute); font-size: 15px; padding: 8px 0 8px 12px; }

.display {
  text-align: center;
  padding: 18px 0 6px;
  font: 300 64px/1 var(--font-display);
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.display small { font: 400 17px var(--font); color: var(--mute); letter-spacing: 0; margin-left: 4px; }
.display.placeholder .v { color: var(--mute); opacity: 0.45; }
.display-sub { text-align: center; color: var(--mute); font-size: 13px; min-height: 18px; }

.label-input {
  width: 100%;
  height: 46px;
  margin: 14px 0 0;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
  outline: none;
  font-size: 16px;
}
.label-input:focus { box-shadow: inset 0 0 0 1.5px var(--ink-2); }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 12px calc(var(--gutter) * -1) 0;
  padding: 0 var(--gutter);
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: none;
  height: 34px;
  padding: 0 12px;
  border-radius: 17px;
  box-shadow: inset 0 0 0 1px var(--line-strong);
  font-size: 14px;
  white-space: nowrap;
  transition: background 0.15s;
}
.chips button:active { background: var(--press); }
.chips button span { color: var(--mute); margin-left: 6px; }

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 16px 0 14px;
}
.keypad button {
  height: 56px;
  border-radius: 12px;
  font: 400 26px var(--font-display);
  transition: background 0.12s;
  user-select: none;
  -webkit-user-select: none;
}
.keypad button:active { background: var(--press); }
.keypad button:disabled { opacity: 0; }
.keypad svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  z-index: 30;
  transform: translate(-50%, -16px);
  opacity: 0;
  padding: 10px 16px;
  border-radius: 20px;
  background: var(--ink);
  color: var(--on-ink);
  font-size: 14px;
  font-weight: 500;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.35s var(--ease);
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
