:root {
  --bg: #f4f6f8; --surface: #fff; --text: #17212b; --muted: #66727f; --line: #e3e8ed; --soft: #f7f9fa;
  --primary: #0f766e; --primary-2: #115e59; --primary-soft: #e6f4f2;
  --pos: #15803d; --neg: #c2410c; --warn-bg: #fff7ed; --cur: #eef7f6;
  --c1: #0f766e; --c2: #f59e0b; --c3: #6366f1; --c4: #ec4899;
  --radius: 12px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1418; --surface: #182027; --text: #e6edf3; --muted: #93a1ad; --line: #26313b; --soft: #1d262e;
    --primary: #2dd4bf; --primary-2: #5eead4; --primary-soft: #133a37; --pos: #4ade80; --neg: #fb923c; --warn-bg: #2b2113; --cur: #17302d;
    --c1: #2dd4bf; --c2: #fbbf24; --c3: #818cf8; --c4: #f472b6; --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
body.noscroll { overflow: hidden; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .6rem; line-height: 1.25; }
h2 { font-size: 1rem; }
h3 { font-size: .9rem; color: var(--muted); }
.cap { text-transform: capitalize; }
.muted { color: var(--muted); }
.small, small { font-size: .82rem; }
.center { text-align: center; }
.pad { padding: 1rem; }
.error { color: var(--neg); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* layout */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1.5rem; padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--text); font-size: 1.05rem; }
.topnav { display: flex; gap: .25rem; flex: 1; align-items: center; }
.topnav a, .topnav .link { padding: .4rem .7rem; border-radius: 8px; color: var(--muted); }
.topnav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.topnav .link { margin-left: auto; }
.view { padding: 1rem 1rem 6rem; max-width: 1100px; margin: 0 auto; }
.view:has(.page.wide) { max-width: 1500px; }
.page-title { font-size: 1.35rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: .5rem; }
.page-head .page-title { margin: 0; margin-right: auto; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card.alert { border-color: #fdba74; background: var(--warn-bg); }
.card-head { display: flex; justify-content: space-between; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid2 > .card { margin-bottom: 0; }
.grid2 { margin-bottom: 1rem; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; margin-bottom: 1rem; }
.kpis.small3 { grid-template-columns: repeat(3, 1fr); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; display: flex; flex-direction: column; gap: .15rem; box-shadow: var(--shadow); }
.kpi span { color: var(--muted); font-size: .8rem; }
.kpi { min-width: 0; }
.modal .kpi { padding: .55rem .7rem; }
.modal .kpi b { font-size: .98rem; }
.modal .kpis { gap: .5rem; }
.kpi b { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.kpi.pos b { color: var(--pos); }
.kpi.neg b { color: var(--neg); }

/* bottom nav + fab (celular) */
.bottomnav { display: none; }
.fab { position: fixed; right: 1.25rem; bottom: 1.5rem; z-index: 30; width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--primary); color: #fff; font-size: 2rem; line-height: 1; box-shadow: 0 6px 16px rgba(15, 118, 110, .35); cursor: pointer; }
.fab:active { transform: scale(.96); }
[hidden] { display: none !important; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list li > div { display: flex; flex-direction: column; min-width: 0; }
.list li > div.grow { flex: 1; }
.list.compact li { padding: .35rem 0; }
.clickable { cursor: pointer; }
.list li.clickable:hover, tr.clickable:hover td, tr.clickable:hover th { background: var(--soft); }
.rows { display: flex; flex-direction: column; }
.row-link { display: flex; justify-content: space-between; padding: .55rem 0; border-bottom: 1px solid var(--line); color: var(--text); background: none; border-left: 0; border-right: 0; border-top: 0; font: inherit; width: 100%; text-align: left; cursor: pointer; }
.row-link.total { font-weight: 700; border-bottom: 0; }
h3.day { margin: .8rem 0 .2rem; }
.hbar { width: 100%; height: 6px; display: block; margin-top: .25rem; }
.hbar .bg { fill: var(--line); }

/* tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-bottom: 1rem; }
.card .table-wrap { margin-bottom: .5rem; }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .85rem; }
.grid th, .grid td { padding: .38rem .55rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid thead th { position: sticky; top: 0; background: var(--soft); font-weight: 600; color: var(--muted); z-index: 2; text-align: right; }
.grid thead th.sticky { text-align: left; }
.grid th.sub { font-weight: 500; font-size: .75rem; }
.grid .sticky { position: sticky; left: 0; background: var(--surface); z-index: 1; text-align: left; font-weight: 500; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; }
.grid thead .sticky { z-index: 3; background: var(--soft); }
.grid tr.sec th, .grid tr.sec td { background: var(--primary-soft); color: var(--primary); font-weight: 700; text-align: left; }
.grid tr.sec .link { font-size: 1rem; margin-left: .25rem; }
.grid tr.subtotal th, .grid tr.subtotal td { background: var(--soft); font-weight: 600; }
.grid tr.total th, .grid tr.total td { background: var(--soft); font-weight: 700; border-top: 1px solid var(--line); }
.grid tr.big th, .grid tr.big td { font-size: .95rem; }
.grid tr.computed th a { font-weight: 600; }
.grid td.tot { font-weight: 600; }
.grid td.cur, .grid th.cur, .grid tr.cur td, .grid tr.cur th { background-color: var(--cur); }
.grid td.edit { cursor: pointer; }
.grid td.edit:hover { outline: 2px solid var(--primary); outline-offset: -2px; }
.grid td.edit:empty::after { content: "·"; color: var(--line); }
.grid td.auto { color: var(--muted); font-style: italic; }
.grid .catname { cursor: pointer; }
.grid .catname.inactive { color: var(--muted); text-decoration: line-through; }
.grid tr.warn td { background: var(--warn-bg); }
.list-table td { vertical-align: top; }
.badge { font-size: .65rem; background: var(--primary-soft); color: var(--primary); padding: 0 .35rem; border-radius: 6px; font-weight: 600; vertical-align: middle; }
input.recat { margin-top: .35rem; min-height: 34px; padding: .3rem .5rem; font-size: .85rem; }
input.recat.saved { border-color: var(--pos); }
input.mini { width: 5rem; padding: .25rem .4rem; text-align: right; }

/* charts */
.chart { width: 100%; height: auto; display: block; }
.chart .axis { font-size: 11px; fill: var(--muted); }
.c1 { fill: var(--c1); } .c2 { fill: var(--c2); } .c3 { fill: var(--c3); } .c4 { fill: var(--c4); }
.legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.lg i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }
.lg i.c1 { background: var(--c1); } .lg i.c2 { background: var(--c2); } .lg i.c3 { background: var(--c3); } .lg i.c4 { background: var(--c4); }

/* forms & buttons */
label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); margin-bottom: .75rem; }
label.check { flex-direction: row; align-items: center; gap: .5rem; color: var(--text); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .55rem .65rem; min-height: 40px; width: 100%; }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; }
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
.big-input { font-size: 1.6rem; font-weight: 700; text-align: right; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; font: inherit; font-weight: 600; padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; min-height: 40px; }
.btn.sm { padding: .25rem .6rem; min-height: 32px; font-size: .85rem; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #062b28; } }
.btn.danger { color: var(--neg); border-color: var(--neg); background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: wait; }
.link { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; padding: 0; }
.actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .5rem; }
.actions.left { justify-content: flex-start; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .5rem; }
.filters select, .filters input { width: auto; flex: 1 1 140px; }
.year-nav { display: flex; align-items: center; gap: .35rem; }
.year-nav select { width: auto; min-height: 32px; padding: .2rem .5rem; }
fieldset.chips { border: 0; padding: 0; margin: 0 0 .75rem; display: flex; flex-wrap: wrap; gap: .4rem; }
fieldset.chips legend { font-size: .85rem; color: var(--muted); margin-bottom: .3rem; padding: 0; }
.chip { margin: 0; display: inline-flex; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { padding: .4rem .75rem; border-radius: 999px; border: 1px solid var(--line); color: var(--text); cursor: pointer; font-size: .85rem; }
.chip input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

/* modal */
.modal-wrap { position: fixed; inset: 0; background: rgba(10, 15, 20, .45); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: .9rem 1rem .4rem; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: .5rem 1rem 1rem; }
.icon-btn { background: none; border: 0; font-size: 1.6rem; line-height: 1; color: var(--muted); cursor: pointer; padding: .2rem .5rem; }

.toast { position: fixed; left: 50%; bottom: 5.5rem; transform: translateX(-50%) translateY(20px); background: #17212b; color: #fff; padding: .6rem 1rem; border-radius: 10px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 60; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.err { background: #b42318; }

/* auth */
.auth { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.auth-card { width: 100%; max-width: 360px; }
.auth-card h1 { font-size: 1.4rem; }

/* celular */
@media (max-width: 760px) {
  .topbar { display: none !important; }
  .view { padding: .75rem .75rem calc(7rem + env(safe-area-inset-bottom)); }
  .bottomnav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .1rem; padding: .45rem 0 .5rem; color: var(--muted); font-size: .7rem; }
  .bottomnav a span { font-size: 1.15rem; line-height: 1.1; }
  .bottomnav a.active { color: var(--primary); font-weight: 600; }
  .fab { bottom: calc(4.6rem + env(safe-area-inset-bottom)); right: 1rem; }
  .toast { bottom: calc(9rem + env(safe-area-inset-bottom)); }
  .kpis { grid-template-columns: 1fr 1fr; gap: .5rem; }
  .kpi { padding: .65rem .75rem; }
  .kpi b { font-size: 1.05rem; }
  .grid2 { grid-template-columns: 1fr; }
  .grid2 > .card { margin-bottom: 0; }
  .modal-wrap { align-items: flex-end; padding: 0; }
  .modal { border-radius: 16px 16px 0 0; max-height: 94vh; padding-bottom: env(safe-area-inset-bottom); }
  .page-title { font-size: 1.2rem; }
  .grid .sticky { max-width: 36vw; }
  .grid th, .grid td { padding: .38rem .45rem; }
}
