:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #15171c;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #10b981;
  --accent-ink: #ffffff;
  --kcal: #f59e0b;
  --protein: #ef4444;
  --carbs: #3b82f6;
  --fat: #a855f7;
  --water: #06b6d4;
  --over: #dc2626;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #1a1d23;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --line: #2a2e36;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
main { padding: 0 16px; max-width: 640px; margin: 0 auto; }
h2 { font-size: 17px; margin: 0; }
.muted { color: var(--muted); font-size: 14px; }
.section-title { margin: 24px 4px 8px; font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

button, .button-like {
  font: inherit; font-size: 15px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 9px 12px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button:active, .button-like:active { transform: scale(.97); }
button.accent { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 4px 8px; }
button:disabled { opacity: .5; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btn-row > * { flex: 1 1 auto; }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px; background: var(--bg);
}
.icon-btn { font-size: 26px; width: 44px; height: 44px; padding: 0; border-radius: 50%; }
.day { text-align: center; }
.day-label { font-weight: 700; font-size: 18px; }
.day-date { color: var(--muted); font-size: 13px; }

.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin: 12px 0; border: 1px solid var(--line); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }

.summary { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 4px; }
.ring { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.ring-circle {
  --p: 0; --c: var(--accent);
  width: 100%; max-width: 66px; aspect-ratio: 1; border-radius: 50%;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--line) 0);
  display: grid; place-items: center;
}
.ring-circle > span {
  width: 76%; aspect-ratio: 1; border-radius: 50%; background: var(--bg); display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
}
.ring-label { font-size: 12px; color: var(--muted); }
.ring-val { font-size: 11px; color: var(--muted); text-align: center; line-height: 1.2; }
.ring.over .ring-circle > span { color: var(--over); }

.water-bar { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 10px; }
#waterFill { height: 100%; width: 0; background: var(--water); transition: width .3s; }

.meal-planned { font-size: 13px; color: var(--muted); margin-top: 4px; }
.macro-line { display: flex; gap: 10px; font-size: 13px; margin-top: 8px; flex-wrap: wrap; }
.macro-line b { font-weight: 600; }
.k { color: var(--kcal); } .p { color: var(--protein); } .c { color: var(--carbs); } .f { color: var(--fat); }
.meal-status { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--muted); white-space: nowrap; }
.meal-status.done { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }

.entry-list { list-style: none; padding: 0; margin: 8px 0 0; }
.entry-list li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.entry-list img { width: 40px; height: 40px; object-fit: cover; border-radius: 8px; flex: none; }
.entry-list .grow { flex: 1; min-width: 0; }
.entry-list .sub { color: var(--muted); font-size: 12px; }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); z-index: 10;
}
.tabs button { flex: 1; border: 0; border-radius: 0; background: transparent; padding: 14px 0; color: var(--muted); font-weight: 600; }
.tabs button.active { color: var(--accent); }

dialog {
  border: 0; border-radius: 20px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: 88vh;
  background: var(--card); color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.5); }
#modalBody { padding: 16px; }
.modal-photo { width: 100%; max-height: 220px; object-fit: cover; border-radius: 12px; }
.items-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 10px; }
.items-table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 4px 2px; }
.items-table td { padding: 3px 2px; }
.items-table input { width: 100%; font: inherit; font-size: 14px; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); }
.items-table td.num input { text-align: right; }
.items-table .name-row td { padding-top: 10px; }
.notice { font-size: 13px; padding: 10px; border-radius: 10px; background: var(--bg); margin-top: 10px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin: 24px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 14px; }
.field span { color: var(--muted); font-size: 13px; }
.field input, .field textarea, .field select {
  font: inherit; padding: 9px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); width: 100%;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.form-grid .full { grid-column: 1 / -1; }

.hist-row { display: grid; grid-template-columns: 74px repeat(5, 1fr); gap: 4px; align-items: center; font-size: 13px; padding: 8px 0; border-top: 1px solid var(--line); }
.hist-row.head { color: var(--muted); font-size: 12px; border-top: 0; }
.pct { text-align: center; border-radius: 8px; padding: 4px 0; font-weight: 600; }
.pct.lo { background: color-mix(in srgb, var(--over) 18%, transparent); }
.pct.mid { background: color-mix(in srgb, var(--kcal) 22%, transparent); }
.pct.ok { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.pct.none { color: var(--muted); font-weight: 400; }

[hidden] { display: none !important; }
button.link { padding: 0; color: var(--text); font-weight: 600; font-size: 13px; text-decoration: underline dotted; }

.bio-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.bio-table th, .bio-table td { padding: 6px 4px; border-top: 1px solid var(--line); text-align: right; }
.bio-table thead th { border-top: 0; color: var(--muted); font-weight: 600; }
.bio-table tbody th { text-align: left; font-weight: 500; }
.bio-table td.delta { font-weight: 600; color: var(--muted); }
.bio-table td.delta.good { color: var(--accent); }
.bio-table td.delta.bad { color: var(--over); }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-grid > div { display: flex; flex-direction: column; background: var(--bg); border-radius: 12px; padding: 10px; }
.stat-grid b { font-size: 17px; }
.chart-block + .chart-block { margin-top: 14px; }

.compare-selects { display: flex; align-items: center; gap: 8px; margin: 12px 0; }
.compare-selects select { flex: 1; font: inherit; font-size: 14px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); }
.compare-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 4px 0 12px; }
.compare-row img, .ph-empty { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 12px; }
.ph-empty { display: grid; place-items: center; background: var(--bg); color: var(--muted); font-size: 13px; }

/* filtros de período */
.top { flex-wrap: wrap; row-gap: 8px; }
.segmented { order: 3; flex: 1 0 100%; display: flex; background: var(--line); border-radius: 10px; padding: 2px; }
.segmented button { flex: 1; border: 0; background: transparent; padding: 6px 0; font-size: 14px; border-radius: 8px; color: var(--muted); }
.segmented button.active { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }

/* resumo */
.center { text-align: center; }
.score-card { display: flex; gap: 16px; align-items: center; }
.score {
  --p: 0; flex: none; width: 92px; height: 92px; border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--line) 0); display: grid; place-items: center;
}
.score > span { width: 74px; height: 74px; border-radius: 50%; background: var(--card); display: grid; place-items: center; font-size: 22px; font-weight: 800; }
.goal-chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; margin: 8px 0; }
.goal-chip { display: flex; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.goal-chip b { margin-left: auto; }
.goal-chip .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.delta { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.delta.good { color: var(--accent); }
.delta.bad { color: var(--over); }
.sub-title { font-size: 14px; margin: 14px 0 0; color: var(--muted); }
.meal-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 6px; }
.meal-table th { text-align: left; font-weight: 500; padding: 6px 0; }
.meal-table td { padding: 6px 4px; white-space: nowrap; color: var(--muted); }
.meal-table td:last-child { width: 30%; }
.mini-bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.mini-bar > div { height: 100%; background: var(--accent); }
.hist-row[data-goto] { cursor: pointer; }
.card.stat-grid { display: grid; }

/* abas com ícone */
.tabs button { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; padding: 8px 0 10px; }
.tabs button span { font-size: 19px; line-height: 1; filter: grayscale(1); opacity: .6; }
.tabs button.active span { filter: none; opacity: 1; }

/* água & sono */
.head-actions { display: flex; align-items: center; gap: 4px; font-size: 12px; text-align: right; }
.big-num { margin-top: 6px; }
.big-num b { font-size: 26px; }
.water-bar > div { height: 100%; background: var(--water); transition: width .3s; }
.split3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.split3 > div { background: var(--bg); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; font-size: 13px; }
.emoji-icon { width: 40px; text-align: center; font-size: 22px; flex: none; }
.sleep-top { display: flex; gap: 14px; align-items: center; margin: 6px 0 12px; }
.sleep-top .ring-circle { flex: none; width: 84px; }
.stage-bar { display: flex; height: 14px; border-radius: 99px; overflow: hidden; gap: 2px; margin-top: 8px; }
.stage-legend { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; font-size: 13px; margin-top: 8px; }
.stage-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }
button.preset { flex: 1 1 0; padding: 8px 4px; font-size: 13px; }

/* gravação de áudio */
.rec-indicator { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 28px; font-weight: 700; margin: 24px 0; font-variant-numeric: tabular-nums; }
.rec-dot { width: 16px; height: 16px; border-radius: 50%; background: var(--over); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; transform: scale(.8); } }

/* assistente */
.fab {
  position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 11;
  width: 54px; height: 54px; border-radius: 50%; font-size: 26px; padding: 0;
  background: var(--accent); border: 0; box-shadow: 0 6px 18px rgba(0,0,0,.25);
}
dialog.sheet { width: 100vw; max-width: 640px; height: 92vh; max-height: 92vh; margin: auto auto 0; border-radius: 20px 20px 0 0; }
dialog.sheet #modalBody { height: 100%; display: flex; flex-direction: column; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
.chat-head { display: flex; justify-content: space-between; align-items: center; }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 10px 0; }
.msg { max-width: 86%; padding: 9px 12px; border-radius: 16px; font-size: 15px; line-height: 1.45; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--bg); border-bottom-left-radius: 4px; }
.msg.typing { color: var(--muted); font-style: italic; }
.chat-input { display: flex; gap: 6px; align-items: flex-end; }
.chat-input textarea { flex: 1; font: inherit; padding: 10px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); color: var(--text); resize: none; max-height: 120px; }
.chat-input button { height: 44px; min-width: 44px; padding: 0 10px; }
