:root {
  --bg: #F5F7F1;
  --surface: #FFFFFF;
  --surface-2: #EEF1E8;
  --border: #DCE2D3;
  --ink: #202B20;
  --ink-muted: #5B6B57;
  --ink-faint: #8A9686;
  --accent: #3E6B4F;
  --accent-ink: #FFFFFF;
  --accent-soft: #E4EEE3;
  --gold: #A9782E;
  --gold-soft: #F4E9D6;
  --ok: #2F7D4F;
  --warn: #A9782E;
  --danger: #B24A3C;
  --shadow: 0 1px 2px rgba(32,43,32,0.06), 0 8px 24px rgba(32,43,32,0.07);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Public Sans', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
h1, h2, h3 { font-family: 'Fraunces', Georgia, serif; font-weight: 600; margin: 0; }
a { color: var(--accent); }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.9rem 1.6rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .marca { display: flex; align-items: center; gap: 0.7rem; text-decoration: none; }
.topbar .marca img { height: 44px; width: 44px; display: block; }
.marca-nome { font-family: 'Fraunces', Georgia, serif; font-size: 1.45rem; font-weight: 600; color: #2A588D; white-space: nowrap; letter-spacing: -0.01em; }
.marca-sub { font-family: 'Public Sans', system-ui, sans-serif; font-size: 0.95rem; font-weight: 500; color: var(--ink-muted); letter-spacing: 0; }
.topbar nav { display: flex; gap: 1.2rem; align-items: center; font-size: 0.92rem; }
.topbar nav > a { text-decoration: none; color: var(--ink); font-weight: 500; }
.topbar nav > a.ativo, .menu-topo > summary.ativo { color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
.menu-topo { position: relative; }
.menu-topo > summary {
  list-style: none; cursor: pointer; font-weight: 500; color: var(--ink); padding: 0.3rem 0; user-select: none;
}
.menu-topo > summary::-webkit-details-marker { display: none; }
.menu-topo > summary::after { content: ""; display: inline-block; margin-left: 0.35rem; border: 4px solid transparent; border-top-color: currentColor; vertical-align: -1px; }
.menu-topo[open] > summary::after { border-top-color: transparent; border-bottom-color: currentColor; vertical-align: 3px; }
.menu-topo .submenu {
  position: absolute; top: calc(100% + 0.5rem); left: -0.8rem; z-index: 40; min-width: 210px;
  display: flex; flex-direction: column; padding: 0.4rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
}
.menu-topo .submenu a { padding: 0.5rem 0.7rem; border-radius: 6px; text-decoration: none; color: var(--ink); }
.menu-topo .submenu a:hover { background: var(--surface-2); color: var(--accent); }
.titulo-folha { margin: 0.6rem 0 0.1rem; padding: 0 0.9rem; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint); }
.topbar .user { color: var(--ink-muted); font-size: 0.88rem; }

main.conteudo { max-width: 1180px; margin: 0 auto; padding: 2rem 1.6rem 4rem; }

.cabecalho-pagina { margin-bottom: 1.4rem; }
.cabecalho-pagina p { color: var(--ink-muted); margin: 0.2rem 0 0; max-width: 60ch; }
.cabecalho-com-acao { display: flex; align-items: flex-start; justify-content: space-between; gap: 1.2rem; flex-wrap: wrap; }

.painel-filtros {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 1.2rem 1.4rem; box-shadow: var(--shadow); margin-bottom: 1.4rem;
}
.filtros-grelha {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.9rem;
  align-items: end;
}
.campo-filtro label {
  display: block; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--ink-faint); margin-bottom: 0.3rem;
}
.campo-filtro select, .campo-filtro input {
  width: 100%; padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--ink); font-size: 0.9rem;
}
.acoes-filtro { display: flex; gap: 0.6rem; }
.botao {
  border: none; border-radius: 8px; padding: 0.5rem 1rem; font-size: 0.88rem; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: 500;
}
.botao.secundario { background: var(--surface-2); color: var(--ink); }

.resumo-totais { display: flex; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.cartao-total {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.8rem 1.1rem; min-width: 170px;
}
.cartao-total .rotulo { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-faint); }
.cartao-total .valor { font-family: 'Fraunces', serif; font-size: 1.25rem; margin-top: 0.15rem; }
.cartao-total.alerta .valor { color: var(--warn); }

.tabela-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
table.documentos { border-collapse: collapse; width: 100%; font-size: 0.9rem; min-width: 760px; }
table.documentos th, table.documentos td { text-align: left; padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--border); }
table.documentos th { background: var(--surface-2); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-faint); font-weight: 500; }
table.documentos td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.documentos tr:last-child td { border-bottom: none; }
table.documentos tr:hover td { background: var(--surface-2); }
table.documentos th a { color: inherit; text-decoration: none; white-space: nowrap; cursor: pointer; }
table.documentos th a:hover { color: var(--ink); text-decoration: underline; }

.pill { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.76rem; padding: 0.15rem 0.55rem; border-radius: 999px; font-weight: 500; }
.pill.pago, .pill.ativo, .pill.cruzado { background: var(--accent-soft); color: var(--ok); }
.pill.nao_pago, .pill.nao_cruzado, .pill.em_falta_na_bd { background: var(--gold-soft); color: var(--warn); }
.pill.parcial, .pill.inativo, .pill.ignorado, .pill.em_falta_no_efatura { background: #EDEEE4; color: var(--ink-muted); }
.pill.ocr { background: #FBEFE0; color: var(--warn); border: 1px dashed var(--warn); margin-left: 0.35rem; }
.pill.outra-entidade { background: #F7E4E0; color: var(--danger); border: 1px solid var(--danger); margin-left: 0.35rem; }

.valor-credito { color: var(--ok); }
.valor-debito { color: var(--ink); }

.vazio { padding: 2.4rem; text-align: center; color: var(--ink-faint); }

/* Categorias */
.swatch {
  display: inline-block; width: 0.65rem; height: 0.65rem; border-radius: 50%;
  margin-right: 0.5rem; border: 1px solid rgba(0,0,0,0.08); vertical-align: middle;
}
table.categorias td.linha-subcategoria { padding-left: 2.2rem; color: var(--ink-muted); }
td.acoes-col { text-align: right; white-space: nowrap; }
.acoes-linha { display: inline-flex; align-items: center; gap: 0.8rem; }
.acoes-linha form { margin: 0; }
.botao-link {
  background: none; border: none; padding: 0; margin: 0; color: var(--accent);
  font-size: inherit; font-family: inherit; cursor: pointer; text-decoration: underline;
}
.campo-caixa { display: flex; align-items: center; }
.campo-caixa input[type="checkbox"] { width: auto; margin-right: 0.4rem; }

/* Associação manual de pagamento (comprovativo ↔ fatura, movimento ↔ fatura) */
.lista-selecao { list-style: none; margin: 0; padding: 0.4rem 0; max-height: 420px; overflow-y: auto; }
.lista-selecao li { border-bottom: 1px solid var(--border); }
.lista-selecao li:last-child { border-bottom: none; }
.lista-selecao label { display: flex; align-items: center; gap: 0.6rem; padding: 0.55rem 0.2rem; margin: 0; cursor: pointer; font-size: 0.9rem; }
.lista-selecao input[type="checkbox"] { width: auto; }
.sugestao-fornecedor { background: var(--accent-soft); color: var(--ok); border-radius: 8px; padding: 0.6rem 0.9rem; font-size: 0.88rem; margin-bottom: 1rem; }

/* Estatísticas */
.grelha-tabelas {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.4rem;
}
.barra-evolucao { display: flex; flex-direction: column; gap: 0.55rem; }
.linha-barra {
  display: grid; grid-template-columns: 42px 1fr 90px; align-items: center; gap: 0.8rem;
}
.linha-barra .rotulo-barra { font-size: 0.8rem; color: var(--ink-muted); }
.linha-barra .trilho { background: var(--surface-2); border-radius: 6px; height: 10px; overflow: hidden; }
.linha-barra .preenchimento { background: var(--accent); height: 100%; border-radius: 6px; }
.linha-barra .valor-barra { text-align: right; font-variant-numeric: tabular-nums; font-size: 0.84rem; color: var(--ink-muted); }

.form-login {
  max-width: 340px; margin: 4rem auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 2rem; box-shadow: var(--shadow);
}
.form-login .logo-login { display: block; height: 44px; width: auto; margin: 0 auto 1.6rem; }
.form-login h1 { font-size: 1.4rem; margin-bottom: 1.2rem; text-align: center; }
.form-login label { display: block; font-size: 0.8rem; color: var(--ink-muted); margin: 0.8rem 0 0.3rem; }
.form-login input { width: 100%; padding: 0.55rem 0.7rem; border: 1px solid var(--border); border-radius: 8px; }
.form-login button { margin-top: 1.2rem; width: 100%; }

/* Importar por foto — botão grande que abre logo a câmara traseira */
.botao-camara {
  display: flex; align-items: center; justify-content: center; width: 100%;
  padding: 0.9rem 1rem; font-size: 1rem; margin-bottom: 0.4rem; text-align: center;
}
.entrada-camara { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.estado-camara { font-size: 0.88rem; color: var(--ink-muted); margin: 0 0 1rem; min-height: 1.2em; }

/* Telemóvel (e webapp instalada no ecrã principal) */
@media (max-width: 720px) {
  .topbar {
    flex-direction: column; align-items: stretch; gap: 0.6rem;
    padding: calc(0.7rem + env(safe-area-inset-top)) 16px 0.6rem;
  }
  .topbar .marca img { height: 34px; width: 34px; }
  .marca-nome { font-size: 1.2rem; }
  .marca-sub { font-size: 0.82rem; }
  .topbar nav {
    gap: 1rem; overflow-x: auto; white-space: nowrap; padding-bottom: 0.2rem;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .topbar nav::-webkit-scrollbar { display: none; }
  main.conteudo { padding: 1.2rem 16px calc(3rem + env(safe-area-inset-bottom)); }
  .painel-filtros { padding: 1rem; }
  /* 16px evita que o iPhone faça zoom ao tocar num campo */
  .campo-filtro select, .campo-filtro input, .form-login input { font-size: 16px; }
  .botao { padding: 0.65rem 1rem; font-size: 0.95rem; }
  .form-login { margin: 2rem auto; padding: 1.4rem; }
  .grelha-tabelas { grid-template-columns: 1fr; }
}

/* Documento: ver e corrigir */
.voltar { margin: 0 0 0.4rem; font-size: 0.9rem; }
.etiquetas { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.5rem; }
.etiquetas .pill { margin-left: 0; }
.documento-grelha { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 1.4rem; align-items: start; }
.pre-visualizacao img { display: block; width: 100%; height: auto; border-radius: 8px; background: var(--surface-2); }
.pre-visualizacao iframe { width: 100%; height: 75vh; border: 0; border-radius: 8px; background: var(--surface-2); }
.ligacoes-ficheiro { font-size: 0.88rem; margin: 0.7rem 0 0; color: var(--ink-muted); }
.grelha-campos { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0.9rem; }
.erro-campo, .erro-formulario { color: var(--danger); font-size: 0.85rem; margin: 0.3rem 0 0; }
.erro-formulario { margin: 0 0 0.8rem; }
.aviso-formulario { background: var(--gold-soft); color: var(--warn); border-radius: 8px; padding: 0.6rem 0.8rem; font-size: 0.88rem; margin: 0 0 0.9rem; }
.titulo-seccao { font-size: 1rem; margin-bottom: 0.5rem; }
.lista-simples { margin: 0; padding-left: 1.1rem; font-size: 0.9rem; }
.zona-apagar { margin: 0.4rem 0 2rem; }
.botao.perigo { background: #F7E4E0; color: var(--danger); }
.faixa-importado {
  display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; flex-wrap: wrap;
  background: var(--accent-soft); color: var(--ok); border-radius: 12px; padding: 0.8rem 1rem; margin-bottom: 1.2rem;
}
.faixa-importado p { margin: 0; }
.pill.efatura { background: var(--accent-soft); color: var(--ok); }
a.botao { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
@media (max-width: 900px) {
  .documento-grelha { grid-template-columns: 1fr; }
  .pre-visualizacao img { max-height: 42vh; object-fit: contain; }
  .pre-visualizacao iframe { height: 60vh; }
}

/* Lista de documentos: linhas clicáveis, coluna e-Fatura, cartões no telemóvel */
table.documentos tr.linha-clicavel { cursor: pointer; }
table.documentos td a { text-decoration: none; }
table.documentos th.centro, table.documentos td.centro { text-align: center; }
.check-efatura {
  display: inline-flex; align-items: center; justify-content: center; width: 1.45rem; height: 1.45rem;
  border-radius: 50%; background: var(--ok); color: #fff; font-weight: 700; font-size: 0.85rem; line-height: 1;
}
.so-telemovel { display: none; }
.cartoes-documentos { list-style: none; margin: 0; padding: 0; flex-direction: column; gap: 0.6rem; }
.cartao-documento {
  display: block; background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 0.85rem 1rem; color: var(--ink); text-decoration: none; box-shadow: var(--shadow);
}
.cartao-documento:active { background: var(--surface-2); }
.cartao-linha { display: flex; justify-content: space-between; align-items: center; gap: 0.8rem; }
.cartao-fornecedor { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cartao-valor { font-family: 'Fraunces', Georgia, serif; font-size: 1.1rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cartao-secundaria { color: var(--ink-muted); font-size: 0.86rem; margin-top: 0.15rem; }
.cartao-documento .etiquetas { margin-top: 0.45rem; }
@media (max-width: 720px) {
  .so-computador { display: none; }
  .so-telemovel { display: flex; }
}

/* Ecrã de espera ("A ler a fatura…") enquanto a foto é enviada */
.espera {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: rgba(245, 247, 241, 0.94);
}
.espera[hidden] { display: none; }
.espera-caixa { text-align: center; padding: 1.5rem; }
.roda {
  width: 46px; height: 46px; margin: 0 auto 0.9rem; border-radius: 50%;
  border: 4px solid var(--accent-soft); border-top-color: var(--accent); animation: rodar 0.9s linear infinite;
}
@keyframes rodar { to { transform: rotate(360deg); } }
.espera-texto { margin: 0; font-size: 1.02rem; }

/* Telemóvel como uma app: barra de separadores em baixo, câmara ao centro */
.barra-inferior, .form-camara-global, .alternar-filtros { display: none; }
@media (max-width: 720px) {
  .topbar {
    flex-direction: row; justify-content: center; position: sticky; top: 0; z-index: 20;
    padding: calc(0.55rem + env(safe-area-inset-top)) 16px 0.55rem;
  }
  .topbar nav { display: none; }
  .barra-inferior {
    display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 0.3rem 0.25rem calc(0.3rem + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 16px rgba(32, 43, 32, 0.06);
  }
  .barra-inferior > a, .barra-inferior summary {
    display: flex; flex-direction: column; align-items: center; gap: 0.12rem; padding: 0.3rem 0;
    font-size: 0.68rem; color: var(--ink-muted); text-decoration: none; list-style: none; cursor: pointer;
    -webkit-tap-highlight-color: transparent; user-select: none;
  }
  .barra-inferior summary::-webkit-details-marker { display: none; }
  .barra-inferior svg {
    width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8;
    stroke-linecap: round; stroke-linejoin: round;
  }
  .barra-inferior .ativo { color: var(--accent); font-weight: 600; }
  .botao-camara-central {
    justify-self: center; align-self: center; width: 60px; height: 60px; margin-top: -26px;
    display: flex; align-items: center; justify-content: center; border-radius: 50%; cursor: pointer;
    background: var(--accent); box-shadow: 0 6px 16px rgba(62, 107, 79, 0.35); -webkit-tap-highlight-color: transparent;
  }
  .botao-camara-central svg { width: 28px; height: 28px; stroke: #fff; }
  .botao-camara-central:active { transform: scale(0.94); }
  .menu-mais { position: relative; display: flex; justify-content: center; }
  .folha-mais {
    position: absolute; right: 0.4rem; bottom: calc(100% + 0.7rem); min-width: 240px; padding: 0.4rem;
    display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; box-shadow: var(--shadow);
  }
  .folha-mais a, .folha-mais button {
    display: block; width: 100%; padding: 0.8rem 0.9rem; border: 0; border-radius: 10px; background: none;
    font: inherit; font-size: 0.95rem; color: var(--ink); text-align: left; text-decoration: none;
  }
  .folha-mais a:active, .folha-mais button:active { background: var(--surface-2); }
  .folha-mais form { margin: 0.3rem 0 0; padding-top: 0.3rem; border-top: 1px solid var(--border); }
  main.conteudo { padding-bottom: calc(6.5rem + env(safe-area-inset-bottom)); }
  .cabecalho-pagina h1 { font-size: 1.5rem; }
  .cabecalho-pagina p { font-size: 0.92rem; }
  .alternar-filtros { display: flex; width: 100%; margin-bottom: 0.8rem; }
  .painel-filtros.recolhivel:not(.aberto) { display: none; }
  .resumo-totais { gap: 0.5rem; }
  .cartao-total { min-width: 0; flex: 1 1 30%; padding: 0.6rem 0.7rem; }
  .cartao-total .rotulo { font-size: 0.62rem; }
  .cartao-total .valor { font-size: 1.02rem; }
}

/* Intracomunitárias e observações */
.na-efatura { font-size: 0.72rem; color: var(--ink-faint); border: 1px solid var(--border); border-radius: 999px; padding: 0.05rem 0.45rem; }
.pill.intracom { background: #E6ECF5; color: #3A5A8C; }
.icone-obs { font-size: 0.8rem; margin-left: 0.2rem; cursor: help; }
.cartao-obs { font-size: 0.82rem; color: var(--ink-muted); margin-top: 0.35rem; }
.obs-documento { background: var(--surface-2); border-radius: 8px; padding: 0.55rem 0.8rem; font-size: 0.9rem; margin: 0.7rem 0 0; max-width: 70ch; }
.grelha-campos .campo-largo { grid-column: 1 / -1; }
.grelha-campos textarea { width: 100%; padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: 8px; font: inherit; font-size: 0.9rem; }
.grelha-campos .campo-caixa label { display: flex; align-items: center; gap: 0.5rem; text-transform: none; letter-spacing: 0; font-size: 0.88rem; color: var(--ink); }

/* Por lançar */
.lista-por-lancar { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.8rem; }
.lista-por-lancar li { display: flex; gap: 1rem; align-items: center; margin: 0; }
.miniatura { flex: 0 0 90px; height: 110px; border-radius: 8px; overflow: hidden; background: var(--surface-2); display: flex; align-items: center; justify-content: center; text-decoration: none; }
.miniatura img { width: 100%; height: 100%; object-fit: cover; }
.miniatura-pdf { font-weight: 700; color: var(--ink-muted); }
.por-lancar-info { display: flex; flex-direction: column; gap: 0.6rem; min-width: 0; }
.por-lancar-info strong { overflow-wrap: anywhere; }
.por-lancar-info form { margin: 0; }

/* Definições */
.grelha-definicoes { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }
.cartao-definicao {
  display: flex; flex-direction: column; gap: 0.35rem; padding: 1.1rem 1.2rem; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); color: var(--ink); text-decoration: none;
}
.cartao-definicao:hover { border-color: var(--accent); }
.cartao-definicao span { color: var(--ink-muted); font-size: 0.9rem; }
.ajuda-campo { font-size: 0.8rem; color: var(--ink-faint); margin: 0.3rem 0 0; }
.historico { margin-top: 0; }

/* ---------- Categorias agrupadas ---------- */
.titulo-grupo { font-size: 1.1rem; margin: 1.4rem 0 0.6rem; }
.titulo-grupo:first-of-type { margin-top: 0; }

/* ---------- Fluxo de caixa ---------- */
.acoes-cabecalho { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.valor-negativo { color: var(--danger); }
.cartao-total.alerta { border-color: var(--danger); }
.cartao-grafico {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 1rem 1rem 0.4rem; margin-bottom: 1.4rem;
}
.legenda-grafico { display: flex; gap: 1.1rem; flex-wrap: wrap; font-size: 0.82rem; color: var(--ink-muted); margin-bottom: 0.4rem; }
.legenda-grafico .chave { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 0.35rem; vertical-align: -1px; }
.chave.receita { background: #7FAE8A; }
.chave.despesa { background: #D39A8E; }
.chave.saldo { background: var(--ink); height: 3px; vertical-align: 3px; }
.grafico-fluxo { width: 100%; height: auto; display: block; }
.grafico-fluxo .grelha { stroke: var(--border); stroke-width: 1; }
.grafico-fluxo .grelha.zero { stroke: var(--ink-faint); }
.grafico-fluxo .eixo { font-size: 11px; fill: var(--ink-faint); font-family: 'Public Sans', system-ui, sans-serif; }
.grafico-fluxo .barra.receita { fill: #7FAE8A; }
.grafico-fluxo .barra.despesa { fill: #D39A8E; }
.grafico-fluxo .alvo { fill: transparent; }
.grafico-fluxo .mes:hover .alvo { fill: var(--surface-2); }
.grafico-fluxo .linha-saldo { fill: none; stroke: var(--ink); stroke-width: 2.2; stroke-linejoin: round; pointer-events: none; }
.grafico-fluxo .ponto-saldo { fill: var(--surface); stroke: var(--ink); stroke-width: 1.6; pointer-events: none; }
.grafico-fluxo .ponto-saldo.negativo { stroke: var(--danger); fill: var(--danger); }

.tabela-fluxo-wrap { max-height: 75vh; }
table.tabela-fluxo { border-collapse: separate; border-spacing: 0; font-size: 0.8rem; white-space: nowrap; }
.tabela-fluxo th, .tabela-fluxo td { padding: 0.32rem 0.55rem; border-bottom: 1px solid var(--surface-2); }
.tabela-fluxo thead th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2); font-weight: 600; font-size: 0.74rem;
  text-transform: uppercase; letter-spacing: 0.03em; color: var(--ink-muted);
}
.tabela-fluxo .num { text-align: right; font-variant-numeric: tabular-nums; }
.tabela-fluxo .col-categoria {
  position: sticky; left: 0; z-index: 1; background: var(--surface); text-align: left; font-weight: 500;
  min-width: 190px; max-width: 240px; overflow: hidden; text-overflow: ellipsis;
}
.tabela-fluxo thead .col-categoria { z-index: 3; background: var(--surface-2); }
.tabela-fluxo .col-categoria a { color: var(--ink); text-decoration: none; border-bottom: 1px dotted var(--ink-faint); }
.tabela-fluxo .col-categoria a:hover { color: var(--accent); }
.tabela-fluxo .col-comparacao { text-align: left; }
.tabela-fluxo .col-total { font-weight: 600; background: var(--surface-2); }
.tabela-fluxo .linha-sub .col-categoria { padding-left: 1.5rem; font-weight: 400; }
.tabela-fluxo .linha-grupo th, .tabela-fluxo .linha-grupo td { font-weight: 600; background: #F8FAF5; }
.tabela-fluxo .linha-grupo .col-categoria { background: #F8FAF5; }
.tabela-fluxo .linha-seccao th, .tabela-fluxo .linha-seccao td {
  background: var(--accent-soft); color: var(--accent); text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.74rem; font-weight: 700;
}
.tabela-fluxo .linha-total th, .tabela-fluxo .linha-total td { font-weight: 700; border-top: 2px solid var(--border); background: var(--surface-2); }
.tabela-fluxo .linha-saldo-mes th, .tabela-fluxo .linha-saldo-mes td { font-weight: 600; }
.tabela-fluxo .linha-caixa th, .tabela-fluxo .linha-caixa td { font-weight: 700; background: var(--gold-soft); border-top: 2px solid var(--gold); }
.tabela-fluxo td.origem-manual, .origem-exemplo.origem-manual { color: #3A5A8C; font-weight: 600; }
.tabela-fluxo td.origem-orcamento, .origem-exemplo.origem-orcamento { color: var(--ink); }
.tabela-fluxo td.origem-sugestao, .origem-exemplo.origem-sugestao { color: var(--ink-muted); font-style: italic; }
.tabela-fluxo .vazio-linha { color: var(--ink-faint); font-weight: 400; }
.pill.comparacao-ok { background: var(--accent-soft); color: var(--ok); }
.pill.comparacao-acima, .pill.comparacao-abaixo { background: var(--gold-soft); color: var(--warn); }
.pill.comparacao-novo { background: #E6ECF5; color: #3A5A8C; }
.pill.comparacao-sem_dados { background: transparent; color: var(--ink-faint); }
.pill.comparacao-distribuicao { background: #EDE6F2; color: #6A4C82; margin-left: 0.2rem; }
.nota-rodape { font-size: 0.8rem; color: var(--ink-muted); margin-top: 0.6rem; }
.origem-exemplo { padding: 0 0.2rem; }
.grelha-meses { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.8rem; }
.dica-automatico { display: block; font-size: 0.74rem; color: var(--ink-faint); margin-top: 0.2rem; }
@media (max-width: 720px) {
  .tabela-fluxo .col-categoria { min-width: 130px; max-width: 150px; }
  .grelha-meses { grid-template-columns: repeat(2, 1fr); }
}
.tabela-orcamento { width: 100%; }
.tabela-orcamento .entrada-valor { width: 8.5rem; text-align: right; padding: 0.3rem 0.45rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; }
.tabela-orcamento .variacao { color: var(--ink-muted); font-size: 0.78rem; }
.form-criar-orcamento { display: flex; gap: 0.5rem; }
.form-criar-orcamento input { width: 6rem; padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: 8px; font: inherit; }
@media (max-width: 720px) {
  .cartao-grafico { overflow-x: auto; }
  .grafico-fluxo { min-width: 680px; }
}

/* ---------- Trabalhadores ---------- */
.grelha-trabalhadores { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 0.9rem; }
.cartao-trabalhador {
  display: flex; gap: 0.9rem; align-items: center; padding: 0.9rem 1rem; text-decoration: none; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.cartao-trabalhador:hover { border-color: var(--accent); }
.cartao-trabalhador.inativo { opacity: 0.6; }
.dados-trabalhador { display: flex; flex-direction: column; gap: 0.1rem; font-size: 0.86rem; color: var(--ink-muted); min-width: 0; }
.dados-trabalhador strong { color: var(--ink); font-size: 1rem; }
.dados-trabalhador .custo { font-size: 0.8rem; }
.foto-trabalhador { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; flex: none; }
.foto-trabalhador.grande { width: 110px; height: 110px; }
.foto-trabalhador.sem-foto {
  display: inline-flex; align-items: center; justify-content: center; background: var(--accent-soft); color: var(--accent);
  font-family: 'Fraunces', serif; font-size: 1.4rem; font-weight: 600;
}
.foto-trabalhador.grande.sem-foto { font-size: 2.4rem; }
.bloco-foto { display: flex; gap: 1.2rem; align-items: center; flex-wrap: wrap; }
.ficha-trabalhador fieldset { border: 1px solid var(--border); }
.ficha-trabalhador legend { padding: 0 0.4rem; }
.campo-largo { grid-column: 1 / -1; }
.erro-campo { color: var(--danger); font-size: 0.82rem; margin: 0.2rem 0 0; }

/* ---------- Sócios ---------- */
.saldo-socio { font-family: 'Fraunces', serif; font-size: 1.1rem; color: var(--ink); }
.saldo-socio.credor { color: var(--ok); }
.saldo-socio.devedor { color: var(--danger); }
.tabela-conta .linha-anulada td { color: var(--ink-faint); }
.tabela-conta .registo { font-size: 0.78rem; color: var(--ink-faint); white-space: nowrap; }
.opcoes-sentido { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.8rem; }
.opcoes-sentido label { text-transform: none; letter-spacing: 0; font-size: 0.9rem; color: var(--ink); }
.form-em-linha { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.form-em-linha select { padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: 8px; font: inherit; min-width: 12rem; }

/* ---------- Fornecedores ---------- */
.grelha-ficha { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1.2rem; align-items: start; }
.grelha-ficha > .painel-filtros { margin-bottom: 0; }
.iban { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }
.lista-ibans li { margin-bottom: 0.35rem; }
.entrada-pesquisa { padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: 8px; font: inherit; min-width: 12rem; }
@media (max-width: 860px) { .grelha-ficha { grid-template-columns: 1fr; } }

/* ---------- Cobertura do e-Fatura ---------- */
.mapa-cobertura { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 0.35rem; margin-bottom: 1rem; }
.mes-cobertura { text-align: center; padding: 0.35rem 0.2rem; border-radius: 6px; font-size: 0.78rem; font-weight: 500; }
.mes-cobertura.coberto { background: var(--accent-soft); color: var(--ok); }
.mes-cobertura.em-falta { background: var(--gold-soft); color: var(--warn); border: 1px dashed var(--warn); }
.mes-cobertura.antes { background: var(--surface-2); color: var(--ink-faint); }
.marca-bloco { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 1.4rem; }
.marca-bloco.centrada { justify-content: center; flex-wrap: wrap; text-align: center; }
.marca-bloco .marca-nome { font-size: 1.6rem; }

/* ---------- Frota ---------- */
.painel-alertas { background: #FBF3EC; border: 1px solid #E8C9B8; border-radius: 12px; padding: 0.9rem 1.2rem; margin-bottom: 1.2rem; }
.painel-alertas ul { margin: 0.3rem 0 0; padding-left: 1.1rem; }
.painel-alertas li { margin-bottom: 0.3rem; }
.painel-alertas li.alerta-vencida { color: var(--danger); }
.painel-alertas li.alerta-breve { color: var(--warn); }
.matricula { display: inline-block; font-family: ui-monospace, Menlo, monospace; font-size: 0.78em; padding: 0.05rem 0.4rem; border: 1px solid var(--ink-faint); border-radius: 4px; background: var(--surface); color: var(--ink); vertical-align: 2px; }
.linha-inativa td { color: var(--ink-faint); }
.form-viatura select, .form-viatura input { padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: 8px; font: inherit; }

/* ---------- Calendário agrícola ---------- */
.grelha-calendario-pagina { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 1.2rem; align-items: start; }
.navegacao-mes { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.7rem; }
.navegacao-mes h2 { font-size: 1.3rem; min-width: 11rem; text-align: center; }
.calendario-mes {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); background: var(--border); gap: 1px;
  border: 1px solid var(--border); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow);
}
.cabecalho-dia { background: var(--surface-2); padding: 0.35rem; text-align: center; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-muted); }
.dia { background: var(--surface); min-height: 96px; padding: 0.3rem; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.dia.fora { background: #FAFBF8; }
.dia.fora .numero-dia { color: var(--ink-faint); }
.dia.hoje .numero-dia { background: var(--accent); color: #fff; }
.numero-dia { align-self: flex-start; font-size: 0.8rem; font-weight: 600; color: var(--ink); text-decoration: none; padding: 0 0.35rem; border-radius: 999px; line-height: 1.5; }
.numero-dia:hover { background: var(--surface-2); }
.evento { display: block; font-size: 0.72rem; line-height: 1.3; padding: 0.1rem 0.3rem; border-radius: 4px; text-decoration: none; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 3px solid var(--ink-faint); background: var(--surface-2); }
.evento.concluida { text-decoration: line-through; opacity: 0.6; }
.tipo-sementeira { --cor: #5E8C3A; } .tipo-colheita { --cor: #C9962B; } .tipo-tratamento { --cor: #3A7C8C; }
.tipo-gado { --cor: #8C5A3A; } .tipo-cortica { --cor: #A0522D; } .tipo-montanheira { --cor: #6B4E8C; }
.tipo-lenha { --cor: #7A6A3A; } .tipo-manutencao { --cor: #5B6B57; } .tipo-administrativo { --cor: #2A588D; }
.tipo-frota { --cor: #B24A3C; } .tipo-outro { --cor: #8A9686; }
.evento[class*="tipo-"] { border-left-color: var(--cor); background: color-mix(in srgb, var(--cor) 12%, white); }
.lista-proximas { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.6rem; font-size: 0.88rem; }
.lista-proximas li { display: flex; gap: 0.5rem; align-items: flex-start; }
.lista-proximas small { color: var(--ink-muted); }
.ponto { width: 10px; height: 10px; border-radius: 50%; background: var(--cor, var(--ink-faint)); flex: none; margin-top: 0.35rem; }
@media (max-width: 860px) {
  .grelha-calendario-pagina { grid-template-columns: 1fr; }
  .dia { min-height: 64px; }
  .evento { font-size: 0.64rem; padding: 0.05rem 0.2rem; }
}
