/* Layout: barra lateral fixa em ecrãs largos; em telemóvel, barra superior com período e navegação inferior com botão + central.
   Visual de livro de contas: neutros ligeiramente esverdeados, verde DinheiroFala como acento, entradas a verde e saídas a tijolo. */
:root {
  --bg: #F4F6F4;
  --panel: #FFFFFF;
  --panel-2: #EEF2EF;
  --ink: #15211C;
  --muted: #5B6A63;
  --line: #DFE5E1;
  --accent: #0E6B50;
  --accent-ink: #FFFFFF;
  --accent-soft: #E1F0E9;
  --ent: #17845E;
  --sai: #B9502F;
  --ent-soft: #DDF1E7;
  --sai-soft: #F7E3DC;
  --warn: #A86A12;
  --warn-soft: #FBF0D9;
  --bad: #B83227;
  --bad-soft: #F8E0DD;
  --shadow: 0 1px 2px rgba(21, 33, 28, .06), 0 8px 24px -12px rgba(21, 33, 28, .18);
  --f-display: 'Bricolage Grotesque', 'Segoe UI', system-ui, sans-serif;
  --f-body: 'Figtree', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --r: 12px;
  --r-s: 8px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1412; --panel: #151D1A; --panel-2: #1B2521; --ink: #E5EDE9; --muted: #95A59D; --line: #26322D;
    --accent: #3DBB8C; --accent-ink: #06130E; --accent-soft: #173229;
    --ent: #4CC795; --sai: #EB805F; --ent-soft: #16302A; --sai-soft: #3A221B;
    --warn: #E2A84B; --warn-soft: #362A15; --bad: #F07468; --bad-soft: #3B1F1C;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 26px -14px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1412; --panel: #151D1A; --panel-2: #1B2521; --ink: #E5EDE9; --muted: #95A59D; --line: #26322D;
  --accent: #3DBB8C; --accent-ink: #06130E; --accent-soft: #173229;
  --ent: #4CC795; --sai: #EB805F; --ent-soft: #16302A; --sai-soft: #3A221B;
  --warn: #E2A84B; --warn-soft: #362A15; --bad: #F07468; --bad-soft: #3B1F1C;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 26px -14px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { background: var(--bg); color: var(--ink); }
body { font-family: var(--f-body); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; margin: 0; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
body.com-modal { overflow: hidden; }
h1, h2, h3 { font-family: var(--f-display); font-weight: 700; margin: 0; text-wrap: balance; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.45rem, 1.1rem + 1.4vw, 2rem); line-height: 1.15; }
h2 { font-size: 1.02rem; font-weight: 700; }
h3 { font-size: .95rem; }
p { margin: 0; }
small { color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--ent); }
.neg { color: var(--sai); }
.sub { color: var(--muted); font-size: .9rem; }
.mudo { color: var(--muted); }
.vazio { color: var(--muted); font-size: .9rem; padding: 8px 0; }
.flex1 { flex: 1; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- Estrutura ---------- */
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.lateral {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px;
  padding: 22px 16px; border-right: 1px solid var(--line); background: var(--panel);
}
.marca { display: flex; align-items: center; gap: 10px; }
.df {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink); font-family: var(--f-display); font-weight: 700; font-size: 15px; letter-spacing: -0.02em; flex: none;
}
.marca-txt { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.marca-txt strong { font-family: var(--f-display); font-size: 1.05rem; }
.marca-txt small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-lateral { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border: 0; background: none; border-radius: var(--r-s);
  color: var(--muted); cursor: pointer; text-align: left; font-weight: 500;
}
.nav-item:hover { background: var(--panel-2); color: var(--ink); }
.nav-item.activo { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.lateral-rodape { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.lateral-rodape small { font-size: .78rem; }

.principal { min-width: 0; display: flex; flex-direction: column; }
.topo {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; display: flex; align-items: center; justify-content: flex-end; gap: 12px;
  padding-block: 12px; padding-left: max(28px, env(safe-area-inset-left, 0px)); padding-right: max(28px, env(safe-area-inset-right, 0px));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.marca-movel { display: none; margin-right: auto; }
.marca-movel strong { font-family: var(--f-display); }
.periodo { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.periodo select { padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--r-s); background: var(--panel); }
.per-nav { display: flex; align-items: center; gap: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-s); padding: 2px; }
.per-rot { min-width: 150px; text-align: center; font-weight: 600; font-size: .92rem; }

.faixa {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin: 16px max(28px, env(safe-area-inset-right, 0px)) 0 max(28px, env(safe-area-inset-left, 0px));
  padding: 10px 14px; border-radius: var(--r); background: var(--warn-soft); color: var(--ink); font-size: .9rem;
}
.vista {
  flex: 1; display: flex; flex-direction: column; gap: 20px; outline: none;
  padding-block: 24px 40px; padding-left: max(28px, env(safe-area-inset-left, 0px)); padding-right: max(28px, env(safe-area-inset-right, 0px));
  max-width: 1320px; width: 100%;
}
.rodape { padding: 16px 28px 28px; color: var(--muted); font-size: .78rem; }
.vista-cab { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.vista-cab .sub { margin-top: 4px; }
.acoes { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 15px; border-radius: var(--r-s);
  border: 1px solid transparent; font-weight: 600; font-size: .9rem; cursor: pointer; white-space: nowrap; line-height: 1.2;
}
.btn svg { width: 17px; height: 17px; }
.btn-pri { background: var(--accent); color: var(--accent-ink); }
.btn-pri:hover { filter: brightness(1.08); }
.btn-sai { background: var(--sai); color: #fff; }
.btn-sec { background: var(--panel); border-color: var(--line); color: var(--ink); }
.btn-sec:hover { background: var(--panel-2); }
.btn-perigo { background: var(--bad); color: #fff; }
.btn-perigo-txt { background: none; color: var(--bad); border-color: transparent; padding-inline: 8px; }
.btn-bloco { width: 100%; }
.btn-peq { padding: 7px 12px; font-size: .85rem; }
.btn-icone { display: inline-grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: var(--r-s); background: none; color: var(--muted); cursor: pointer; }
.btn-icone:hover:not(:disabled) { background: var(--panel-2); color: var(--ink); }
.btn-icone:disabled { opacity: .35; cursor: default; }
.link { background: none; border: 0; color: var(--accent); font-weight: 600; font-size: .85rem; cursor: pointer; padding: 0; }
.link:hover { text-decoration: underline; }

/* ---------- Indicadores ---------- */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.kpis-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi {
  display: flex; flex-direction: column; gap: 4px; padding: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); min-width: 0;
}
.kpi-rot { font-size: .74rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.kpi-val { font-family: var(--f-body); font-weight: 700; font-size: clamp(1.15rem, .9rem + .8vw, 1.5rem); letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; }
.kpi-extra { font-size: .8rem; color: var(--muted); }
.kpi-destaque { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.kpi-destaque .kpi-rot, .kpi-destaque .kpi-extra { color: inherit; opacity: .8; }
.kpi-ent .kpi-val { color: var(--ent); }
.kpi-sai .kpi-val { color: var(--sai); }
.kpi-neg .kpi-val { color: var(--bad); }

/* ---------- Cartões ---------- */
.painel-grelha { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.cartao { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.span2 { grid-column: span 2; }
.cartao-cab { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.mini-tit { font-family: var(--f-body); font-size: .74rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-top: 4px; }
.legenda { display: flex; gap: 14px; font-size: .8rem; color: var(--muted); flex-wrap: wrap; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.dot.ent { background: var(--ent); } .dot.sai { background: var(--sai); } .dot.sal { background: var(--ink); border-radius: 50%; }

/* Gráfico */
.grafico { position: relative; min-height: 120px; }
.grafico svg { display: block; }
.ch-grid { stroke: var(--line); stroke-width: 1; }
.ch-eixo { fill: var(--muted); font-size: 11px; font-family: var(--f-body); }
.ch-ent { fill: var(--ent); }
.ch-sai { fill: var(--sai); }
.ch-saldo { stroke: var(--ink); stroke-width: 2; stroke-dasharray: 0; }
.ch-saldo-pt { fill: var(--panel); stroke: var(--ink); stroke-width: 2; }
.ch-col { cursor: pointer; }
.ch-col:hover rect:first-child { fill: var(--panel-2); }
.ch-tip {
  position: absolute; pointer-events: none; background: var(--ink); color: var(--bg); padding: 8px 10px; border-radius: var(--r-s);
  font-size: .8rem; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); white-space: nowrap; z-index: 2;
}
.ch-tip .dot.sal { background: var(--bg); }

/* Barras horizontais */
.barras { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.barras-txt { display: flex; justify-content: space-between; gap: 10px; font-size: .88rem; margin-bottom: 4px; }
.barras-txt > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barras-txt small { margin-left: 8px; font-size: .78rem; display: inline-block; min-width: 34px; text-align: right; }
.barras-trilho { height: 7px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.barras-fill { height: 100%; border-radius: 4px; background: var(--muted); }
.fill-ent { background: var(--ent); } .fill-sai { background: var(--sai); } .fill-neutro { background: color-mix(in srgb, var(--muted) 55%, var(--panel-2)); }

.ranking { list-style: none; margin: 0; padding: 0; counter-reset: rk; display: flex; flex-direction: column; }
.ranking li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); counter-increment: rk; }
.ranking li:last-child { border-bottom: 0; }
.ranking li::before { content: counter(rk); font-family: var(--f-display); font-weight: 700; color: var(--accent); width: 18px; flex: none; }
.rk-nome { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rk-nome small { font-size: .78rem; }

.duplo { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.duplo > div { display: flex; flex-direction: column; gap: 2px; padding: 12px; background: var(--panel-2); border-radius: var(--r-s); }
.duplo strong { font-size: 1.15rem; }
.duplo small { font-size: .78rem; }
.lista-pend { list-style: none; margin: 0; padding: 0; }
.lista-pend li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .88rem; cursor: pointer; }
.lista-pend li:last-child { border-bottom: 0; }
.lista-pend li > span:first-child { display: flex; flex-direction: column; min-width: 0; }
.lista-pend small { font-size: .78rem; }

.mini-dre { margin: 0; display: flex; flex-direction: column; }
.mini-dre > div { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: .9rem; border-bottom: 1px dashed var(--line); }
.mini-dre dt { color: var(--muted); }
.mini-dre dd { margin: 0; font-weight: 600; }
.mini-dre .tot { border-bottom: 1px solid var(--line); }
.mini-dre .tot dt { color: var(--ink); font-weight: 600; }
.mini-dre .fim { border-top: 2px solid var(--ink); border-bottom: 0; padding-top: 9px; }
.mini-dre .fim dd { font-size: 1.05rem; }

.alertas { display: flex; flex-direction: column; gap: 8px; }
.alerta { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: var(--r-s); font-size: .9rem; }
.alerta svg { flex: none; width: 18px; height: 18px; margin-top: 2px; }
.alerta-aviso { background: var(--warn-soft); color: var(--ink); } .alerta-aviso svg { color: var(--warn); }
.alerta-mau { background: var(--bad-soft); color: var(--ink); } .alerta-mau svg { color: var(--bad); }

/* ---------- Tabelas ---------- */
.tabela-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); }
.cartao .tabela-wrap { border: 0; border-radius: 0; margin: 0 -18px; }
.tabela { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tabela th { text-align: left; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--panel); }
.tabela td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tabela tbody tr:last-child td { border-bottom: 0; }
.tabela tbody tr[data-id] { cursor: pointer; }
.tabela tbody tr[data-id]:hover { background: var(--panel-2); }
.tabela .dir { text-align: right; }
.tabela .data { white-space: nowrap; color: var(--muted); font-size: .85rem; }
.tabela .desc { font-weight: 500; }
.tabela small { font-size: .8rem; }
.tabela small.bloco { display: block; }
.tabela tr.inactivo { opacity: .55; }
.tabela.compacta td { padding: 7px 0; }
.tabela.compacta tr td:first-child { color: var(--muted); }
.dre tr.tot td { font-weight: 700; background: var(--panel-2); }
.dre tr.tot .desc { font-family: var(--f-display); }
.dre tr.fim td { border-top: 2px solid var(--ink); font-size: 1rem; }
.mensal td, .mensal th { padding: 9px 10px; font-size: .84rem; }
.mensal tr.tot td { font-weight: 700; background: var(--panel-2); }
.mensal td:first-child, .mensal th:first-child { position: sticky; left: 0; background: var(--panel); white-space: nowrap; }
.mensal tr.tot td:first-child { background: var(--panel-2); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.pill-ok { background: var(--ent-soft); color: var(--ent); }
.pill-aviso { background: var(--warn-soft); color: var(--warn); }
.pill-mau { background: var(--bad-soft); color: var(--bad); }
.pill-neutro { background: var(--panel-2); color: var(--muted); }

.filtros { display: flex; gap: 8px; flex-wrap: wrap; }
.filtros select, .pesquisa { border: 1px solid var(--line); background: var(--panel); border-radius: var(--r-s); padding: 8px 10px; min-width: 0; }
.pesquisa { flex: 1 1 240px; display: flex; align-items: center; gap: 8px; color: var(--muted); }
.pesquisa input { border: 0; background: none; outline: none; flex: 1; min-width: 0; color: var(--ink); }
.resumo-linha { display: flex; gap: 18px; flex-wrap: wrap; font-size: .88rem; color: var(--muted); }
.resumo-linha .pos, .resumo-linha .neg { font-weight: 600; }

.estado-vazio { text-align: center; padding: 48px 20px; background: var(--panel); border: 1px dashed var(--line); border-radius: var(--r); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.estado-vazio p { color: var(--muted); max-width: 46ch; }
.nota-rodape { font-size: .8rem; color: var(--muted); }
.nota { font-size: .84rem; color: var(--muted); background: var(--panel-2); padding: 10px 12px; border-radius: var(--r-s); }
.grande { font-size: 1.8rem; font-weight: 700; letter-spacing: -0.02em; }
.explica p { color: var(--muted); max-width: 75ch; }
.explica strong { color: var(--ink); }
.fontes { font-size: .82rem; }
.fontes a { color: var(--accent); }
.regime { background: var(--accent-soft); border-color: transparent; }
.regime p { max-width: 80ch; }
.etiqueta { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--accent); }
.calendario { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 24px; }
.calendario li { display: flex; flex-direction: column; gap: 3px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.calendario li > span:last-child { display: flex; flex-direction: column; }
.cal-data { display: flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 600; color: var(--accent); }
.cal-data svg { width: 15px; height: 15px; }

/* ---------- Formulários ---------- */
.grelha-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.grelha-form > [data-mostra] { display: contents; }
.grelha-form > [data-mostra][hidden] { display: none !important; }
.campo { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.campo.largo { grid-column: 1 / -1; }
.campo label { font-size: .82rem; font-weight: 600; }
.campo label b { color: var(--bad); }
.campo input, .campo select, .campo textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-s); background: var(--panel); min-width: 0;
}
.campo input:focus, .campo select:focus, .campo textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
.campo small { font-size: .78rem; }
.campo-check { flex-direction: row; align-items: flex-start; gap: 10px; cursor: pointer; grid-column: 1 / -1; padding: 6px 0; }
.campo-check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.campo-check span { display: flex; flex-direction: column; font-size: .9rem; }
.ajuda-grupo { font-size: .82rem; color: var(--muted); background: var(--panel-2); padding: 10px 12px; border-radius: var(--r-s); }
.ajuda-grupo:empty { display: none; }

.segmento { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; background: var(--panel-2); border-radius: var(--r); }
.segmento label { cursor: pointer; position: relative; }
.segmento input { position: absolute; opacity: 0; pointer-events: none; }
.segmento span { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 9px; border-radius: var(--r-s); font-weight: 600; color: var(--muted); }
.segmento svg { width: 17px; height: 17px; }
.segmento input:checked + span { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.segmento input[value="entrada"]:checked + span { color: var(--ent); }
.segmento input[value="saida"]:checked + span { color: var(--sai); }
.segmento input:focus-visible + span { outline: 2px solid var(--accent); }
.seg-peq { padding: 3px; }
.seg-peq span { padding: 6px 12px; font-size: .85rem; }

.def { display: flex; flex-direction: column; gap: 16px; }
.regimes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.regime-op { display: flex; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r); cursor: pointer; align-items: flex-start; }
.regime-op:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.regime-op input { accent-color: var(--accent); margin-top: 3px; flex: none; }
.regime-op span { display: flex; flex-direction: column; gap: 3px; }
.regime-op small { font-size: .8rem; }
.cats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 24px; }
.cat-grupo { display: flex; flex-direction: column; gap: 6px; }
.cat-grupo h3 { display: flex; align-items: center; gap: 8px; font-family: var(--f-body); font-size: .92rem; }
.cat-grupo .sub { font-size: .8rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 11px; font-size: .83rem; cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.acoes-dados { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Janelas ---------- */
.modal-fundo {
  position: fixed; inset: 0; z-index: 50; background: rgba(10, 18, 15, .45); display: flex; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  animation: aparecer .15s ease-out;
}
.modal { background: var(--panel); border-radius: 16px; width: min(640px, 100%); max-height: 100%; display: flex; flex-direction: column; box-shadow: var(--shadow); overflow: hidden; }
.modal-peq { width: min(420px, 100%); }
.modal-form { display: flex; flex-direction: column; min-height: 0; max-height: 100%; }
.modal-cab { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-corpo { padding: 18px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-erro { margin: 0 20px; padding: 9px 12px; background: var(--bad-soft); color: var(--bad); border-radius: var(--r-s); font-size: .88rem; }
.modal-rodape { display: flex; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); align-items: center; flex-wrap: wrap; }
@keyframes aparecer { from { opacity: 0; } to { opacity: 1; } }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: .9rem; z-index: 60; transition: .2s; max-width: calc(100% - 32px);
}
.toast.visivel { opacity: 1; transform: translate(-50%, 0); }
.toast.erro { background: var(--bad); color: #fff; }

/* ---------- Navegação inferior (telemóvel) ---------- */
.nav-baixo { display: none; }
.folha-fundo { position: fixed; inset: 0; z-index: 40; background: rgba(10, 18, 15, .4); display: flex; align-items: flex-end; }
.folha {
  width: 100%; background: var(--panel); border-radius: 18px 18px 0 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  padding: 16px max(16px, env(safe-area-inset-right, 0px)) calc(84px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
.folha-item { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 6px; border: 0; background: var(--panel-2); border-radius: var(--r); font-size: .82rem; font-weight: 600; cursor: pointer; }

/* ---------- Responsivo ---------- */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpis .kpi-destaque { grid-column: span 3; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .lateral { display: none; }
  .marca-movel { display: flex; }
  .topo { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); flex-wrap: wrap; }
  .vista { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 18px 110px; }
  .faixa { margin-left: max(16px, env(safe-area-inset-left, 0px)); margin-right: max(16px, env(safe-area-inset-right, 0px)); }
  .rodape { display: none; }
  .painel-grelha, .kpis-4, .regimes, .cats, .calendario { grid-template-columns: minmax(0, 1fr); }
  .kpis-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span2 { grid-column: auto; }
  .so-largo { display: none; }
  .nav-baixo {
    display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    background: var(--panel); border-top: 1px solid var(--line);
    padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
  }
  .nav-baixo .nav-item { flex-direction: column; gap: 2px; font-size: .7rem; padding: 6px 2px; align-items: center; text-align: center; }
  .nav-baixo .nav-item.activo { background: none; }
  .nav-novo {
    justify-self: center; width: 52px; height: 52px; border-radius: 16px; border: 0; background: var(--accent); color: var(--accent-ink);
    display: grid; place-items: center; box-shadow: var(--shadow); cursor: pointer; margin-top: -18px;
  }
  .nav-novo svg { width: 26px; height: 26px; }
  .toast { bottom: calc(88px + env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis .kpi-destaque { grid-column: span 2; }
  .grelha-form { grid-template-columns: minmax(0, 1fr); }
  .per-rot { min-width: 0; font-size: .85rem; }
  .periodo { width: 100%; justify-content: space-between; }
  .per-nav { flex: 1; justify-content: space-between; }
  .vista-cab .acoes { width: 100%; }
  .vista-cab .acoes .btn { flex: 1; }
  .tabela th, .tabela td { padding: 10px; }
  .modal-fundo { align-items: flex-end; padding: 0; }
  .modal { border-radius: 18px 18px 0 0; max-height: 92%; }
  .modal-rodape { padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Histórico ---------- */
.hist-controlos { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; }
.hist-sel { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.hist-sel label { font-size: .85rem; color: var(--muted); font-weight: 600; }
.hist-sel select { padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--r-s); background: var(--panel); }
.chip-activo { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip-activo:hover { color: var(--accent-ink); }
.var { font-size: .78rem; font-weight: 600; }
.var-bom { color: var(--ent); } .var-mau { color: var(--sai); } .var-neutro { color: var(--muted); font-weight: 500; }
.historia { gap: 8px; border-left: 3px solid var(--accent); }
.historia p { max-width: 80ch; color: var(--muted); }
.historia strong { color: var(--ink); }
.ch-ant { fill: color-mix(in srgb, var(--muted) 40%, var(--panel-2)); }
.ch-act { fill: var(--accent); }
.ch-parcial { opacity: .55; }
.ch-zero { stroke: var(--muted); }
.ch-lucro { stroke: var(--warn); stroke-width: 2.2; }
.ch-lucro-pt { fill: var(--panel); stroke: var(--warn); stroke-width: 2; }
.dot.act { background: var(--accent); } .dot.ant { background: color-mix(in srgb, var(--muted) 40%, var(--panel-2)); } .dot.luc { background: var(--warn); border-radius: 50%; }
.hist-tab tbody tr[data-mes] { cursor: pointer; }
.hist-tab tbody tr[data-mes]:hover td { background: var(--panel-2); }
.hist-tab tfoot td { font-weight: 700; border-top: 2px solid var(--ink); background: var(--panel-2); }
.hist-tab tfoot td:first-child { background: var(--panel-2); }
.trims { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.trim { display: flex; flex-direction: column; gap: 3px; text-align: left; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); cursor: pointer; }
.trim:hover:not(:disabled) { border-color: var(--accent); }
.trim:disabled { cursor: default; opacity: .6; }
.trim-nome { font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.trim-val { font-size: 1.25rem; font-weight: 700; }
.trim small { font-size: .8rem; }
.trim-melhor { border-color: var(--accent); background: var(--accent-soft); }
.trim-melhor .trim-nome { color: var(--accent); }
.calor td.num { background: color-mix(in srgb, var(--accent) calc(var(--a, 0) * 100%), transparent); }
.calor td:first-child { white-space: nowrap; }
.marcos { list-style: none; margin: 0; padding: 0; }
.marcos li { display: grid; grid-template-columns: 110px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.marcos li:last-child { border-bottom: 0; }
.marco-data { color: var(--muted); font-size: .82rem; }
.marco-txt .pill { margin-right: 6px; }
@media (max-width: 900px) {
  .trims { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .marcos li { grid-template-columns: minmax(0, 1fr) auto; }
  .marco-data { grid-column: 1 / -1; }
}
.conv-info { grid-column: 1 / -1; font-size: .85rem; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 8px 12px; border-radius: var(--r-s); }

/* ---------- Tema, moeda, primeiros passos ---------- */
.btn-tema { flex: none; border: 1px solid var(--line); background: var(--panel); }
.seg-moeda { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-check { position: relative; display: inline-flex; align-items: center; cursor: pointer; padding: 0; overflow: hidden; }
.chip-check input { position: absolute; opacity: 0; pointer-events: none; }
.chip-check span { padding: 6px 12px; }
.chip-check input:checked + span { background: var(--accent); color: var(--accent-ink); }
.chip-check input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.passos { border-color: var(--accent); }
.passos-lista { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; }
.passos-lista button { width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-s); background: var(--panel); cursor: pointer; font-size: .88rem; }
.passos-lista button:hover { border-color: var(--accent); }
.visto { flex: none; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: .75rem; font-weight: 700; }
.passos-lista .feito .visto { background: var(--ent); border-color: var(--ent); color: #fff; }
.passos-lista .feito span:last-child { color: var(--muted); text-decoration: line-through; }

/* ---------- Onboarding ---------- */
.onb {
  position: fixed; inset: 0; z-index: 70; overflow-y: auto; background: var(--bg);
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
.onb-caixa { width: min(760px, 100%); margin: 0 auto; display: flex; flex-direction: column; gap: 20px; padding-block: 12px 32px; }
.onb-topo { display: flex; align-items: center; gap: 14px; }
.onb-prog { flex: 1; height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.onb-prog span { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s; }
.onb-n { font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.onb-form { display: flex; flex-direction: column; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: clamp(18px, 4vw, 32px); box-shadow: var(--shadow); }
.onb-boas { background: var(--accent-soft); color: var(--ink); padding: 10px 14px; border-radius: var(--r-s); font-size: .92rem; }
.onb-corpo { display: flex; flex-direction: column; gap: 16px; margin-top: 10px; }
.onb-perfis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.onb-moedas { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.onb-perfil, .onb-vol { position: relative; display: flex; cursor: pointer; }
.onb-perfil input, .onb-vol input { position: absolute; opacity: 0; pointer-events: none; }
.onb-perfil > span { flex: 1; display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border: 1.5px solid var(--line); border-radius: var(--r); transition: border-color .15s, background .15s; }
.onb-perfil strong { font-family: var(--f-display); font-size: 1rem; }
.onb-perfil > span > span { font-size: .87rem; color: var(--muted); }
.onb-perfil small { font-size: .78rem; }
.onb-perfil input:checked + span, .onb-vol input:checked + span { border-color: var(--accent); background: var(--accent-soft); }
.onb-perfil input:focus-visible + span, .onb-vol input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.onb-perfil:hover > span, .onb-vol:hover > span { border-color: var(--accent); }
.onb-volumes { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; }
.onb-vol > span { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: var(--r); font-size: .9rem; }
.onb-vol small { font-size: .78rem; }
.onb-sug { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border-radius: var(--r); background: var(--accent-soft); }
.onb-sug p { color: var(--ink); font-size: .9rem; }
.onb-prods { display: flex; flex-direction: column; gap: 8px; }
.onb-prod { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.onb-prod input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-s); background: var(--panel); min-width: 0; }
.onb-resumo { margin: 0; display: flex; flex-direction: column; }
.onb-resumo > div { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.onb-resumo dt { color: var(--muted); }
.onb-resumo dd { margin: 0; font-weight: 600; }
.onb-rodape { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 14px; padding-top: 16px; border-top: 1px solid var(--line); }
.onb .modal-erro { margin: 6px 0 0; }
@media (max-width: 560px) {
  .onb-perfis, .onb-moedas { grid-template-columns: minmax(0, 1fr); }
  .onb-prod { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .onb-prod input:first-child { grid-column: 1 / -1; }
  .onb-resumo > div { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .onb-exemplo { order: 3; width: 100%; }
}
@media (max-width: 900px) {
  .marca-movel { order: 0; }
  .btn-tema { order: 1; }
  .periodo { order: 2; }
}
.grafico-vazio { min-height: 120px; display: grid; place-items: center; text-align: center; border: 1px dashed var(--line); border-radius: var(--r-s); }

/* ---------- Marca Fluxca ---------- */
.df-marca { width: 36px; height: 36px; flex: none; display: block; }
.fluxca { font-family: 'Montserrat', var(--f-display); font-weight: 800; letter-spacing: -0.03em; font-size: 1.22rem; color: var(--ink); line-height: 1; }
.fluxca span { color: var(--accent); }
.marca-txt .fluxca { margin-bottom: 3px; display: block; }
.onb-topo .df-marca { width: 34px; height: 34px; }
