:root {
  --navy: #05244c;
  --navy-2: #0b3566;
  --red: #e5202a;
  --bg: #f2f3f5;
  --card: #ffffff;
  --ink: #0f1b2d;
  --muted: #5b6678;
  --line: #dde1e8;
  --ok: #1c8a4a;
  --warn: #b36b00;
  --radius: 14px;
  --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1424;
    --card: #12213a;
    --ink: #eaf0fb;
    --muted: #9fb0c9;
    --line: #243553;
    --ok: #52c98a;
    --warn: #f0b04a;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body.noscroll { overflow: hidden; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* estrutura */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--navy); color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex; align-items: center; gap: 10px;
}
.brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; font-weight: 700; font-size: 13px; line-height: 1.15; letter-spacing: .02em; }
.brand span { min-width: 0; }
.mark {
  width: 34px; height: 34px; border-radius: 50%;
  background: #fff; color: var(--red);
  display: grid; place-items: center;
  border: 2px solid var(--red);
  object-fit: cover; overflow: hidden;
}
.topbar .icon { background: transparent; border: 0; color: #fff; padding: 8px; border-radius: 8px; }
main { padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; }
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--navy);
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
}
.nav button {
  background: transparent; border: 0; color: #b9c8e0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .78rem; font-weight: 600;
}
.nav button .ico { font-size: 1.3rem; line-height: 1; }
.nav button[aria-current="page"] { color: #fff; box-shadow: inset 0 3px 0 var(--red); }

/* componentes */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 14px; }
.page-head h1 { font-size: 1.35rem; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.card h2 { font-size: 1rem; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.row {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.row:first-of-type { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow-wrap: anywhere; }
.btn {
  background: var(--navy); color: #fff; border: 0; border-radius: 10px;
  padding: 10px 14px; font-weight: 600; min-height: 44px;
}
.btn.red { background: var(--red); }
.btn.ghost { background: transparent; color: var(--navy); border: 1px solid var(--line); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.ghost { color: var(--ink); } }
.btn.sm { padding: 6px 10px; min-height: 36px; font-size: .88rem; }
.btn[disabled] { opacity: .55; }
.badge {
  display: inline-block; font-size: .74rem; font-weight: 700; padding: 2px 8px;
  border-radius: 999px; background: var(--line); color: var(--ink);
}
.badge.red { background: var(--red); color: #fff; }
.badge.navy { background: var(--navy); color: #fff; }
.badge.ok { background: var(--ok); color: #fff; }
.badge.warn { background: var(--warn); color: #fff; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 10px; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 6px 14px; font-weight: 600; font-size: .9rem;
}
.chip[aria-pressed="true"] { background: var(--navy); color: #fff; border-color: var(--navy); }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--red); }
.bar.done > i { background: var(--ok); }
.goal { margin-bottom: 12px; }
.goal:last-child { margin-bottom: 0; }
.goal .top { display: flex; justify-content: space-between; font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 18px 8px; }
.error { border-color: var(--red); }
.alert { color: var(--red); font-weight: 700; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* formulários */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--card); min-height: 44px;
}
.field textarea { min-height: 76px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 14px 0 8px; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: var(--navy); }
.login .box { background: var(--card); border-radius: 18px; padding: 24px; width: 100%; max-width: 380px; }
.login .mark { margin: 0 auto 12px; width: 56px; height: 56px; font-size: 34px; }
.login h1 { text-align: center; font-size: 1.3rem; margin-bottom: 4px; }
.login p { text-align: center; margin: 0 0 18px; }
.linkbtn { background: none; border: 0; color: var(--red); font-weight: 600; padding: 8px 0; }

/* sheet (formulário em painel) */
#sheet .backdrop { position: fixed; inset: 0; background: rgba(5, 20, 40, .55); z-index: 20; }
#sheet .panel {
  position: fixed; z-index: 21; left: 0; right: 0; bottom: 0; max-height: 92dvh;
  background: var(--card); border-radius: 18px 18px 0 0; display: flex; flex-direction: column;
  max-width: 760px; margin: 0 auto;
}
#sheet .panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
#sheet .panel-head h2 { font-size: 1.1rem; }
#sheet .panel-head .icon { background: transparent; border: 0; font-size: 1.1rem; padding: 6px 10px; }
#sheet .panel-body { overflow-y: auto; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 30; background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-weight: 600; max-width: 90vw;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
#toast.show { opacity: 1; }

.grupo { padding: 0 14px; }
.grupo summary { cursor: pointer; padding: 14px 0; display: flex; justify-content: space-between; align-items: center; list-style: none; }
.grupo summary::-webkit-details-marker { display: none; }
.grupo summary::after { content: '▾'; color: var(--muted); margin-left: 8px; }
.grupo[open] summary::after { content: '▴'; }
