:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f0f2f5; --border: #dfe3e8; --text: #1b1f24; --muted: #5d6673;
  --accent: #2456c7; --accent-ink: #ffffff; --pos: #1f7a4d; --neg: #b3261e; --warn: #9a6200;
  --s1: #2456c7; --s2: #b3261e; --s3: #1f7a4d; --s4: #8a4fbf; --s5: #c07a00; --s6: #0f7c8c;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --surface: #171b21; --surface-2: #1e232b; --border: #2b323c; --text: #e7ebf0; --muted: #9aa4b2;
    --accent: #6e9bff; --accent-ink: #0f1216; --pos: #4cc38a; --neg: #ff7b72; --warn: #e3b341;
    --s1: #6e9bff; --s2: #ff7b72; --s3: #4cc38a; --s4: #c39bff; --s5: #e3b341; --s6: #4fd1e0;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 1rem 0 .5rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
p { margin: .25rem 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn { color: var(--warn); }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 1.25rem 1rem; display: flex; flex-direction: column; gap: .25rem; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 1.05rem; margin: 0 .5rem 1rem; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { color: var(--text); padding: .5rem .75rem; border-radius: 8px; }
.side nav a:hover { background: var(--surface-2); text-decoration: none; }
.side nav a.active { background: var(--accent); color: var(--accent-ink); }
.side .spacer { flex: 1; }
.side .who { font-size: .85rem; color: var(--muted); margin: 0 .5rem .5rem; }
main { padding: 1.5rem 2rem 3rem; min-width: 0; max-width: 1280px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.grid { display: grid; gap: 1rem; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr)); gap: .75rem; margin-bottom: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 1rem; }
.grid > .card + .card, .kpis > .card + .card { margin-top: 0; }
.kpi .label { color: var(--muted); font-size: .8rem; }
.kpi .value { font-size: clamp(1.05rem, 1.6vw, 1.35rem); font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .hint { color: var(--muted); font-size: .78rem; }
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: .75rem 1rem; border-right: 0; border-bottom: 1px solid var(--border); }
  .side nav { flex-direction: row; overflow-x: auto; flex: 1 1 100%; order: 3; min-width: 0; }
  .side nav a { white-space: nowrap; }
  .side .spacer, .side .who { display: none; }
  .brand { margin: 0 auto 0 0; }
  main { padding: 1rem 16px 3rem; }
  .cols-2, .cols-3 { grid-template-columns: 1fr; }
}

/* alerts */
.flash { padding: .65rem .9rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash.ok { border-color: var(--pos); color: var(--pos); background: color-mix(in srgb, var(--pos) 8%, transparent); }
.flash.err { border-color: var(--neg); color: var(--neg); background: color-mix(in srgb, var(--neg) 8%, transparent); }
.flash.warn { border-color: var(--warn); color: var(--warn); background: color-mix(in srgb, var(--warn) 8%, transparent); }
ul.alerts { margin: 0; padding-left: 1.1rem; }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -.25rem; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .45rem .5rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
tr.total td { font-weight: 650; border-top: 2px solid var(--border); }
tbody tr:hover { background: var(--surface-2); }
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 99px; font-size: .75rem; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.badge.ok { color: var(--pos); border-color: var(--pos); }
.badge.bad { color: var(--neg); border-color: var(--neg); }
.badge.warn { color: var(--warn); border-color: var(--warn); }

/* forms */
form.inline { display: inline; }
label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .2rem; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .45rem .6rem; width: 100%; min-width: 0; }
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem 1rem; margin-bottom: 1rem; }
.fields .wide { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: .4rem; color: var(--text); font-size: .9rem; margin: 0; }
button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); border-radius: 8px; padding: .45rem .9rem; display: inline-block; }
button.secondary, .btn.secondary { background: transparent; color: var(--accent); }
button.danger { background: transparent; color: var(--neg); border-color: var(--neg); }
button.link { background: none; border: 0; color: var(--accent); padding: 0; }
button.small, .btn.small { padding: .2rem .55rem; font-size: .82rem; }
.btn:hover { text-decoration: none; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
details > summary { cursor: pointer; color: var(--accent); margin: .25rem 0; }
details[open] > summary { margin-bottom: .75rem; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filters > div { min-width: 140px; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 400px; }
.qr { background: #fff; padding: .5rem; border-radius: 8px; width: 220px; margin: .5rem auto; }
.qr svg { width: 100%; height: auto; display: block; }
code.secret { display: block; word-break: break-all; background: var(--surface-2); padding: .5rem; border-radius: 6px; font-size: .85rem; }
.codes { columns: 2; font-family: ui-monospace, Menlo, monospace; font-size: 1rem; padding-left: 1.2rem; }

/* charts */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .zero { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 3; }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .series { fill: none; stroke-width: 2.25; stroke-linejoin: round; }
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: color-mix(in srgb, var(--text) 20%, transparent); }
.chart .bar.pos { fill: var(--pos); }
.chart .bar.neg { fill: var(--neg); }
.s1 { stroke: var(--s1); } .s2 { stroke: var(--s2); } .s3 { stroke: var(--s3); }
.s4 { stroke: var(--s4); } .s5 { stroke: var(--s5); } .s6 { stroke: var(--s6); }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .82rem; color: var(--muted); margin-top: .25rem; }
.legend .key::before { content: ""; display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: .35rem; vertical-align: middle; background: currentColor; }
.legend .key { color: var(--muted); }
.legend .key.s1::before { background: var(--s1); } .legend .key.s2::before { background: var(--s2); }
.legend .key.s3::before { background: var(--s3); } .legend .key.s4::before { background: var(--s4); }
.legend .key.s5::before { background: var(--s5); } .legend .key.s6::before { background: var(--s6); }
.legend .key.pos::before { background: var(--pos); } .legend .key.neg::before { background: var(--neg); }
.hbars .hlabel, .hbars .hvalue { fill: var(--text); font-size: 13px; }
.hbars .hvalue { fill: var(--muted); }
.hbars .htrack { fill: var(--surface-2); }
.hbars .hfill { fill: var(--accent); }

/* scenario editor */
table.lines tr.section th { background: var(--surface-2); color: var(--text); text-transform: none; letter-spacing: 0; font-size: .85rem; padding: .4rem .5rem; }
table.lines td { padding: .35rem .5rem; }
table.lines .note { max-width: 46ch; }
table.lines tr.edit-row { display: none; }
table.lines tr.edit-row:target { display: table-row; }
table.lines tr.edit-row td { background: var(--surface-2); padding: .9rem; }
table.lines tr:target:not(.edit-row) td { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.kind { display: inline-block; width: 1.1em; font-weight: 700; text-align: center; }
.kind.receita { color: var(--pos); } .kind.despesa { color: var(--neg); }
button.toggle { width: 18px; height: 18px; padding: 0; border-radius: 50%; border: 2px solid var(--muted); background: transparent; vertical-align: middle; }
button.toggle.on { border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 3px var(--surface); }
tr.off td { opacity: .55; }
tr.off td:first-child { opacity: 1; }
.sticky-first td:first-child, .sticky-first th:first-child { position: sticky; left: 0; background: var(--surface); }
.matrix td, .matrix th { font-size: .8rem; padding: .3rem .4rem; }
@media (max-width: 600px) {
  /* O SVG encolhe junto com a tela: compensa o tamanho do texto dos eixos. */
  .chart .tick { font-size: 22px; }
}
.chart .future { fill: color-mix(in srgb, var(--accent) 6%, transparent); }
.chart .dot { stroke: var(--surface); stroke-width: 1.5; }
.chart .dot.s1 { fill: var(--s1); } .chart .dot.s4 { fill: var(--s4); }
.chart .dot.neg { fill: var(--neg); }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .45rem .9rem; border-radius: 8px 8px 0 0; color: var(--muted); border: 1px solid transparent; border-bottom: 0; }
.tabs a.active { color: var(--text); background: var(--surface); border-color: var(--border); margin-bottom: -1px; }
.tabs a:hover { text-decoration: none; color: var(--text); }
