:root {
  --bg: #eef1f1;
  --surface: #ffffff;
  --surface-2: #f5f7f7;
  --line: #e1e6e6;
  --text: #2b3333;
  --muted: #6d7878;
  --accent: #3a9d74;
  --accent-soft: #e2f3eb;
  --protein: #3a9d74;
  --carbs: #e0a23a;
  --fat: #d9665b;
  --water: #3b8fd6;
  --warn: #c9822d;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 40, 40, .06), 0 4px 14px rgba(20, 40, 40, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1514; --surface: #182120; --surface-2: #1f2a29; --line: #2a3634;
    --text: #e6eeec; --muted: #93a19e; --accent: #5cc79a; --accent-soft: #1d3a2f;
    --protein: #5cc79a; --carbs: #f0b65a; --fat: #ef8277; --water: #63a9e6;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1514; --surface: #182120; --surface-2: #1f2a29; --line: #2a3634;
  --text: #e6eeec; --muted: #93a19e; --accent: #5cc79a; --accent-soft: #1d3a2f;
  --protein: #5cc79a; --carbs: #f0b65a; --fat: #ef8277; --water: #63a9e6;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }

#app { max-width: 640px; margin: 0 auto; padding: calc(12px + env(safe-area-inset-top)) 16px 24px; }
h1 { font-size: 26px; margin: 4px 0 2px; letter-spacing: -.02em; }
h2 { font-size: 17px; margin: 0; }
h3 { font-size: 15px; margin: 0; }
.sub { color: var(--muted); font-size: 14px; margin: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.stack { display: grid; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.section-title { margin: 22px 2px 10px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

.btn { border: 0; border-radius: 12px; padding: 10px 14px; background: var(--surface-2); font-weight: 600; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: transparent; color: var(--accent); padding: 6px 8px; }
.btn.small { padding: 6px 10px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.icon-btn { border: 0; background: var(--surface-2); width: 36px; height: 36px; border-radius: 50%; font-size: 18px; display: grid; place-items: center; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: 14px; white-space: nowrap; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
input.field, textarea.field, select.field {
  width: 100%; border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 10px 12px;
}
label.lbl { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }

/* Topo do dia */
.daybar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.summary { display: grid; grid-template-columns: 132px 1fr; gap: 16px; align-items: center; }
.ring { position: relative; width: 132px; height: 132px; }
.ring svg { transform: rotate(-90deg); }
.ring .center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring .big { font-size: 26px; font-weight: 700; line-height: 1; }
.ring .small { font-size: 12px; color: var(--muted); }
.macro { display: grid; gap: 4px; margin-bottom: 10px; }
.macro:last-child { margin-bottom: 0; }
.macro .top { display: flex; justify-content: space-between; font-size: 13px; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; transition: width .4s ease; }

/* Refeições */
.meal { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center; width: 100%; text-align: left; border: 0; }
.meal .emoji { width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; font-size: 20px; }
.meal.done .emoji { background: var(--accent-soft); }
.meal .what { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.meal.done .what { color: var(--text); }
.meal .kc { font-weight: 700; text-align: right; font-size: 15px; }
.meal .kc small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.meals .card { padding: 12px 14px; }

.tracker .big { font-size: 22px; font-weight: 700; }
.steps { display: flex; gap: 6px; flex-wrap: wrap; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch { width: 52px; height: 32px; border-radius: 99px; border: 0; background: var(--line); position: relative; transition: background .2s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(20px); }

/* Sheet */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); animation: fade .2s; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 86vh; overflow-y: auto;
  background: var(--bg); border-radius: 20px 20px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto; animation: up .25s ease;
}
.sheet-panel::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 12px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.opt { display: flex; justify-content: space-between; gap: 12px; align-items: center; width: 100%; text-align: left; border: 0; background: var(--surface); padding: 12px 14px; border-radius: 12px; }
.opt.sel { outline: 2px solid var(--accent); }
.opt .k { font-weight: 600; white-space: nowrap; font-size: 14px; }
.opt .m { font-size: 12px; color: var(--muted); }
.opts { display: grid; gap: 8px; }

/* Assistente */
.chat { display: grid; gap: 10px; margin: 12px 0; }
.bubble { max-width: 88%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; font-size: 15px; }
.bubble.user { justify-self: end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.bubble.model { justify-self: start; background: var(--surface); box-shadow: var(--shadow); border-bottom-left-radius: 4px; }
.recipe { border-left: 4px solid var(--accent); }
.recipe ul, .recipe ol { margin: 8px 0; padding-left: 20px; font-size: 14px; }
.recipe li { margin: 2px 0; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; font-size: 12px; }
.pill { padding: 3px 8px; border-radius: 99px; background: var(--surface-2); }
.pill.k { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.composer { position: sticky; bottom: calc(72px + env(safe-area-inset-bottom)); display: flex; gap: 8px; background: var(--bg); padding: 8px 0; }
.composer textarea { resize: none; min-height: 44px; max-height: 120px; }
.typing { color: var(--muted); font-size: 14px; }

/* Corpo */
.stat .v { font-size: 22px; font-weight: 700; }
.stat .d { font-size: 12px; }
.up { color: var(--fat); } .down { color: var(--accent); }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 19px; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: right; color: var(--muted); font-weight: 500; font-size: 12px; padding: 4px; }
table.t th:first-child, table.t td:first-child { text-align: left; }
table.t td { padding: 7px 4px; border-top: 1px solid var(--line); text-align: right; }

.plan-meal summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.plan-meal summary::-webkit-details-marker { display: none; }
.plan-meal ol { margin: 10px 0 0; padding-left: 22px; font-size: 14px; }
.plan-meal li { margin: 4px 0; }
.plan-meal li span { color: var(--muted); }
.rules li { margin: 4px 0; font-size: 14px; }

/* Tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { border: 0; background: none; padding: 8px 0 10px; font-size: 11px; color: var(--muted); display: grid; justify-items: center; gap: 2px; }
.tabs button span { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabs button.on { color: var(--accent); font-weight: 600; }
.tabs button.on span { filter: none; opacity: 1; }

.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 60; max-width: calc(100% - 32px); }

.login { min-height: 80vh; display: grid; place-content: center; text-align: center; gap: 14px; }
.login img { width: 72px; margin: 0 auto; }
.empty { text-align: center; color: var(--muted); font-size: 14px; padding: 12px; }
.sync { font-size: 12px; color: var(--muted); }

@media (max-width: 380px) {
  .summary { grid-template-columns: 1fr; justify-items: center; }
  .summary .macros { width: 100%; }
}

/* ---------- Corpo: abas, cartões e listas ---------- */
button.card { border: 0; width: 100%; text-align: left; color: inherit; font: inherit; display: block; }
button.card:active, .li.metric:active, tr.tap:active { transform: scale(.99); opacity: .85; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 14px; margin: 14px 0 4px; position: sticky; top: calc(6px + env(safe-area-inset-top)); z-index: 5; box-shadow: 0 0 0 6px var(--bg); }
.seg button { border: 0; background: none; padding: 8px 0; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--muted); transition: background .2s, color .2s; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
#btab { margin-top: 12px; animation: fade .25s; }

.cta { display: flex; align-items: center; gap: 12px; background: var(--accent-soft); box-shadow: none; }
.cta .sub { font-size: 13px; }
.cta-icon { width: 44px; height: 44px; border-radius: 12px; background: var(--surface); display: grid; place-items: center; font-size: 22px; flex: none; }
.hint { background: var(--accent-soft); box-shadow: none; font-size: 14px; }

.stat .v { font-size: 24px; font-weight: 700; margin-top: 2px; letter-spacing: -.01em; }
.stat .v small { font-size: 14px; font-weight: 500; color: var(--muted); }
.stat .row { align-items: flex-start; }
.spark { width: 72px; height: 28px; flex: none; }
.delta { font-size: 12px; color: var(--muted); }
.delta.up, .pctpill.up, .epct.up, td.up { color: var(--fat); }
.delta.down, .pctpill.down, .epct.down, td.down { color: var(--accent); }
.chart-card { padding: 12px 10px 6px; }

.list { padding: 4px 14px; }
.li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; color: inherit; font: inherit; }
.list > .li:first-child { border-top: 0; }
.li .sub { font-size: 13px; margin: 0; }
.li.metric > div { flex: 1; min-width: 0; }
.pctpill { min-width: 62px; text-align: right; font-weight: 700; font-size: 14px; color: var(--muted); }
.chev { color: var(--muted); font-size: 20px; line-height: 1; }
.icon-btn.small { width: 30px; height: 30px; font-size: 13px; color: var(--muted); }
tr.tap { cursor: pointer; }

.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mini { background: var(--surface); border-radius: 12px; padding: 10px; text-align: center; }
.mini .sub { font-size: 12px; margin: 0 0 2px; }
.mini b { font-size: 18px; }

/* ---------- Editor de avaliação ---------- */
.edit-list { padding: 4px 14px; }
.erow { display: grid; grid-template-columns: 1fr 96px 64px; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.edit-list .erow:first-child { border-top: 0; }
.elabel { display: grid; font-size: 14px; }
.elabel small { font-size: 12px; }
.erow input.field { padding: 8px 10px; text-align: right; font-size: 16px; }
.epct { text-align: right; font-size: 13px; font-weight: 700; color: var(--muted); }
.sticky-save { position: sticky; bottom: calc(-20px - env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); padding: 18px 0 calc(4px + env(safe-area-inset-bottom)); margin-top: 8px; }
.big-input { font-size: 28px !important; font-weight: 700; text-align: center; }

/* ---------- Importação ---------- */
.drop { display: grid; justify-items: center; gap: 4px; padding: 26px 16px; border: 2px dashed var(--line); border-radius: 16px; background: var(--surface); cursor: pointer; text-align: center; transition: border-color .2s, background .2s; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-icon { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 24px; margin-bottom: 4px; }
.files { display: grid; gap: 8px; margin-top: 12px; }
.file { display: flex; align-items: center; gap: 10px; background: var(--surface); border-radius: 12px; padding: 10px 12px; animation: up .2s; }
.file-ic { font-size: 22px; }
.file-name { flex: 1; min-width: 0; display: grid; }
.file-name b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-name .sub { font-size: 12px; }
.reading { text-align: center; padding: 18px 0 26px; display: grid; gap: 10px; justify-items: center; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.steps-list { list-style: none; padding: 0; margin: 4px 0; display: grid; gap: 8px; text-align: left; }
.steps-list li { color: var(--muted); font-size: 15px; padding-left: 28px; position: relative; }
.steps-list li::before { content: "○"; position: absolute; left: 4px; }
.steps-list li.now { color: var(--text); font-weight: 600; }
.steps-list li.now::before { content: "◌"; color: var(--accent); animation: spin 1.2s linear infinite; display: inline-block; }
.steps-list li.done { color: var(--accent); }
.steps-list li.done::before { content: "✓"; }

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