:root {
  --paper: #F3F5F2;
  --surface: #FFFFFF;
  --ink: #18232E;
  --muted: #5B6773;
  --rule: #DCE1E4;
  --rule-strong: #B9C2C8;
  --accent: #0F5C5A;
  --accent-soft: #E3EFEC;
  --gain: #1B7F4B;
  --loss: #B4332B;
  --warn: #9A5F05;
  --warn-soft: #FBF1DC;
  --loss-soft: #F8E5E3;
  --gain-soft: #E2F2E8;
  --radius: 6px;
  --sans: 'Public Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Newsreader', Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #12181D; --surface: #1A2228; --ink: #E7ECEF; --muted: #9AA7B1; --rule: #2C3740; --rule-strong: #43515C;
    --accent: #5FB8B2; --accent-soft: #1D3534; --gain: #5CC08A; --loss: #F08377; --warn: #E3B05A;
    --warn-soft: #3A2E17; --loss-soft: #3B2220; --gain-soft: #1C3426; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--paper); color: var(--ink); font: 15px/1.5 var(--sans); font-variant-numeric: tabular-nums; }
a { color: var(--accent); }
h1, h2, h3 { font-weight: 600; line-height: 1.2; margin: 0; }
h1 { font-family: var(--serif); font-weight: 500; font-size: 2rem; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; margin: 2rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1.2rem 0 .4rem; }
p { margin: .4rem 0 .8rem; max-width: 72ch; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* layout */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--rule); padding: 1.2rem 0; position: sticky; top: 0; height: 100vh; overflow: auto; }
.brand { padding: 0 1.2rem 1rem; font-family: var(--serif); font-size: 1.35rem; }
.brand small { display: block; font-family: var(--sans); font-size: .78rem; color: var(--muted); }
.profile-pick { margin: 0 1rem 1rem; }
.profile-pick select { width: 100%; }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: .45rem 1.2rem; color: var(--ink); text-decoration: none; border-left: 3px solid transparent; }
.nav a:hover { background: var(--paper); }
.nav a.on { border-left-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.nav .sep { height: 1px; background: var(--rule); margin: .6rem 1.2rem; }
.badge { background: var(--loss); color: #fff; border-radius: 99px; font-size: .72rem; padding: 0 .45rem; font-weight: 600; }
.badge.warn { background: var(--warn); }
.app > div { min-width: 0; }
main { padding: 2rem clamp(1rem, 3vw, 2.6rem) 4rem; min-width: 0; }
.head { display: flex; gap: 1rem; justify-content: space-between; align-items: end; flex-wrap: wrap; margin-bottom: 1.2rem; }
.head p { margin: .3rem 0 0; color: var(--muted); }
.toolbar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.mobilebar { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 20; transform: translateX(-102%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  .side.open { transform: none; }
  .mobilebar { display: flex; align-items: center; gap: .8rem; padding: .7rem 1rem; background: var(--surface); border-bottom: 1px solid var(--rule); position: sticky; top: 0; z-index: 10; }
  main { padding: 1.2rem 1rem 3rem; }
  h1 { font-size: 1.6rem; }
}

/* controls */
button, .btn { font: inherit; border: 1px solid var(--rule-strong); background: var(--surface); color: var(--ink); padding: .45rem .9rem; border-radius: var(--radius); cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .btn:hover { border-color: var(--ink); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.1); }
button.link { border: 0; background: none; color: var(--accent); padding: 0; text-decoration: underline; }
button.danger { color: var(--loss); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--rule-strong); border-radius: var(--radius); padding: .4rem .55rem; min-width: 0; }
input[type=number] { text-align: right; }
label.f { display: grid; gap: .25rem; font-size: .85rem; color: var(--muted); }
label.f > input, label.f > select, label.f > textarea { color: var(--ink); font-size: 15px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .8rem; align-items: end; }

/* panels */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; margin-bottom: 1.2rem; }
.figures > div { background: var(--surface); padding: .9rem 1rem; }
.figures b { display: block; font-size: 1.35rem; font-weight: 600; margin-top: .15rem; }
.figures span { color: var(--muted); font-size: .85rem; }

/* tables */
.tw { overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface); margin-bottom: 1rem; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { padding: .5rem .7rem; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: .8rem; background: var(--paper); position: sticky; top: 0; }
td.n, th.n { text-align: right; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 600; border-top: 1px solid var(--rule-strong); }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--paper); }
.nw { white-space: nowrap; }
.pos { color: var(--gain); }
.neg { color: var(--loss); }
.tag { display: inline-block; font-size: .75rem; padding: .05rem .45rem; border-radius: 4px; background: var(--paper); border: 1px solid var(--rule); white-space: nowrap; }
.tag.ok { background: var(--gain-soft); border-color: transparent; color: var(--gain); }
.tag.bad { background: var(--loss-soft); border-color: transparent; color: var(--loss); }
.tag.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }

/* the year strip: the app's signature element */
.year { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; margin: .4rem 0 1.4rem; }
.mo { background: var(--surface); border: 1px solid var(--rule); border-radius: 4px; padding: .5rem .45rem .55rem; min-height: 84px; display: flex; flex-direction: column; gap: .15rem; cursor: pointer; position: relative; text-align: left; font: inherit; color: inherit; }
.mo::before { content: ''; position: absolute; inset: 0 0 auto 0; height: 4px; border-radius: 4px 4px 0 0; background: var(--rule); }
.mo.darf::before { background: var(--loss); }
.mo.isento::before { background: var(--gain); }
.mo.prej::before { background: var(--warn); }
.mo.vazio { color: var(--muted); }
.mo.sel { outline: 2px solid var(--accent); }
.mo .m { font-weight: 600; font-size: .85rem; margin-top: .2rem; }
.mo .v { font-size: .8rem; }
.mo .l { font-size: .72rem; color: var(--muted); }
@media (max-width: 860px) { .year { grid-template-columns: repeat(4, 1fr); } }

/* misc */
.drop { border: 2px dashed var(--rule-strong); border-radius: var(--radius); padding: 2.2rem 1rem; text-align: center; background: var(--surface); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.notice { border-left: 4px solid var(--accent); background: var(--accent-soft); padding: .7rem 1rem; border-radius: 0 var(--radius) var(--radius) 0; margin: 0 0 1rem; }
.notice.warn { border-color: var(--warn); background: var(--warn-soft); }
.notice.bad { border-color: var(--loss); background: var(--loss-soft); }
.issue { display: grid; grid-template-columns: auto 1fr auto; gap: .8rem; padding: .7rem 0; border-bottom: 1px solid var(--rule); align-items: start; }
.issue:last-child { border-bottom: 0; }
.toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: .6rem 1.1rem; border-radius: var(--radius); z-index: 50; }
dialog { border: 1px solid var(--rule); border-radius: 8px; padding: 1.4rem; max-width: min(640px, 94vw); background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(10, 20, 30, .45); }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.copy { cursor: copy; }
.desc { max-width: 52ch; }
details summary { cursor: pointer; color: var(--accent); }
.loading { padding: 3rem; color: var(--muted); }

@media print {
  .side, .mobilebar, .toolbar, .noprint, button { display: none !important; }
  .app { display: block; }
  main { padding: 0; }
  body { background: #fff; color: #000; font-size: 11px; }
  .tw, .panel { border: 0; overflow: visible; }
  th { position: static; background: #eee; }
  h2 { break-after: avoid; }
  tr { break-inside: avoid; }
}
