:root {
  --bg: #f3f5f4;
  --card: #ffffff;
  --ink: #15211f;
  --muted: #5d6b68;
  --line: #dfe5e3;
  --pri: #0e5a52;
  --pri-ink: #ffffff;
  --pri-soft: #e3f0ed;
  --acc: #d9822b;
  --ok: #1d7a46;
  --ok-soft: #e2f3e8;
  --warn: #9a6200;
  --warn-soft: #fdf1dc;
  --err: #b42318;
  --err-soft: #fde7e5;
  --r: 14px;
  --sh: 0 1px 2px rgba(16, 32, 28, .06), 0 4px 14px rgba(16, 32, 28, .05);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; letter-spacing: -.01em; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hide { display: none !important; }

/* layout */
.topbar { position: sticky; top: 0; z-index: 5; background: var(--pri); color: var(--pri-ink);
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 18px 14px; display: flex; align-items: center; gap: 12px; }
.topbar .logo { width: 32px; height: 32px; border-radius: 9px; background: rgba(255,255,255,.16); display: grid; place-items: center; font-weight: 800; font-size: 13px; letter-spacing: .02em; }
.topbar .t { flex: 1; min-width: 0; }
.topbar .t b { display: block; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .t span { font-size: 12px; opacity: .8; }
.topbar .back { background: none; border: 0; color: inherit; font-size: 22px; padding: 0 6px 0 0; }
main { padding: 16px 16px calc(96px + var(--safe-b) + var(--badge, 0px)); max-width: 640px; margin: 0 auto; }
.screen { display: none; animation: in .18s ease-out; }
.screen.on { display: block; }
@keyframes in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* cards */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--sh); padding: 16px; }
.card.flat { box-shadow: none; border: 1px solid var(--line); }
.kpi .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .val { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.bar { height: 6px; background: var(--pri-soft); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--pri); border-radius: 99px; }
.bar.warn > i { background: var(--acc); }

.alert { border-radius: 12px; padding: 12px 14px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.err { background: var(--err-soft); color: var(--err); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.info { background: var(--pri-soft); color: var(--pri); }
.alert .grow { flex: 1; }
.alert button { flex: none; }

/* lista de notas */
.list { background: var(--card); border-radius: var(--r); box-shadow: var(--sh); overflow: hidden; }
.item { display: flex; gap: 12px; align-items: center; padding: 13px 16px; border-top: 1px solid var(--line); background: none; border-left: 0; border-right: 0; border-bottom: 0; width: 100%; text-align: left; }
.item:first-child { border-top: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .grow b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.item .grow span { font-size: 13px; color: var(--muted); }
.item .v { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chip { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--pri-soft); color: var(--pri); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.err { background: var(--err-soft); color: var(--err); }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }

/* formulários */
label.f { display: block; }
label.f > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
label.f > small { display: block; font-size: 12px; color: var(--muted); margin-top: 5px; }
input, select, textarea { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 11px; padding: 12px 13px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--pri); box-shadow: 0 0 0 3px var(--pri-soft); }
textarea { min-height: 84px; resize: vertical; }
input.money { font-size: 26px; font-weight: 700; padding: 12px 14px; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 8px 14px; font-size: 14px; }
.chips button.sel { background: var(--pri); border-color: var(--pri); color: #fff; }
.switch { display: flex; align-items: center; gap: 12px; padding: 4px 0; }
.switch input { width: 46px; height: 28px; appearance: none; -webkit-appearance: none; background: #cfd8d5; border-radius: 99px; position: relative; border: 0; padding: 0; flex: none; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; background: #fff; border-radius: 50%; transition: left .15s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked { background: var(--pri); }
.switch input:checked::after { left: 21px; }
.switch input:focus { box-shadow: none; }
details.more > summary { cursor: pointer; color: var(--pri); font-weight: 600; font-size: 14px; list-style: none; padding: 4px 0; }
details.more > summary::-webkit-details-marker { display: none; }

/* botões */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 12px; padding: 13px 18px; font-weight: 650; background: var(--pri-soft); color: var(--pri); cursor: pointer; text-decoration: none; }
.btn.pri { background: var(--pri); color: #fff; }
.btn.acc { background: var(--acc); color: #fff; }
.btn.ghost { background: none; color: var(--pri); padding: 8px 10px; }
.btn.danger { background: var(--err-soft); color: var(--err); }
.btn.block { width: 100%; }
.btn.big { padding: 16px; font-size: 17px; }
.btn:disabled { opacity: .55; }
.btn.sm { padding: 8px 12px; font-size: 13px; border-radius: 10px; }

/* navegação inferior */
nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; background: rgba(255,255,255,.96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line); display: flex; justify-content: space-around; align-items: flex-end; padding: 6px 6px calc(6px + var(--safe-b) + var(--badge, 0px)); }
nav.tabs button { background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 10px; min-width: 64px; }
nav.tabs button svg { width: 24px; height: 24px; }
nav.tabs button.on { color: var(--pri); font-weight: 650; }
nav.tabs button.fab { color: #fff; }
nav.tabs button.fab .c { width: 54px; height: 54px; border-radius: 18px; background: var(--acc); display: grid; place-items: center; margin-top: -24px; box-shadow: 0 6px 16px rgba(217,130,43,.35); }
nav.tabs button.fab span { color: var(--acc); font-weight: 650; }

/* folha (bottom sheet) */
.sheet-bg { position: fixed; inset: 0; background: rgba(10, 20, 18, .45); z-index: 20; display: none; }
.sheet-bg.on { display: block; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--card); border-radius: 20px 20px 0 0; max-height: 92vh; overflow: auto;
  padding: 10px 18px calc(20px + var(--safe-b)); transform: translateY(105%); transition: transform .22s ease; max-width: 640px; margin: 0 auto; }
.sheet.on { transform: none; }
.sheet .grab { width: 40px; height: 4px; border-radius: 99px; background: var(--line); margin: 0 auto 12px; }
.resumo { border: 1px solid var(--line); border-radius: 12px; }
.resumo div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border-top: 1px solid var(--line); font-size: 14px; }
.resumo div:first-child { border-top: 0; }
.resumo div span { color: var(--muted); flex: none; }
.resumo div b { text-align: right; overflow-wrap: anywhere; font-weight: 600; }

/* PIN */
.pin { display: flex; gap: 10px; justify-content: center; margin: 14px 0; }
.pin i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--pri); }
.pin i.f { background: var(--pri); }
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 300px; margin: 0 auto; }
.keys button { height: 56px; border-radius: 14px; border: 0; background: var(--bg); font-size: 22px; font-weight: 600; }

/* sucesso */
.done { text-align: center; padding: 10px 0 4px; }
.done .ic { width: 64px; height: 64px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); display: grid; place-items: center; margin: 0 auto 12px; font-size: 32px; }

.spinner { width: 40px; height: 40px; border-radius: 50%; border: 4px solid var(--pri-soft); border-top-color: var(--pri); animation: spin .8s linear infinite; margin: 18px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; left: 50%; bottom: calc(92px + var(--safe-b) + var(--badge, 0px)); transform: translateX(-50%); background: #1d2a27; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 40; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; }
.toast.on { opacity: 1; }

.wiz-steps { display: flex; gap: 6px; margin-bottom: 4px; }
.wiz-steps i { flex: 1; height: 4px; border-radius: 99px; background: var(--line); }
.wiz-steps i.on { background: var(--pri); }
.hero { text-align: center; padding: 18px 6px 4px; }
.hero .mark { width: 72px; height: 72px; border-radius: 22px; background: var(--pri); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 24px; margin: 0 auto 14px; }
.sec-t { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 22px 4px 8px; }
.menu .item { cursor: pointer; }
.menu .item .ico { width: 34px; height: 34px; border-radius: 10px; background: var(--pri-soft); color: var(--pri); display: grid; place-items: center; flex: none; }
.menu .item .ico svg { width: 19px; height: 19px; }
.banner-teste { background: var(--warn-soft); color: var(--warn); font-size: 13px; text-align: center; padding: 7px 12px; font-weight: 600; }

/* financeiro */
.leg { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.gfin { display: flex; gap: 6px; align-items: stretch; height: 150px; border-bottom: 1px solid var(--line); }
.gcol { flex: 1; display: flex; flex-direction: column; background: none; border: 0; padding: 0 0 4px; border-radius: 8px; cursor: pointer; min-width: 0; }
.gcol.on { background: var(--pri-soft); }
.gbars { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 2px; padding: 6px 4px 0; }
.gbars i { width: 40%; max-width: 18px; min-height: 2px; border-radius: 4px 4px 0 0; }
.gcol span { font-size: 11px; color: var(--muted); margin-top: 4px; }
table.dre { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
table.dre th { font-size: 11px; color: var(--muted); font-weight: 600; text-align: right; padding: 8px 12px 4px; }
table.dre td { padding: 7px 12px; border-top: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.dre td:first-child { text-align: left; white-space: normal; padding-left: 26px; color: var(--muted); }
table.dre tr.tot td { font-weight: 700; background: #f7f9f8; }
table.dre tr.tot td:first-child { padding-left: 12px; color: var(--ink); }
table.dre tr.forte td { background: var(--pri-soft); color: var(--pri); }
table.dre td:last-child { color: var(--muted); font-size: 12px; }
table.dre .neg, .lucros .neg { color: var(--err); }
table.dre.comp td:first-child { padding-left: 12px; color: var(--ink); }
table.dre.comp td:last-child { font-size: 13.5px; }
.lucros { display: flex; flex-direction: column; gap: 8px; }
.lrow { display: grid; grid-template-columns: 54px 1fr 104px; align-items: center; gap: 8px; font-size: 13px; }
.lrow span { color: var(--muted); }
.lrow b { text-align: right; font-variant-numeric: tabular-nums; }
.lbar { height: 12px; background: #f1f4f3; border-radius: 4px; overflow: hidden; }
.lbar i { display: block; height: 100%; background: #2a9d8f; border-radius: 0 4px 4px 0; }
.lbar i.neg { background: #e76f51; }

/* ---------- tela inicial: painel de funções ---------- */
main:has(> .home) { max-width: 980px; }
.hero-emit { background: var(--pri); color: #fff; border-radius: 22px; padding: 16px; display: grid; gap: 10px; }
.he-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; font-size: 15px; opacity: .92; }
.he-mes { font-size: 13px; opacity: .85; font-variant-numeric: tabular-nums; }
.he-mes b { font-size: 15px; opacity: 1; }
.he-main { display: flex; align-items: center; gap: 14px; width: 100%; border: 0; border-radius: 16px; background: var(--acc); color: #fff; padding: 16px 18px; text-align: left; cursor: pointer;
  box-shadow: 0 8px 20px -10px rgba(0,0,0,.45); }
.he-main b { display: block; font-size: 20px; letter-spacing: -.01em; }
.he-main small { display: block; font-size: 13px; opacity: .9; margin-top: 2px; }
.he-ic { flex: none; width: 46px; height: 46px; border-radius: 14px; background: rgba(255,255,255,.18); display: grid; place-items: center; }
.he-ic svg { width: 26px; height: 26px; }
.he-alt { border: 1px solid rgba(255,255,255,.35); background: transparent; color: #fff; border-radius: 12px; padding: 11px 14px; font-weight: 600; cursor: pointer; }
.he-main:active, .he-alt:active, .tile:active { transform: scale(.985); }
.he-main:focus-visible, .he-alt:focus-visible, .tile:focus-visible { outline: 3px solid var(--acc); outline-offset: 2px; }

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tile { --tc: var(--pri); --tb: var(--pri-soft); position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 3px; text-align: left; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px 14px 13px; min-height: 118px; color: var(--ink); }
.tile .t-ic { width: 40px; height: 40px; border-radius: 12px; background: var(--tb); color: var(--tc); display: grid; place-items: center; margin-bottom: 8px; }
.tile .t-ic svg { width: 22px; height: 22px; }
.tile b { font-size: 15px; font-weight: 650; line-height: 1.2; }
.tile small { font-size: 12.5px; color: var(--muted); line-height: 1.3; }
.tile.alerta small { color: var(--tc); font-weight: 600; }
.tile .t-n { position: absolute; top: 12px; right: 12px; min-width: 24px; height: 24px; padding: 0 7px; border-radius: 99px; background: var(--acc); color: #fff; font-size: 12.5px; font-weight: 700; display: grid; place-items: center; }
.tile.g-op  { --tc: #0e5a52; --tb: #e3f0ed; }
.tile.g-com { --tc: #2f5d8a; --tb: #e7eef6; }
.tile.g-fin { --tc: #9a5a12; --tb: #fbeedd; }
.tile.g-cad { --tc: #4a5553; --tb: #eceeed; }

.resumo-mes { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.resumo-mes > div { display: flex; flex-direction: column; gap: 2px; }
.resumo-mes span { font-size: 12.5px; color: var(--muted); }
.resumo-mes b { font-size: 20px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.resumo-mes small { font-size: 12px; color: var(--muted); }
.resumo-mes .rm-lim { grid-column: 1 / -1; }

@media (min-width: 640px) {
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .hero-emit { grid-template-columns: 1fr auto; align-items: stretch; padding: 18px; }
  .he-top { grid-column: 1 / -1; }
  .he-alt { padding: 0 20px; }
  .resumo-mes { grid-template-columns: 1fr 1fr 1.4fr; }
  .resumo-mes .rm-lim { grid-column: auto; }
}
@media (min-width: 900px) {
  .tiles { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) { .he-main:active, .he-alt:active, .tile:active { transform: none; } }
