:root {
  --bg: #f4f5f2;
  --card: #ffffff;
  --text: #17201b;
  --muted: #5d6b63;
  --line: #e2e6e1;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --green-text: #14532d;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --red-text: #7f1d1d;
  --empty: #eef0ec;
  --accent: #16a34a;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1411;
    --card: #182019;
    --text: #eef3ef;
    --muted: #9aa8a0;
    --line: #26302a;
    --green: #22c55e;
    --green-soft: #14341f;
    --green-text: #bbf7d0;
    --red: #ef4444;
    --red-soft: #3a1717;
    --red-text: #fecaca;
    --empty: #212a24;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.wrap { max-width: 560px; margin: 0 auto; padding: 0 16px 40px; }

/* Topo */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  display: flex; align-items: center; gap: 8px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 10px;
  max-width: 560px; margin: 0 auto;
}
.top h1 { font-size: 22px; margin: 0; flex: 1; letter-spacing: -.01em; }
.icon-btn {
  border: 0; background: var(--card); box-shadow: var(--shadow);
  width: 44px; height: 44px; border-radius: 12px; font-size: 20px;
  display: grid; place-items: center;
}

/* Cartões */
.card {
  background: var(--card); border-radius: 18px; padding: 16px;
  box-shadow: var(--shadow); margin-bottom: 12px;
  border: 1px solid var(--line);
}
.goal-card { display: block; text-decoration: none; color: inherit; }
.goal-head { display: flex; align-items: center; gap: 12px; }
.goal-emoji {
  width: 48px; height: 48px; border-radius: 14px; background: var(--empty);
  display: grid; place-items: center; font-size: 26px; flex-shrink: 0;
}
.goal-name { font-weight: 700; font-size: 19px; }
.goal-sub { color: var(--muted); font-size: 15px; }
.big-count { font-size: 28px; font-weight: 800; margin-left: auto; white-space: nowrap; }
.big-count small { font-size: 16px; color: var(--muted); font-weight: 600; }

.bar { height: 12px; background: var(--empty); border-radius: 99px; overflow: hidden; margin: 14px 0 8px; }
.bar > span { display: block; height: 100%; background: var(--green); border-radius: 99px; transition: width .3s; }

.today-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.today-row .label { font-size: 15px; color: var(--muted); margin-right: auto; }

.btn {
  border: 0; border-radius: 14px; padding: 14px 18px; font-weight: 700;
  background: var(--empty); min-height: 48px;
}
.btn-sm { padding: 10px 14px; min-height: 44px; font-size: 16px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-yes { background: var(--green-soft); color: var(--green-text); }
.btn-no { background: var(--red-soft); color: var(--red-text); }
.btn-yes.on { background: var(--green); color: #fff; }
.btn-no.on { background: var(--red); color: #fff; }
.btn-danger { background: transparent; color: var(--red); border: 2px solid var(--red-soft); }
.btn-block { width: 100%; }

.notice {
  background: #fef9c3; color: #713f12; border-radius: 16px; padding: 14px 16px;
  margin-bottom: 14px; font-size: 16px;
}
@media (prefers-color-scheme: dark) { .notice { background: #3b3410; color: #fef08a; } }
.notice b { display: block; margin-bottom: 8px; }

.empty-state { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty-state .e { font-size: 54px; }

/* Abas */
.tabs { display: flex; background: var(--empty); border-radius: 14px; padding: 4px; margin: 4px 0 14px; }
.tabs button {
  flex: 1; border: 0; background: transparent; padding: 11px; border-radius: 11px;
  font-weight: 700; color: var(--muted);
}
.tabs button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* Resumo do mês */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 6px; text-align: center; }
.stat b { display: block; font-size: 24px; line-height: 1.1; }
.stat span { font-size: 12px; color: var(--muted); white-space: nowrap; }
.stat.g b { color: var(--green); }
.stat.r b { color: var(--red); }

.status-msg { font-weight: 600; text-align: center; margin: 4px 0 14px; }

/* Calendário */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.month-nav h2 { font-size: 20px; margin: 0; text-transform: capitalize; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal .wd { text-align: center; font-size: 13px; color: var(--muted); font-weight: 700; padding-bottom: 2px; }
.day {
  aspect-ratio: 1; border: 0; border-radius: 12px; background: var(--empty);
  font-weight: 700; font-size: 16px; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
}
.day .mk { font-size: 14px; line-height: 1; }
.day.done { background: var(--green); color: #fff; }
.day.missed { background: var(--red-soft); color: var(--red-text); }
.day.today { outline: 3px solid var(--text); outline-offset: -3px; }
.day.future { opacity: .35; cursor: default; }
.day.blank { background: transparent; }
.legend { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; font-size: 14px; color: var(--muted); margin-top: 12px; }
.legend i { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: 4px; }
.hint { text-align: center; font-size: 14px; color: var(--muted); margin-top: 8px; }

/* Histórico */
.hist-row { display: grid; grid-template-columns: 74px 1fr 82px; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.hist-row:last-child { border-bottom: 0; }
.hist-row .m { font-weight: 700; font-size: 15px; text-transform: capitalize; }
.hist-row .bar { margin: 0; height: 14px; }
.hist-row .v { text-align: right; font-size: 15px; font-weight: 700; }
.hist-row .v small { display: block; font-weight: 500; color: var(--muted); font-size: 13px; }
.hist-row.hit .bar > span { background: var(--green); }
.hist-row.miss .bar > span { background: #f59e0b; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.kpi b { display: block; font-size: 26px; }
.kpi span { color: var(--muted); font-size: 14px; }
.section-title { font-size: 17px; margin: 18px 0 8px; }

/* Formulário */
.field { margin-bottom: 18px; }
.field > label { display: block; font-weight: 700; margin-bottom: 8px; }
.field .help { font-size: 14px; color: var(--muted); margin-top: 6px; }
.input {
  width: 100%; border: 2px solid var(--line); background: var(--card);
  border-radius: 14px; padding: 13px 14px; min-height: 52px; font-size: 18px;
}
.input:focus { outline: none; border-color: var(--accent); }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button { width: 56px; height: 56px; border-radius: 14px; border: 0; background: var(--empty); font-size: 26px; font-weight: 700; }
.stepper output { flex: 1; text-align: center; font-size: 30px; font-weight: 800; }
.emojis { display: flex; flex-wrap: wrap; gap: 8px; }
.emojis button { width: 50px; height: 50px; border-radius: 12px; border: 2px solid transparent; background: var(--empty); font-size: 26px; }
.emojis button.on { border-color: var(--accent); background: var(--green-soft); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch { position: relative; width: 58px; height: 34px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; transition: .2s; }
.switch span::before { content: ""; position: absolute; width: 28px; height: 28px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(24px); }
.actions { display: grid; gap: 10px; margin-top: 24px; }
.hora-row { display: flex; align-items: center; gap: 8px; }
.hora-row select { flex: 1; font-size: 22px; font-weight: 700; text-align: center; appearance: none; -webkit-appearance: none; }
.hora-row span { font-size: 26px; font-weight: 800; }

.login { min-height: 80vh; display: flex; flex-direction: column; justify-content: center; }
.login .logo { font-size: 60px; text-align: center; }
.login h1 { text-align: center; margin: 6px 0 4px; }
.login p { text-align: center; color: var(--muted); margin: 0 0 22px; }
.err { color: var(--red); font-weight: 600; margin-top: 8px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px;
  font-weight: 600; z-index: 50; max-width: calc(100% - 32px); text-align: center;
}
