:root {
  color-scheme: light;
  --bg: #fbf8f2;
  --surface: #ffffff;
  --surface-2: #f3eee4;
  --text: #2f3136;
  --muted: #6d6a62;
  --line: #e8e1d4;
  --primary: #4a6178;
  --primary-text: #ffffff;
  --accent-soft: #edf1f5;
  --gold: #a98a4f;
  --ok: #3f6b52;
  --ok-soft: #e9f2ec;
  --warn: #85622a;
  --warn-soft: #f8f0df;
  --danger: #9c4141;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
.topo h1, .folha-topo h2, dialog h2 { font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif; font-weight: 600; letter-spacing: .005em; }
.topo { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.estado-ok { color: var(--ok); font-weight: 600; }
.estado-aberto { color: var(--warn); font-weight: 600; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; opacity: .35; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 16px) 16px calc(var(--safe-b) + 92px);
}
body.sem-nav #app { padding-bottom: calc(var(--safe-b) + 32px); }

.topo { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; min-height: 44px; }
.topo h1 { font-size: 22px; line-height: 1.2; }
.topo .sub { color: var(--muted); font-size: 14px; }
.topo .cresce { flex: 1; min-width: 0; }
.icone-btn {
  width: 44px; height: 44px; flex: none; border: 0; border-radius: 12px;
  background: var(--surface-2); font-size: 20px; line-height: 1;
}

.cartao { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 12px; }
.cartao h2, .secao { font-size: 12px; font-weight: 700; color: var(--gold); letter-spacing: .08em; text-transform: uppercase; }
.cartao h2 { margin-bottom: 10px; }
.secao { margin: 20px 2px 8px; }
.texto-fraco { color: var(--muted); font-size: 14px; }
.pilha > * + * { margin-top: 10px; }

.btn {
  display: block; width: 100%; min-height: 48px; padding: 10px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600; text-align: center;
}
.btn.primario { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.grande { min-height: 60px; font-size: 18px; }
.btn.perigo { color: var(--danger); }
.btn.aviso { color: var(--warn); background: var(--warn-soft); border-color: transparent; }

.aviso-caixa { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 12px 14px; font-size: 14px; margin-bottom: 12px; }
.ok-caixa { background: var(--ok-soft); color: var(--ok); border-radius: 12px; padding: 12px 14px; font-size: 14px; margin-bottom: 12px; }

.campo { display: block; }
.campo > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.campo input, .campo select, .campo textarea, .entrada {
  width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); font-size: 16px;
}
textarea { resize: vertical; }

.opcoes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.opcao {
  min-height: 52px; padding: 8px 10px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-size: 15px; font-weight: 600;
}
.opcao[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.opcao.largo { grid-column: 1 / -1; }

.item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; text-align: left; margin-bottom: 8px;
}
.item .corpo { flex: 1; min-width: 0; }
.item .nome { font-weight: 600; display: block; }
.item .dica { font-size: 13px; color: var(--muted); display: block; overflow-wrap: anywhere; }
.num {
  flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); color: var(--muted); font-size: 13px; font-weight: 700;
}
.item.tocado .num { background: var(--ok-soft); color: var(--ok); }
.item.suprimido .num { background: var(--warn-soft); color: var(--warn); }
.valor { flex: none; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.valor.vazio { color: var(--muted); font-weight: 400; }
.valor.sup { font-size: 13px; color: var(--warn); background: var(--warn-soft); padding: 4px 8px; border-radius: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 36px; padding: 4px 10px; border: 0; border-radius: 9px; background: var(--accent-soft);
  font-weight: 700; font-variant-numeric: tabular-nums;
}
.chip.com-obs::after { content: " •"; color: var(--warn); }

details.ajuste { margin-bottom: 12px; }
details.ajuste summary { color: var(--muted); font-size: 14px; padding: 8px 2px; cursor: pointer; }

.resumo { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.resumo div { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px; text-align: center; }
.resumo b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.resumo span { font-size: 12px; color: var(--muted); }

.modo {
  position: sticky; top: calc(var(--safe-t) + 6px); z-index: 5; display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  padding: 4px; margin-bottom: 12px; background: var(--surface-2); border-radius: 12px; box-shadow: 0 2px 8px rgb(0 0 0 / .14);
}
.modo button { min-height: 44px; border: 0; border-radius: 9px; background: transparent; font-weight: 700; }
.modo button[aria-pressed="true"] { background: var(--primary); color: var(--primary-text); }

.contador { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.cartao .contador:first-of-type { border-top: 0; }
.contador .rotulo { flex: 1; min-width: 0; }
.contador .rotulo b { display: block; font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.contador .rotulo small { color: var(--muted); font-size: 12px; }
.passo { display: flex; align-items: center; flex: none; }
.passo button { width: 44px; height: 44px; border: 0; border-radius: 10px; background: var(--surface-2); font-size: 22px; font-weight: 600; }
.passo input { width: 46px; height: 44px; border: 0; background: transparent; text-align: center; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; padding: 0; }
.remover { width: 32px; height: 44px; flex: none; border: 0; background: transparent; color: var(--danger); font-size: 18px; }
.linha-add { display: flex; gap: 8px; margin-top: 10px; }
.linha-add .btn { width: auto; flex: none; }

#nav {
  position: fixed; inset: auto 0 0 0; z-index: 10; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
body.sem-nav #nav { display: none; }
#nav button {
  min-height: 60px; border: 0; background: transparent; color: var(--muted); font-size: 12px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; position: relative;
}
#nav button[aria-current="page"] { color: var(--primary); }
#nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.selo {
  position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--warn); color: var(--surface); font-size: 11px; line-height: 18px;
}

.fundo { position: fixed; inset: 0; z-index: 20; background: rgb(60 55 45 / .28); display: flex; align-items: flex-end; justify-content: center; }
.folha {
  width: 100%; max-width: 560px; max-height: 100dvh; overflow-y: auto; background: var(--surface);
  border-radius: 18px 18px 0 0; padding: 12px 16px calc(var(--safe-b) + 14px);
}
.folha-topo { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.folha-topo h2 { flex: 1; font-size: 18px; line-height: 1.2; }
.folha-topo small { display: block; font-size: 13px; font-weight: 400; color: var(--muted); }
.visor {
  height: 58px; display: grid; place-items: center; font-size: 38px; font-weight: 800; border-radius: 12px;
  background: var(--surface-2); font-variant-numeric: tabular-nums; margin-bottom: 8px;
}
.visor.vazio { color: var(--muted); font-size: 16px; font-weight: 400; }
.teclado { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.teclado button { height: 52px; border: 0; border-radius: 11px; background: var(--surface-2); font-size: 23px; font-weight: 700; }
.teclado button[aria-pressed="true"] { background: var(--primary); color: var(--primary-text); }
.folha .chips { margin-bottom: 8px; }
.acoes { display: grid; grid-template-columns: 1fr 1.6fr; gap: 8px; }
.link-btn { display: block; width: 100%; min-height: 40px; border: 0; background: transparent; color: var(--muted); font-size: 14px; font-weight: 600; }
.folha textarea { width: 100%; min-height: 64px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); margin-bottom: 8px; font-size: 16px; }

dialog { border: 0; border-radius: 16px; padding: 20px; width: min(340px, calc(100vw - 32px)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgb(60 55 45 / .35); }
dialog h2 { font-size: 18px; margin-bottom: 6px; }
dialog p { color: var(--muted); font-size: 15px; margin-bottom: 16px; }
dialog .acoes { grid-template-columns: 1fr 1fr; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 76px); z-index: 40; transform: translate(-50%, 12px);
  width: max-content; max-width: calc(100vw - 32px); padding: 10px 14px; border-radius: 10px;
  background: var(--text); color: var(--bg); font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
}
#toast.visivel { opacity: 1; transform: translate(-50%, 0); }

@media (max-height: 680px) {
  .teclado button { height: 44px; }
  .visor { height: 46px; font-size: 30px; }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
