/* Calorias Perneco — telemóvel primeiro, claro e escuro conforme o sistema. */

:root {
  --accent: #00897b;
  --accent-strong: #00695c;
  --accent-soft: #e0f2f1;
  --bg: #f3f7f6;
  --surface: #ffffff;
  --border: #dde7e5;
  --text: #15201e;
  --muted: #5f6f6c;
  --warn: #ef6c00;
  --warn-soft: #fff3e0;
  --track: #e3ebe9;
  --danger: #d32f2f;
  --danger-soft: #fdecea;
  --ok: #2e7d32;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(27 24 48 / 6%), 0 6px 18px rgb(27 24 48 / 6%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #4db6ac;
    --accent-strong: #80cbc4;
    --accent-soft: #15302d;
    --bg: #0e1413;
    --surface: #17201f;
    --border: #263331;
    --text: #e6efed;
    --muted: #93a5a2;
    --warn: #ffb74d;
    --warn-soft: #3a2a14;
    --track: #263331;
    --danger: #ef6c6c;
    --danger-soft: #3a1d22;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 18px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body.no-scroll { overflow: hidden; }

button, input, select, textarea { font: inherit; color: inherit; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ───────────────────────────────────────────────────────────── entrada ── */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.login__card {
  width: 100%;
  max-width: 380px;
  padding: 32px 24px;
  text-align: center;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.login__logo { font-size: 56px; }
.login__card h1 { margin: 8px 0; font-size: 1.5rem; }
.login__button { display: flex; justify-content: center; margin-top: 20px; min-height: 44px; }

.alert {
  margin: 16px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  text-align: left;
}

.alert--error { background: var(--danger-soft); color: var(--danger); }

/* ───────────────────────────────────────────────────────────── aplicação ── */

.app {
  min-height: 100dvh;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--accent);
  color: #fff;
}

.topbar__title { flex: 1; margin: 0; font-size: 1.25rem; font-weight: 600; }

.icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  font-size: 1.3rem;
  cursor: pointer;
}

.icon-btn:active { background: rgb(255 255 255 / 15%); }

.sync--spinning { animation: spin 1s linear infinite; }
.sync--pending::after {
  content: "";
  position: relative;
  top: -12px;
  left: -2px;
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffca28;
}

@keyframes spin { to { transform: rotate(360deg); } }

.avatar {
  width: 36px;
  height: 36px;
  padding: 0;
  overflow: hidden;
  border: 2px solid rgb(255 255 255 / 60%);
  border-radius: 50%;
  background: var(--accent-strong);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.avatar img { width: 100%; height: 100%; object-fit: cover; }

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #fff3cd;
  color: #5d4300;
  font-size: 0.9rem;
}

@media (prefers-color-scheme: dark) {
  .banner { background: #3d3214; color: #ffe08a; }
}

/* Listas (filtros) */
.filters {
  display: flex;
  gap: 8px;
  padding: 12px 16px 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.filters::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.875rem;
  white-space: nowrap;
  cursor: pointer;
}

.chip--active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip__count { opacity: 0.7; font-size: 0.8rem; }

.content { padding: 0 16px; max-width: 720px; margin: 0 auto; }

.group {
  margin: 18px 4px 8px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.group--late { color: var(--danger); }

.todo {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.todo__check {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  margin-top: 1px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: transparent;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.todo--done .todo__check { background: var(--accent); }
.todo--done .todo__title { color: var(--muted); text-decoration: line-through; }

.todo--pending { opacity: 0.75; }
.todo--pending .todo__check { border: 0; font-size: 1.1rem; }

.todo__main {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}

.todo__title { font-weight: 500; line-height: 1.35; overflow-wrap: anywhere; }

.todo__notes {
  color: var(--muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.todo__meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: 0.8rem; color: var(--muted); }

.tag {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.tag--late { background: var(--danger-soft); color: var(--danger); }
.tag--high { background: var(--danger-soft); color: var(--danger); font-weight: 600; }
.tag--low { background: transparent; color: var(--muted); border: 1px solid var(--border); }

.empty { padding: 48px 16px; text-align: center; }
.empty__icon { font-size: 48px; }
.empty p { margin: 6px 0; }

.footnote { margin: 20px 0; text-align: center; font-size: 0.8rem; }

/* Barra de baixo: escrever ou ditar */
.addbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
}

.addbar input {
  flex: 1;
  min-width: 0;
  height: 48px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface);
  font-size: 1rem;
}

.addbar input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.mic,
.addbar__send {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  margin-top: -16px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 1.7rem;
  box-shadow: 0 4px 14px rgb(0 137 123 / 45%);
  cursor: pointer;
}

.addbar__send { width: 48px; height: 48px; margin-top: 0; font-size: 1.2rem; }
.mic:active, .addbar__send:active { transform: scale(0.95); }

/* ───────────────────────────────────────────────────────────── a ouvir ── */

.listen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 24px 24px calc(24px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--accent-strong) 94%, black);
  color: #fff;
  text-align: center;
}

.listen__hint { margin: 0; font-size: 1.05rem; opacity: 0.85; }

.listen__text {
  min-height: 4.5em;
  max-width: 560px;
  margin: 0;
  font-size: 1.45rem;
  font-weight: 500;
  line-height: 1.4;
}

.listen__mic {
  width: 112px;
  height: 112px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: var(--accent-strong);
  font-size: 3rem;
  cursor: pointer;
}

.listen--active .listen__mic { animation: pulse 1.4s ease-out infinite; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgb(255 255 255 / 55%); }
  100% { box-shadow: 0 0 0 36px rgb(255 255 255 / 0%); }
}

.listen__help { max-width: 420px; margin: 0; font-size: 0.85rem; color: rgb(255 255 255 / 70%); }

.listen__cancel {
  padding: 10px 24px;
  border: 1px solid rgb(255 255 255 / 50%);
  border-radius: 999px;
  background: transparent;
  color: #fff;
  cursor: pointer;
}

/* ─────────────────────────────────────────────────────────── folha modal ── */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgb(0 0 0 / 45%);
}

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-radius: 20px 20px 0 0;
}

.sheet__title { margin: 0 0 12px; font-size: 1.15rem; }
.sheet__body { display: grid; gap: 14px; }

.sheet__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.field { display: grid; gap: 6px; font-size: 0.85rem; color: var(--muted); min-width: 0; }

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  resize: vertical;
}

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; }

.btn {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
}

.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--danger { color: var(--danger); margin-right: auto; }
.btn:disabled { opacity: 0.6; }

.facts { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.sheet a { color: var(--accent); }

/* ──────────────────────────────────────────────────────────────── avisos ── */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + env(safe-area-inset-bottom));
  z-index: 60;
  width: max-content;
  max-width: calc(100% - 32px);
  transform: translateX(-50%);
  padding: 12px 16px;
  border-radius: 12px;
  background: #1f2d2b;
  color: #fff;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
}

.toast__action {
  margin-left: 8px;
  padding: 4px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #b2dfdb;
  font-weight: 700;
  cursor: pointer;
}

.install-btn {
  position: fixed;
  right: 16px;
  bottom: calc(100px + env(safe-area-inset-bottom));
  z-index: 30;
  padding: 10px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow);
  cursor: pointer;
}

/* ───────────────────────────────────────────────────────────── calorias ── */

.daynav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 16px 0;
  position: relative;
}

.daynav__arrow {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--accent);
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
}

.daynav__arrow:disabled { opacity: 0.25; cursor: default; }

.daynav__label {
  min-width: 180px;
  padding: 8px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-weight: 600;
  text-transform: capitalize;
  cursor: pointer;
}

/* O seletor de datas fica escondido por baixo da etiqueta. */
.daynav__picker {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.summary {
  margin-top: 14px;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.summary__top {
  display: flex;
  align-items: center;
  gap: 18px;
}

.ring { position: relative; width: 120px; height: 120px; flex-shrink: 0; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring__track { fill: none; stroke: var(--track); stroke-width: 10; }
.ring__value { fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset 0.4s; }
.ring--over .ring__value { stroke: var(--warn); }

.ring__center {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
}

.ring__big { font-size: 1.6rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.ring__small { font-size: 0.75rem; color: var(--muted); }

.summary__facts { flex: 1; display: grid; gap: 6px; font-size: 0.9rem; min-width: 0; }
.summary__facts strong { font-variant-numeric: tabular-nums; }
.summary__over { color: var(--warn); font-weight: 600; }

.macros {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.macro { display: grid; gap: 4px; font-size: 0.78rem; color: var(--muted); }
.macro strong { color: var(--text); font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.macro__bar { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.macro__bar span { display: block; height: 100%; border-radius: 3px; }

.week {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  align-items: end;
  gap: 6px;
  height: 72px;
  margin-top: 16px;
  border-top: 1px solid var(--border);
}

.week__day {
  display: flex;
  align-items: flex-end;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.week__bar {
  width: 100%;
  min-height: 3px;
  border-radius: 4px 4px 2px 2px;
  background: color-mix(in srgb, var(--accent) 45%, transparent);
}

.week__day--over .week__bar { background: color-mix(in srgb, var(--warn) 60%, transparent); }
.week__day--current .week__bar { background: var(--accent); }
.week__day--current.week__day--over .week__bar { background: var(--warn); }

.week__labels {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-top: 4px;
  text-align: center;
}

.week__label { font-size: 0.7rem; color: var(--muted); text-transform: capitalize; }
.week__label--current { color: var(--text); font-weight: 700; }

/* Linha do objetivo por cima das barras. */
.week__goal {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px dashed var(--muted);
  opacity: 0.6;
  pointer-events: none;
}

.week__note { margin: 8px 0 0; font-size: 0.78rem; color: var(--muted); text-align: center; }

.meal { margin-top: 18px; }

.meal__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0 4px 8px;
}

.meal__title {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.meal__total { font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.food {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin-bottom: 8px;
  padding: 12px 14px;
  border: 0;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: left;
  cursor: pointer;
}

.food__main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.food__name { font-weight: 500; line-height: 1.3; overflow-wrap: anywhere; }
.food__meta { font-size: 0.8rem; color: var(--muted); }

.food__kcal {
  flex-shrink: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.food__kcal small { font-weight: 400; color: var(--muted); }
.food__kcal--unknown { color: var(--warn); }
.food--pending { opacity: 0.7; cursor: default; }

.meal__add {
  display: block;
  margin: 0 4px;
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 0.85rem;
  cursor: pointer;
}

.recent { display: flex; flex-wrap: wrap; gap: 6px; }
.recent .chip small { color: var(--muted); }

.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.addbar__plus {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--accent);
  font-size: 1.4rem;
  cursor: pointer;
}

.ai-note { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 0.85rem; }

/* No escuro o verde-azulado do tema é claro demais para letra branca. */
@media (prefers-color-scheme: dark) {
  .topbar { background: #00695c; }
  .mic, .addbar__send, .btn--primary, .chip--active { background: #00897b; border-color: #00897b; }
}
