/* Layout: menu lateral discreto + barra superior com navegação de mês; a planilha ocupa toda a largura útil. */
:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-2: #f8faf8;
  --ink: #17201d;
  --muted: #5f6b66;
  --faint: #8a958f;
  --line: #e1e6e2;
  --line-strong: #c9d1cc;
  --hdr: #131816;
  --hdr-ink: #f2f5f3;
  --accent: #0e6a61;
  --accent-ink: #ffffff;
  --accent-soft: #e0f0ec;
  --fill: #fff8d6;
  --fill-hover: #fff1b0;
  --fill-strong: #ffe58a;
  --plan: #fdf3c4;
  --pos: #1b7a4b;
  --pos-soft: #e3f4ea;
  --neg: #bf3a2b;
  --neg-soft: #fbe7e4;
  --warn: #a8690f;
  --warn-soft: #fbf0dc;
  --cur: #e7f3f0;
  --shadow: 0 1px 2px rgb(20 30 25 / 6%), 0 4px 16px rgb(20 30 25 / 6%);
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --side-w: 212px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101413; --surface: #171d1b; --surface-2: #1c2321; --ink: #e6ece9; --muted: #a0aca7; --faint: #77837e;
    --line: #29322f; --line-strong: #3a4541; --hdr: #0a0d0c; --hdr-ink: #eef3f0;
    --accent: #4db3a6; --accent-ink: #08201d; --accent-soft: #19332f;
    --fill: #2c2814; --fill-hover: #3a3418; --fill-strong: #5c4d12; --plan: #3a3416;
    --pos: #52c48c; --pos-soft: #16301f; --neg: #f07563; --neg-soft: #3a1c18; --warn: #e3a648; --warn-soft: #34290f;
    --cur: #15302b; --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 18px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101413; --surface: #171d1b; --surface-2: #1c2321; --ink: #e6ece9; --muted: #a0aca7; --faint: #77837e;
  --line: #29322f; --line-strong: #3a4541; --hdr: #0a0d0c; --hdr-ink: #eef3f0;
  --accent: #4db3a6; --accent-ink: #08201d; --accent-soft: #19332f;
  --fill: #2c2814; --fill-hover: #3a3418; --fill-strong: #5c4d12; --plan: #3a3416;
  --pos: #52c48c; --pos-soft: #16301f; --neg: #f07563; --neg-soft: #3a1c18; --warn: #e3a648; --warn-soft: #34290f;
  --cur: #15302b; --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 18px rgb(0 0 0 / 25%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; }
h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 650; }
h3 { font-size: 13px; font-weight: 650; }
.num, td, .kpi-v { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn { color: var(--warn); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- Botões e campos ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); background: var(--surface); padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; font-weight: 550; font-size: 13px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--neg); }
.btn.danger.solid { background: var(--neg); color: #fff; border-color: var(--neg); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); border-color: var(--line); }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; padding: 4px 6px; border-radius: 6px; cursor: pointer; color: var(--muted); line-height: 1; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 550; }
.field input, .field select, .field textarea, .input { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0; }
.field input.money, .input.money { background: var(--fill); text-align: right; font-variant-numeric: tabular-nums; }
.field textarea { resize: vertical; min-height: 60px; }
.field .hint { font-size: 11.5px; color: var(--faint); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 12px; cursor: pointer; font-size: 13px; font-weight: 550; }
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

/* ---------- Chips de status/fonte ---------- */
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 650; padding: 2px 7px; border-radius: 999px; white-space: nowrap; letter-spacing: .01em; }
.chip.real { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.chip.plan { background: var(--plan); color: var(--warn); }
.chip.auto { background: transparent; color: var(--muted); border: 1px dashed var(--line-strong); }
.chip.paid { background: var(--pos-soft); color: var(--pos); }
.chip.pending { background: var(--warn-soft); color: var(--warn); }
.chip.overdue { background: var(--neg-soft); color: var(--neg); }
.chip.info { background: var(--accent-soft); color: var(--accent); }
button.chip { border: 0; cursor: pointer; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: none; }
.dot.paid { background: var(--pos); }
.dot.pending { background: var(--warn); }
.dot.overdue { background: var(--neg); }

/* ---------- Estrutura ---------- */
#app { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100%; }
.side { background: var(--hdr); color: var(--hdr-ink); position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 16px 10px; gap: 2px; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 18px; }
.brand-mark { width: 30px; height: 30px; border: 1.5px solid currentColor; border-radius: 7px; display: grid; place-items: center; font-weight: 800; font-size: 13px; }
.brand b { display: block; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; }
.brand small { opacity: .6; font-size: 11px; }
.nav-btn { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: transparent; border: 0; color: inherit; opacity: .72; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-weight: 550; font-size: 13.5px; }
.nav-btn svg { width: 17px; height: 17px; flex: none; }
.nav-btn:hover { opacity: 1; background: rgb(255 255 255 / 7%); }
.nav-btn.on { opacity: 1; background: rgb(255 255 255 / 12%); }
.nav-sep { height: 1px; background: rgb(255 255 255 / 10%); margin: 10px 8px; }
.side-foot { margin-top: auto; padding: 10px 8px 0; font-size: 12px; opacity: .65; overflow-wrap: anywhere; }
.badge-n { margin-left: auto; background: var(--neg); color: #fff; border-radius: 999px; font-size: 10.5px; padding: 1px 6px; font-weight: 700; }

.main-col { min-width: 0; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 20; background: var(--bg); border-bottom: 1px solid var(--line); padding: 12px max(20px, env(safe-area-inset-right, 0px)) 12px max(20px, env(safe-area-inset-left, 0px)); display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.top h1 { flex: 1; min-width: 140px; }
.monthnav { display: flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; padding: 3px; }
.monthnav .mlabel { min-width: 132px; text-align: center; font-weight: 650; text-transform: capitalize; }
.monthnav select { border: 0; background: transparent; font-weight: 650; padding: 4px; cursor: pointer; }
#main { padding: 20px max(20px, env(safe-area-inset-right, 0px)) 40px max(20px, env(safe-area-inset-left, 0px)); min-width: 0; display: flex; flex-direction: column; gap: 18px; }
.banner { background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid var(--line); padding: 8px 20px; font-weight: 600; font-size: 13px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.tabbar { display: none; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.panel-h { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-h p { margin: 2px 0 0; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; align-items: start; }
.cols-2-1 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 18px; align-items: start; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.kpi-l { font-size: 11.5px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.kpi-v { font-size: 21px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-s { font-size: 12px; color: var(--muted); }
.meter { height: 6px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--pos); }
.meter.warn > i { background: var(--warn); }
.meter.neg > i { background: var(--neg); }

/* ---------- Tabela planilha ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar .input { width: auto; padding: 6px 10px; }
.toolbar .search { min-width: 200px; flex: 1; max-width: 300px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); align-items: center; }
.legend i { display: inline-block; width: 22px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 5px; border: 1px solid var(--line-strong); }
.legend .lg-fill { background: var(--fill); }
.legend .lg-plan { background: var(--plan); }
.legend .lg-auto { background: repeating-linear-gradient(135deg, transparent 0 3px, var(--line) 3px 4px); }
.legend .lg-cur { background: var(--cur); }

.sheet-wrap { overflow: auto; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); max-height: calc(100vh - 220px); min-height: 300px; }
table.sheet { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: 12.5px; }
.sheet th, .sheet td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0; height: 30px; white-space: nowrap; }
.sheet thead th { position: sticky; top: 0; z-index: 3; background: var(--hdr); color: var(--hdr-ink); font-weight: 650; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; padding: 0 10px; text-align: right; }
.sheet thead th.cur { background: var(--accent); color: var(--accent-ink); }
.sheet thead th:first-child { left: 0; z-index: 5; text-align: left; }
.sheet .name { position: sticky; left: 0; z-index: 2; background: var(--surface); min-width: 250px; max-width: 290px; padding: 0 6px 0 10px; text-align: left; border-right: 1px solid var(--line-strong); }
.sheet .name-in { display: flex; align-items: center; gap: 6px; min-width: 0; }
.sheet .name button.lname { border: 0; background: transparent; padding: 0; cursor: pointer; text-align: left; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; color: var(--ink); }
.sheet .name button.lname:hover { color: var(--accent); text-decoration: underline; }
.sheet .tag { font-size: 10px; font-weight: 700; color: var(--muted); border: 1px solid var(--line-strong); border-radius: 4px; padding: 0 4px; flex: none; }
.sheet .tag.via { color: var(--accent); border-color: var(--accent); }
td.c { min-width: 104px; text-align: right; padding: 0 8px; cursor: cell; position: relative; background: var(--fill); }
td.c:hover { background: var(--fill-hover); }
td.c.cur { box-shadow: inset 2px 0 0 var(--accent), inset -2px 0 0 var(--accent); }
td.c.plan { background: var(--plan); font-style: italic; color: var(--warn); }
td.c.auto { background: repeating-linear-gradient(135deg, var(--surface) 0 5px, var(--surface-2) 5px 7px); color: var(--muted); font-style: italic; }
td.c.real { color: var(--ink); }
td.c.ro { background: var(--surface-2); color: var(--faint); cursor: default; }
td.c .dot { position: absolute; left: 6px; top: 50%; margin-top: -3.5px; }
td.c .flag { position: absolute; right: 2px; top: 1px; font-size: 9px; font-style: normal; font-weight: 800; line-height: 1; }
td.c .flag.up { color: var(--neg); }
td.c .flag.low { color: var(--warn); }
td.c .flag.items { color: var(--accent); }
td.c input.cell-in { position: absolute; inset: 0; width: 100%; border: 2px solid var(--accent); border-radius: 0; text-align: right; padding: 0 6px; background: var(--surface); font-style: normal; color: var(--ink); outline: 0; }
.cell-pop { position: absolute; z-index: 6; top: 100%; right: -2px; display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 0 0 6px 6px; padding: 3px; box-shadow: var(--shadow); }
td.stat { min-width: 108px; text-align: right; padding: 0 10px; background: var(--surface-2); color: var(--muted); }
td.stat .sub { font-size: 10px; color: var(--faint); margin-left: 4px; }
tr.cat td { background: var(--accent-soft); font-weight: 700; color: var(--accent); }
tr.cat td.name { background: var(--accent-soft); }
tr.cat .cat-in { display: flex; align-items: center; gap: 6px; }
tr.cat .cat-in button.cname { border: 0; background: transparent; color: inherit; font-weight: 750; cursor: pointer; text-transform: uppercase; letter-spacing: .05em; font-size: 11.5px; padding: 0; }
tr.cat td.sub { text-align: right; padding: 0 8px; font-size: 11.5px; }
tr.tot td { background: var(--hdr); color: var(--hdr-ink); font-weight: 700; text-align: right; padding: 0 8px; border-color: rgb(255 255 255 / 8%); }
tr.tot td.name { background: var(--hdr); color: var(--hdr-ink); font-size: 11.5px; letter-spacing: .05em; text-transform: uppercase; }
tr.tot td.fc { font-style: italic; opacity: .78; }
tr.tot td .pos, tr.tot td .neg { filter: brightness(1.35); }
tr.inc-row td.name button.lname { color: var(--pos); }
tr.empty-hint td { color: var(--faint); font-style: italic; padding: 0 10px; background: var(--surface); }

/* ---------- Visão mês / listas ---------- */
.mlist { display: flex; flex-direction: column; }
.mgroup-h { display: flex; justify-content: space-between; align-items: center; padding: 10px 4px 6px; border-bottom: 2px solid var(--accent); color: var(--accent); font-weight: 750; text-transform: uppercase; font-size: 11.5px; letter-spacing: .05em; gap: 8px; }
.mrow { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.mrow .mn { min-width: 0; }
.mrow .mn b { display: block; font-weight: 600; }
.mrow .mn b .btn { white-space: normal; text-align: left; line-height: 1.3; }
.mrow .mn small { color: var(--muted); font-size: 11.5px; }
.mrow .mv { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; cursor: pointer; padding: 4px 8px; border-radius: 6px; background: var(--fill); min-width: 108px; }
.mrow .mv.auto { background: transparent; border: 1px dashed var(--line-strong); color: var(--muted); font-style: italic; }
.mrow .mv.plan { background: var(--plan); color: var(--warn); font-style: italic; }
.mrow .mv.empty { color: var(--faint); font-weight: 500; }

table.list { width: 100%; border-collapse: collapse; font-size: 13px; }
table.list th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; padding: 8px 10px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
table.list td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list td.r, table.list th.r { text-align: right; }
table.list tr.neg-row td { background: var(--neg-soft); }
table.list tfoot td { font-weight: 700; border-top: 2px solid var(--line-strong); }
.table-scroll { overflow-x: auto; min-width: 0; }

/* ---------- Previsão ---------- */
.fc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.fc-cell { background: var(--surface); padding: 14px; display: flex; flex-direction: column; gap: 4px; }
.fc-cell .l { font-size: 12px; color: var(--muted); font-weight: 600; }
.fc-cell .v { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.fc-cell.total { background: var(--surface-2); }
.note { padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 12.5px; }
.note.info { background: var(--accent-soft); color: var(--accent); }
.note.bad { background: var(--neg-soft); color: var(--neg); }

/* ---------- Cartões ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.ccard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; }
.ccard-h { background: var(--hdr); color: var(--hdr-ink); padding: 12px 14px; display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.ccard-h b { display: block; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.ccard-h small { opacity: .7; font-size: 11.5px; }
.ccard-b { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.kv { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.kv span:first-child { color: var(--muted); }
.kv b { font-variant-numeric: tabular-nums; }
.plist { border-top: 1px solid var(--line); padding-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.pitem { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: center; font-size: 12.5px; }
.pitem span.d { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prog { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; margin-top: 3px; }
.prog i { display: block; height: 100%; background: var(--accent); }

/* ---------- Gráficos ---------- */
.chart { width: 100%; height: auto; max-height: 290px; display: block; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .bar-inc { fill: var(--accent); }
.chart .bar-exp { fill: #e0876f; }
.chart .bar-fc { opacity: .38; }
.chart .ln { fill: none; stroke: var(--ink); stroke-width: 2; }
.chart .ln-sim { fill: none; stroke: var(--neg); stroke-width: 2; stroke-dasharray: 5 4; }
.chart .pt { fill: var(--surface); stroke: var(--ink); stroke-width: 2; }
.chart .zero { stroke: var(--line-strong); stroke-width: 1.2; }
.chart .hbar { fill: var(--accent); }
.chart-legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

/* ---------- Alertas ---------- */
.alerts { display: flex; flex-direction: column; gap: 6px; }
.alert { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); font-size: 13px; }
.alert.overdue { background: var(--neg-soft); }
.alert.soon { background: var(--warn-soft); }
.alert b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }

.money-wrap { display: flex; gap: 4px; align-items: stretch; min-width: 0; width: 100%; }
.money-wrap input { flex: 1; min-width: 0; }
.sign-btn { flex: none; width: 34px; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 6px; cursor: pointer; font-weight: 700; color: var(--muted); }
.sign-btn:hover { color: var(--ink); border-color: var(--accent); }
.hyp { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; }
.hyp-d { flex: 1 1 220px; min-width: 0; }

/* ---------- Gaveta / modal ---------- */
#drawer { position: fixed; inset: 0; z-index: 50; background: rgb(10 15 13 / 42%); display: flex; justify-content: flex-end; }
.drawer-panel { width: min(520px, 100%); height: 100%; background: var(--surface); box-shadow: var(--shadow); display: flex; flex-direction: column; animation: slidein .16s ease-out; }
@keyframes slidein { from { transform: translateX(24px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .drawer-panel { animation: none; } }
.drawer-h { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding-top: max(16px, env(safe-area-inset-top, 0px)); }
.drawer-b { padding: 18px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 14px; }
.drawer-f { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding-bottom: max(12px, env(safe-area-inset-bottom, 0px)); }
.drawer-f .spacer { flex: 1; }
#modal { position: fixed; inset: 0; z-index: 60; background: rgb(10 15 13 / 45%); display: grid; place-items: center; padding: 16px; }
.modal-box { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); padding: 20px; width: min(420px, 100%); display: flex; flex-direction: column; gap: 14px; }
.items-tbl { width: 100%; border-collapse: collapse; }
.items-tbl td { padding: 3px 3px; }
.items-tbl input { border: 1px solid var(--line-strong); border-radius: 6px; padding: 6px 8px; width: 100%; background: var(--surface); }
.items-tbl input.money { background: var(--fill); text-align: right; }
.explain { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 12.5px; display: flex; flex-direction: column; gap: 4px; }
.explain .kv { font-size: 12.5px; }

#toast { position: fixed; left: 50%; bottom: max(20px, calc(env(safe-area-inset-bottom, 0px) + 74px)); transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--hdr); color: var(--hdr-ink); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); display: flex; gap: 12px; align-items: center; pointer-events: auto; font-size: 13px; max-width: calc(100vw - 32px); }
.toast.err { background: var(--neg); color: #fff; }
.toast button { background: transparent; border: 1px solid rgb(255 255 255 / 40%); color: inherit; border-radius: 6px; padding: 3px 8px; cursor: pointer; font-weight: 650; }
.saving { font-size: 12px; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }

/* ---------- Login / boas-vindas ---------- */
#auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: var(--hdr); }
.auth-box { width: min(400px, 100%); background: var(--surface); border-radius: 14px; padding: 28px; display: flex; flex-direction: column; gap: 16px; box-shadow: var(--shadow); }
.auth-box .brand { color: var(--ink); padding: 0; }
.auth-err { color: var(--neg); font-size: 13px; min-height: 18px; }
.welcome { max-width: 760px; margin: 20px auto; display: flex; flex-direction: column; gap: 16px; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.choice { text-align: left; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 16px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; }
.choice:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.choice b { font-size: 14px; }
.choice span { color: var(--muted); font-size: 12.5px; }

/* ---------- Importação ---------- */
.imp-tbl td, .imp-tbl th { font-size: 12px; padding: 5px 7px; }
.imp-tbl td.bad { background: var(--warn-soft); color: var(--warn); }
.imp-tbl td.conf { box-shadow: inset 0 0 0 2px var(--neg); }
.imp-tbl tr.ignored td { opacity: .45; }
.imp-tbl select { max-width: 220px; padding: 4px 6px; border-radius: 6px; border: 1px solid var(--line-strong); background: var(--surface); }
.dropzone { border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--muted); }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- Impressão / PDF ---------- */
#print { display: none; }
@media print {
  body { background: #fff; color: #000; }
  #app, #auth, #drawer, #modal, #toast, .tabbar { display: none !important; }
  #print { display: block; padding: 0; font-size: 11px; }
  #print h1 { font-size: 18px; margin-bottom: 4px; }
  #print h2 { font-size: 13px; margin: 16px 0 6px; }
  #print table { border-collapse: collapse; width: 100%; }
  #print th, #print td { border: 1px solid #bbb; padding: 3px 5px; text-align: right; font-size: 9.5px; }
  #print th:first-child, #print td:first-child { text-align: left; }
  #print thead th { background: #111 !important; color: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #print .page-break { page-break-before: always; }
  @page { size: A4 landscape; margin: 12mm; }
}

/* ---------- Responsivo ---------- */
@media (max-width: 1280px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 1000px) { .cols-2-1 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 820px) {
  #app { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .top { padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); top: env(safe-area-inset-top, 0px); gap: 10px; }
  .top h1 { font-size: 17px; }
  .monthnav { width: 100%; justify-content: space-between; }
  #main { padding: 16px max(16px, env(safe-area-inset-right, 0px)) 96px max(16px, env(safe-area-inset-left, 0px)); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 12px; }
  .kpi-v { font-size: 17px; }
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }
  .cols { grid-template-columns: minmax(0, 1fr); }
  .sheet .name { min-width: 150px; max-width: 170px; }
  .sheet-wrap { max-height: calc(100vh - 260px); }
  .toolbar .search { min-width: 0; max-width: none; width: 100%; flex-basis: 100%; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--hdr); color: var(--hdr-ink); padding: 6px max(8px, env(safe-area-inset-right, 0px)) max(6px, env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px)); }
  .tabbar button { background: transparent; border: 0; color: inherit; opacity: .65; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; padding: 4px 0; cursor: pointer; }
  .tabbar button.on { opacity: 1; }
  .tabbar svg { width: 20px; height: 20px; }
  body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 30; background: var(--bg); }
  .more-menu { position: fixed; right: max(8px, env(safe-area-inset-right, 0px)); bottom: calc(64px + env(safe-area-inset-bottom, 0px)); z-index: 45; background: var(--hdr); color: var(--hdr-ink); border-radius: 12px; padding: 6px; box-shadow: var(--shadow); min-width: 210px; }
  .drawer-panel { width: 100%; }
  .items-tbl tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) auto; gap: 6px; padding-bottom: 10px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
  .items-tbl td { width: auto !important; padding: 0; min-width: 0; }
  .items-tbl td:first-child { grid-column: 1 / -1; }
}
