:root {
  --paper: #F2F5F1;
  --card: #FFFFFF;
  --ink: #17393D;
  --text: #1E2A2B;
  --muted: #5B6E6C;
  --line: #D6E0D7;
  --mist: #E4ECE4;
  --leaf: #3E8E4F;
  --leaf-soft: #DCEFDF;
  --water: #2C78A0;
  --water-soft: #DCEBF3;
  --amber: #A86A12;
  --amber-soft: #F7EAD3;
  --alert: #B3362B;
  --alert-soft: #F8E1DE;
  --f1: #D9A441;
  --f2: #3E8E4F;
  --tr: #93BC9C;
  --f3: #2C78A0;
  --f4: #17393D;
  --display: "Bricolage Grotesque", "Albert Sans", system-ui, sans-serif;
  --body: "Albert Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 22px;
  --tabbar: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0E1C1E; --card: #152628; --ink: #CFE6DD; --text: #E5EEEA; --muted: #9BB1AC;
    --line: #2A3F41; --mist: #1D3335; --leaf: #6CC07F; --leaf-soft: #1E3A27;
    --water: #6BB6DD; --water-soft: #173343; --amber: #E3A64A; --amber-soft: #3A2C15;
    --alert: #EE7A6E; --alert-soft: #3E1E1A; --f4: #CFE6DD; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0E1C1E; --card: #152628; --ink: #CFE6DD; --text: #E5EEEA; --muted: #9BB1AC;
  --line: #2A3F41; --mist: #1D3335; --leaf: #6CC07F; --leaf-soft: #1E3A27;
  --water: #6BB6DD; --water-soft: #173343; --amber: #E3A64A; --amber-soft: #3A2C15;
  --alert: #EE7A6E; --alert-soft: #3E1E1A; --f4: #CFE6DD; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--text);
  font: 16px/1.5 var(--body); min-height: 100dvh;
}
#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; }
h1, h2, h3 { font-family: var(--display); color: var(--ink); margin: 0; line-height: 1.15; }
h1 { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.01em; }
h2 { font-size: 1.25rem; font-weight: 800; }
h3 { font-size: 1.02rem; font-weight: 600; }
p { margin: 0 0 .6em; }
a { color: var(--water); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--water); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.num { font-family: var(--display); font-weight: 800; font-variant-numeric: tabular-nums; }

/* ---------- estrutura ---------- */
.screen { padding: 12px 16px calc(var(--tabbar) + 32px + env(safe-area-inset-bottom)); }
.screen.no-tabs { padding-bottom: 40px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 6px; max-width: 560px; margin: 0 auto;
}
.topbar .brand { font-family: var(--display); font-weight: 800; color: var(--ink); font-size: 1.05rem; }
.btn-sos {
  border: 1.5px solid var(--alert); color: var(--alert); background: transparent;
  border-radius: 999px; padding: 6px 12px; font-weight: 600; font-size: .85rem; cursor: pointer;
}
.back { background: none; border: 0; color: var(--ink); font-weight: 600; padding: 8px 0; cursor: pointer; }
section { margin-top: 22px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }

.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 14px 16px;
}
.panel + .panel { margin-top: 10px; }
.stack > * + * { margin-top: 10px; }

/* ---------- botões e campos ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 600; cursor: pointer;
  background: var(--ink); color: var(--paper); min-height: 46px; text-decoration: none;
}
.btn.leaf { background: var(--leaf); color: #fff; }
.btn.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn.danger { background: var(--alert); color: #fff; }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: .9rem; border-radius: 10px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.panel.stack > .link { display: block; text-align: left; }
.link { background: none; border: 0; color: var(--water); font-weight: 600; cursor: pointer; padding: 4px 0; }
label.field { display: block; margin-top: 12px; }
label.field > span { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
.input, select.input, textarea.input {
  width: 100%; border: 1.5px solid var(--line); border-radius: 10px; background: var(--card);
  padding: 11px 12px; min-height: 46px;
}
.input:focus { border-color: var(--water); outline: none; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.check:last-child { border-bottom: 0; }
.check input { width: 22px; height: 22px; margin-top: 1px; accent-color: var(--leaf); flex: none; }
.seg { display: flex; background: var(--mist); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 9px 6px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip { flex: none; border: 1.5px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: .88rem; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* ---------- Hoje: cabeçalho e fita do protocolo ---------- */
.today-head { padding-top: 6px; }
.today-head .phase { margin-top: 2px; }
.today-head .day { font-family: var(--display); font-weight: 800; color: var(--muted); font-size: 1.05rem; margin-top: 4px; }
.ribbon { margin-top: 18px; }
.ribbon-track { display: flex; align-items: flex-end; gap: 2px; height: 46px; }
.ribbon-track i {
  flex: 1 1 0; min-width: 2px; height: 22px; border-radius: 3px; background: var(--c);
  opacity: .32; transition: height .25s;
}
.ribbon-track i.done { opacity: 1; }
.ribbon-track i.now { height: 46px; opacity: 1; box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--c); }
.ribbon-track .tail { flex: 0 0 26px; height: 22px; border-radius: 3px; background: repeating-linear-gradient(90deg, var(--f4) 0 3px, transparent 3px 6px); opacity: .5; }
.ribbon-legend { display: flex; justify-content: space-between; gap: 6px; margin-top: 8px; font-size: .78rem; color: var(--muted); }
.ribbon-legend b { color: var(--text); font-weight: 600; }

/* ---------- alertas ---------- */
.note { border-radius: var(--r-md); padding: 12px 14px; border: 1px solid transparent; }
.note h3 { margin-bottom: 4px; }
.note.info { background: var(--water-soft); }
.note.warn { background: var(--amber-soft); }
.note.alert { background: var(--alert-soft); }
.note.ok { background: var(--leaf-soft); }
.note .actions { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- água ---------- */
.water { display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: center; }
.water .amount { font-size: 2.2rem; color: var(--water); line-height: 1; }
.water .of { color: var(--muted); font-size: .9rem; }
.bar { height: 10px; background: var(--mist); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.bar > span { display: block; height: 100%; background: var(--c, var(--leaf)); border-radius: 99px; transition: width .3s; }
.bar.over > span { background: var(--amber); }
.water-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.water-btns button { border: 1.5px solid var(--water); color: var(--water); background: transparent; border-radius: 10px; padding: 7px 11px; font-weight: 600; cursor: pointer; }

/* ---------- refeições ---------- */
.meal { padding: 12px 0; border-top: 1px solid var(--line); }
.meal:first-child { border-top: 0; padding-top: 2px; }
.meal-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.meal-need { font-size: .88rem; color: var(--muted); margin-top: 2px; }
.meal-need .done { color: var(--leaf); }
.item { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.item .grow { flex: 1; min-width: 0; }
.item .name { font-weight: 500; overflow-wrap: anywhere; }
.item .meta { font-size: .82rem; color: var(--muted); }
.item .x { border: 0; background: transparent; color: var(--muted); font-size: 1.3rem; width: 36px; height: 36px; border-radius: 8px; cursor: pointer; }
.tag { display: inline-block; font-size: .72rem; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: var(--alert-soft); color: var(--alert); }

/* ---------- totais ---------- */
.limits { display: grid; gap: 10px; }
.limit-row { display: grid; grid-template-columns: 1fr auto; font-size: .92rem; }
.limit-row .bar { grid-column: 1 / -1; margin-top: 5px; height: 8px; }
.kcal-big { font-size: 2rem; line-height: 1; color: var(--ink); }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; text-align: left; }
.macros div { background: var(--mist); border-radius: 10px; padding: 8px 10px; }
.macros b { display: block; font-family: var(--display); font-size: 1.1rem; color: var(--ink); }
.macros span { font-size: .78rem; color: var(--muted); }

/* ---------- navegação de data ---------- */
.datenav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.datenav button { border: 1.5px solid var(--line); background: var(--card); width: 42px; height: 42px; border-radius: 12px; font-size: 1.2rem; cursor: pointer; color: var(--ink); }
.datenav .label { text-align: center; }
.datenav .label b { display: block; font-family: var(--display); font-size: 1.15rem; color: var(--ink); }

/* ---------- receitas ---------- */
.recipe-list { display: grid; gap: 0; }
.recipe-row { display: flex; align-items: center; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.recipe-row .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.recipe-row .grow { flex: 1; min-width: 0; }
.recipe-row .name { font-weight: 600; color: var(--ink); }
.recipe-row .meta { font-size: .83rem; color: var(--muted); }
.fav { border: 0; background: none; font-size: 1.3rem; cursor: pointer; color: var(--muted); width: 40px; height: 40px; }
.fav[aria-pressed="true"] { color: var(--amber); }
ol.steps, ul.ing { padding-left: 1.2em; margin: 0; }
ul.ing li, ol.steps li { margin: 4px 0; }
.shortcuts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.shortcut { display: block; text-decoration: none; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px; }
.shortcut b { display: block; font-family: var(--display); font-size: 1.05rem; }
.shortcut span { font-size: .85rem; color: var(--muted); }

/* ---------- evolução ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart .ln { fill: none; stroke: var(--leaf); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .pt { fill: var(--card); stroke: var(--leaf); stroke-width: 2; }
.chart .ax { stroke: var(--line); stroke-width: 1; }
.chart text { fill: var(--muted); font: 11px var(--body); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.stats b { display: block; font-family: var(--display); font-size: 1.3rem; color: var(--ink); }
.stats span { font-size: .78rem; color: var(--muted); }
table.list { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.list td, table.list th { text-align: left; padding: 8px 4px; border-bottom: 1px solid var(--line); }
table.list th { font-weight: 600; color: var(--muted); font-size: .8rem; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar nav { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); height: var(--tabbar); }
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: .72rem; font-weight: 600; }
.tabbar a svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a[aria-current="page"] { color: var(--ink); }
.tabbar a[aria-current="page"] svg { stroke-width: 2.4; }

/* ---------- folha (bottom sheet) ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 25, 27, .45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--paper); width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto;
  border-radius: var(--r-lg) var(--r-lg) 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  animation: up .22s ease-out;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 12px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.sheet-head .close { border: 0; background: var(--mist); border-radius: 50%; width: 36px; height: 36px; font-size: 1.2rem; cursor: pointer; color: var(--ink); }
@keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.food-results { margin-top: 8px; }
.food-btn { display: flex; width: 100%; text-align: left; gap: 10px; align-items: center; border: 0; border-bottom: 1px solid var(--line); background: transparent; padding: 11px 2px; cursor: pointer; }
.food-btn .grow { flex: 1; min-width: 0; }
.food-btn .name { font-weight: 500; }
.food-btn .meta { font-size: .8rem; color: var(--muted); }
.food-btn.out .name { color: var(--muted); }

/* ---------- login e onboarding ---------- */
.auth { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 32px 20px; }
.auth .mark { width: 64px; height: 64px; border-radius: 18px; margin-bottom: 18px; }
.auth h1 { font-size: 2.3rem; }
.steps-dots { display: flex; gap: 6px; margin: 4px 0 18px; }
.steps-dots i { flex: 1; height: 4px; border-radius: 9px; background: var(--line); }
.steps-dots i.on { background: var(--leaf); }
.terms-box { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px 16px; max-height: 46dvh; overflow: auto; font-size: .93rem; }
.terms-box ol { padding-left: 1.2em; margin: 0; }
.terms-box li { margin-bottom: 8px; }
.footer-note { font-size: .78rem; color: var(--muted); margin-top: 28px; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + 18px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 12px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

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