/* N-Restauros Finanças — estilos */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #1e293b;
  --muted: #5b6b80;
  --border: #dfe5ec;
  --primary: #1d4ed8;
  --primary-text: #ffffff;
  --nr: #2563eb;
  --fr: #047857;
  --pos: #157a3b;
  --pos-bg: #e8f6ee;
  --neg: #b42318;
  --neg-bg: #fdecea;
  --warn: #9a5b00;
  --warn-bg: #fff4e0;
  --info-bg: #eaf1ff;
  --sombra: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --raio: 10px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tema="claro"]) {
    --bg: #0f1520; --surface: #172030; --surface-2: #1c2738; --text: #e6ebf2; --muted: #9fb0c6; --border: #2b394d;
    --primary: #4f80ff; --nr: #6b9bff; --fr: #34d399; --pos: #4ade80; --pos-bg: #13301f; --neg: #ff7a6b; --neg-bg: #3a1714;
    --warn: #fbbf24; --warn-bg: #3a2a0c; --info-bg: #182a4a; --sombra: none; color-scheme: dark;
  }
}
:root[data-tema="escuro"] {
  --bg: #0f1520; --surface: #172030; --surface-2: #1c2738; --text: #e6ebf2; --muted: #9fb0c6; --border: #2b394d;
  --primary: #4f80ff; --nr: #6b9bff; --fr: #34d399; --pos: #4ade80; --pos-bg: #13301f; --neg: #ff7a6b; --neg-bg: #3a1714;
  --warn: #fbbf24; --warn-bg: #3a2a0c; --info-bg: #182a4a; --sombra: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--primary); }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 1.4rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
p { margin: .4rem 0; }
.carregar { padding: 2rem; color: var(--muted); }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/* Cabeçalho */
.topo { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--sombra); }
.topo-linha { display: flex; align-items: center; gap: .75rem; padding: .5rem 1rem; flex-wrap: wrap; }
.marca { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; }
.marca img { width: 28px; height: 28px; }
.menu { display: flex; gap: .15rem; flex-wrap: wrap; flex: 1; }
.menu a { padding: .4rem .6rem; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; white-space: nowrap; }
.menu a:hover { background: var(--surface-2); color: var(--text); }
.menu a.ativo { background: var(--info-bg); color: var(--primary); }
.menu .contador { display: inline-block; min-width: 1.3rem; padding: 0 .35rem; margin-left: .25rem; border-radius: 99px; background: var(--neg); color: #fff; font-size: .75rem; text-align: center; }
.topo-direita { display: flex; align-items: center; gap: .5rem; }
.botao-menu { display: none; }
@media (max-width: 900px) {
  .botao-menu { display: inline-flex; }
  .menu { display: none; flex-basis: 100%; flex-direction: column; }
  .menu.aberto { display: flex; }
}

main { max-width: 1400px; margin: 0 auto; padding: 1rem; }
.cabecalho-ecra { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.cabecalho-ecra .sub { color: var(--muted); }
.acoes { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* Botões e campos */
button, .botao { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: .45rem .8rem; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: .35rem; min-height: 36px; }
button:hover, .botao:hover { background: var(--surface-2); }
button.primario, .botao.primario { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
button.primario:hover { filter: brightness(1.08); }
button.perigo { color: var(--neg); border-color: var(--neg); }
button.pequeno { padding: .2rem .5rem; min-height: 28px; font-size: .85rem; }
button.ligacao { border: 0; background: none; color: var(--primary); padding: 0; min-height: 0; text-decoration: underline; }
button:disabled { opacity: .55; cursor: not-allowed; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .45rem .6rem; min-height: 36px; max-width: 100%; }
textarea { min-height: 110px; width: 100%; resize: vertical; }
label { display: block; font-weight: 600; font-size: .88rem; margin: .6rem 0 .25rem; }
label .opcional { font-weight: 400; color: var(--muted); }
.campo { margin-bottom: .2rem; }
.campos { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 1rem; }
.filtros { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; margin-bottom: .8rem; background: var(--surface); padding: .7rem; border: 1px solid var(--border); border-radius: var(--raio); }
.filtros label { margin: 0 0 .15rem; font-size: .78rem; color: var(--muted); }
.erro-campo { color: var(--neg); font-size: .85rem; }

/* Cartões e tabelas */
.cartao { background: var(--surface); border: 1px solid var(--border); border-radius: var(--raio); padding: 1rem; box-shadow: var(--sombra); }
.grelha { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.kpi .rotulo { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.kpi .valor { font-size: 1.45rem; font-weight: 700; margin-top: .2rem; font-variant-numeric: tabular-nums; }
.empresa-cartao { border-top: 4px solid var(--cor, var(--primary)); }
.tabela-envolve { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--raio); }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: .45rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: var(--surface-2); font-size: .8rem; color: var(--muted); font-weight: 600; position: sticky; top: 0; z-index: 1; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
tfoot td { font-weight: 700; background: var(--surface-2); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.zero { color: var(--muted); }
.vazio { padding: 1.5rem; text-align: center; color: var(--muted); }
.etiqueta { display: inline-block; padding: .05rem .45rem; border-radius: 99px; font-size: .75rem; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.etiqueta.alta { background: var(--pos-bg); color: var(--pos); border-color: transparent; }
.etiqueta.media { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.etiqueta.baixa { background: var(--neg-bg); color: var(--neg); border-color: transparent; }
.etiqueta.nr { color: var(--nr); }
.etiqueta.fr { color: var(--fr); }
.aviso { padding: .7rem .9rem; border-radius: var(--raio); background: var(--warn-bg); color: var(--warn); margin: .6rem 0; }
.aviso.info { background: var(--info-bg); color: var(--text); }
.aviso.erro { background: var(--neg-bg); color: var(--neg); }
.aviso.ok { background: var(--pos-bg); color: var(--pos); }
.pequeno-texto { font-size: .85rem; color: var(--muted); }
.mono { font-family: var(--mono); }
.desc { max-width: 420px; word-break: break-word; }
.barra { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; min-width: 80px; }
.barra > span { display: block; height: 100%; background: var(--pos); }
.barra.media > span { background: var(--warn); }
.barra.alta > span { background: var(--neg); }
.separadores { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; flex-wrap: wrap; }
.separadores button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; color: var(--muted); }
.separadores button.ativo { border-bottom-color: var(--primary); color: var(--text); font-weight: 600; }

/* Mapa Geral */
.mapa th, .mapa td { padding: .3rem .45rem; font-size: .85rem; }
.mapa td.nome { min-width: 260px; max-width: 360px; }
.mapa tr.seccao td { background: var(--info-bg); font-weight: 700; cursor: pointer; }
.mapa tr.grupo td { font-weight: 600; background: var(--surface-2); }
.mapa tr.resumo td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--border); }
.mapa td.previsto[tabindex] { cursor: text; }
.mapa td.previsto[tabindex]:hover { outline: 1px dashed var(--muted); }
.mapa td.real.clicavel { cursor: pointer; text-decoration: underline dotted; }
.mapa input.editar { width: 100px; min-height: 26px; padding: .1rem .3rem; text-align: right; }
.mapa .mes-cab { text-align: center; border-left: 2px solid var(--border); }
.mapa td.inicio-mes, .mapa th.inicio-mes { border-left: 2px solid var(--border); }

/* Janela */
.fundo-janela { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 1rem; z-index: 50; overflow-y: auto; }
.janela { background: var(--surface); border-radius: 12px; max-width: 720px; width: 100%; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.janela.larga { max-width: 1100px; }
.janela-cab { display: flex; justify-content: space-between; align-items: center; padding: .9rem 1.1rem; border-bottom: 1px solid var(--border); }
.janela-cab h2 { margin: 0; }
.janela-corpo { padding: 1rem 1.1rem; }
.janela-rodape { display: flex; justify-content: flex-end; gap: .5rem; padding: .8rem 1.1rem; border-top: 1px solid var(--border); flex-wrap: wrap; }

/* Avisos rápidos */
#toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 60; }
.toast { background: var(--text); color: var(--surface); padding: .6rem .9rem; border-radius: 8px; box-shadow: var(--sombra); max-width: 380px; }
.toast.erro { background: var(--neg); color: #fff; }

/* Escolha com pesquisa */
.escolha { position: relative; min-width: 240px; }
.escolha input { width: 100%; }
.escolha-lista { position: absolute; left: 0; right: 0; top: 100%; z-index: 30; max-height: 280px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 20px rgba(0,0,0,.15); margin-top: 2px; }
.escolha-lista div { padding: .35rem .6rem; cursor: pointer; font-size: .9rem; }
.escolha-lista div.grupo { font-weight: 700; color: var(--muted); font-size: .75rem; text-transform: uppercase; cursor: default; background: var(--surface-2); }
.escolha-lista div.marcado, .escolha-lista div:not(.grupo):hover { background: var(--info-bg); }

/* Entrar */
.entrar { max-width: 420px; margin: 8vh auto; }
.entrar .cartao { padding: 1.6rem; }
.entrar h1 { display: flex; align-items: center; gap: .6rem; }
.entrar input { width: 100%; }
.qr { display: flex; justify-content: center; margin: .8rem 0; }
.qr svg { width: 220px; height: 220px; background: #fff; padding: 4px; border-radius: 6px; }
.codigos { display: grid; grid-template-columns: repeat(2, 1fr); gap: .3rem .8rem; font-family: var(--mono); font-size: 1rem; background: var(--surface-2); padding: .8rem; border-radius: 8px; }

/* Botão de pedido à Pulso */
.botao-pedido { position: fixed; left: 1rem; bottom: 1rem; z-index: 40; border-radius: 99px; box-shadow: var(--sombra); }
@media print { .topo, .botao-pedido, .acoes, .filtros { display: none !important; } }

/* Texto só para leitores de ecrã */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
