/* Controlo de Raspadinhas — estilos.
   Tokens de cor em :root, variante escura por prefers-color-scheme. Tipografia de sistema, sem fontes externas.
   CSP estrita: este é o único sítio com estilos (nada inline no HTML). */

/* ───────────────────────── tokens ───────────────────────── */

:root {
    color-scheme: light dark;

    /* superfícies e texto */
    --fundo: #f4f3ef;
    --superficie: #ffffff;
    --superficie-2: #f8f7f4;
    --superficie-3: #efeee9;
    --texto: #1c1c1a;
    --texto-2: #4f4e49;
    --texto-3: #6b6a63;
    --linha: #e1e0d9;
    --linha-forte: #c3c2b7;

    /* acção e foco */
    --primario: #1f5fae;
    --primario-hover: #184d8f;
    --primario-texto: #ffffff;
    --foco: #2a78d6;
    --perigo: #b3261e;
    --perigo-fundo: #fbeaea;
    --perigo-linha: #e9b9b6;

    /* estados: texto sobre o seu fundo (contraste AA) — sempre com ícone + texto */
    --ok-texto: #17603a;
    --ok-fundo: #e4f3ea;
    --neg-texto: #a1231f;
    --neg-fundo: #fbe9e8;
    --pos-texto: #1a4f96;
    --pos-fundo: #e5effb;
    --nf-texto: #55544e;
    --nf-fundo: #ecebe5;
    --inc-texto: #6b6a63;

    /* gráfico: par divergente validado (azul/vermelho) + cinzento neutro */
    --g-pos: #2a78d6;
    --g-neg: #e34948;
    --g-nf: #898781;
    --g-superficie: #fcfcfb;
    --g-grelha: #e1e0d9;
    --g-base: #c3c2b7;

    --aviso-fundo: #1c1c1a;
    --aviso-texto: #ffffff;
    --fundo-modal: rgb(20 20 18 / 0.5);
    --sombra: 0 1px 2px rgb(0 0 0 / 0.05);
    --sombra-alta: 0 16px 40px rgb(0 0 0 / 0.2), 0 2px 6px rgb(0 0 0 / 0.08);
    --raio: 10px;
    --fonte: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --fundo: #121211;
        --superficie: #1a1a19;
        --superficie-2: #20201f;
        --superficie-3: #292927;
        --texto: #ecebe7;
        --texto-2: #bdbcb5;
        --texto-3: #9a9992;
        --linha: #2c2c2a;
        --linha-forte: #45453f;

        --primario: #2f74cf;
        --primario-hover: #2867ba;
        --primario-texto: #ffffff;
        --foco: #6aa6f0;
        --perigo: #f08a84;
        --perigo-fundo: #341a19;
        --perigo-linha: #6b2f2c;

        --ok-texto: #84d7a5;
        --ok-fundo: #15301f;
        --neg-texto: #f4a5a0;
        --neg-fundo: #3a1b1a;
        --pos-texto: #9fc6f6;
        --pos-fundo: #172b45;
        --nf-texto: #c4c3bc;
        --nf-fundo: #2c2c2a;
        --inc-texto: #9a9992;

        --g-pos: #3987e5;
        --g-neg: #e66767;
        --g-nf: #898781;
        --g-superficie: #1a1a19;
        --g-grelha: #2c2c2a;
        --g-base: #383835;

        --aviso-fundo: #ecebe7;
        --aviso-texto: #1a1a19;
        --fundo-modal: rgb(0 0 0 / 0.65);
        --sombra: none;
        --sombra-alta: 0 16px 40px rgb(0 0 0 / 0.6);
    }
}

/* ───────────────────────── base ───────────────────────── */

*,
*::before,
*::after {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scrollbar-gutter: stable;
}

html.com-dialogo {
    overflow: hidden;
}

body {
    margin: 0;
    min-width: 320px;
    font-family: var(--fonte);
    font-size: 16px;
    line-height: 1.45;
    color: var(--texto);
    background: var(--fundo);
    accent-color: var(--primario);
}

h1,
h2,
h3,
p,
dl,
dd,
ul {
    margin: 0;
}

button,
input,
textarea {
    font-family: inherit;
}

:focus-visible {
    outline: 3px solid var(--foco);
    outline-offset: 2px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.so-impressao {
    display: none;
}

.saltar {
    position: absolute;
    left: -999px;
    top: 8px;
    z-index: 100;
    padding: 10px 14px;
    border-radius: 8px;
    background: var(--superficie);
    color: var(--texto);
    font-weight: 600;
}

.saltar:focus {
    left: 8px;
}

/* ───────────────────────── botões ───────────────────────── */

.botao {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 40px;
    padding: 0 14px;
    border: 1px solid var(--linha-forte);
    border-radius: 8px;
    background: var(--superficie);
    color: var(--texto);
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.12s ease, border-color 0.12s ease;
}

.botao:hover {
    background: var(--superficie-3);
}

.botao:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.botao--primario {
    border-color: transparent;
    background: var(--primario);
    color: var(--primario-texto);
}

.botao--primario:hover {
    background: var(--primario-hover);
}

.botao--primario:disabled:hover {
    background: var(--primario);
}

.botao--discreto {
    border-color: transparent;
    background: transparent;
    color: var(--texto-2);
    font-weight: 500;
    padding: 0 10px;
}

.botao--icone {
    width: 40px;
    padding: 0;
    font-size: 1.375rem;
    line-height: 1;
}

.botao--perigo {
    border-color: var(--perigo-linha);
    color: var(--perigo);
}

.botao--perigo:hover {
    background: var(--perigo-fundo);
}

.botao--largo {
    width: 100%;
    min-height: 48px;
}

.botao--pequeno {
    min-height: 32px;
    padding: 0 10px;
    font-size: 0.8125rem;
}

@media (pointer: coarse) {
    .botao {
        min-height: 44px;
    }

    .botao--icone {
        width: 44px;
    }

    .botao--pequeno {
        min-height: 40px;
    }
}

/* ───────────────────────── cabeçalho ───────────────────────── */

.topo {
    background: var(--superficie);
    border-bottom: 1px solid var(--linha);
}

.topo__dentro {
    max-width: 1180px;
    margin: 0 auto;
    padding: 10px 16px 14px;
}

.topo__linha {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 12px;
}

.topo__linha--mes {
    margin-top: 10px;
}

.topo__titulo {
    font-size: 1.0625rem;
    font-weight: 700;
    letter-spacing: -0.005em;
}

.topo__accoes {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    margin-right: -10px;
}

.mes-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.mes-nav__titulo {
    min-width: 8.6em;
    padding: 0 4px;
    font-size: 1.375rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    text-align: center;
    white-space: nowrap;
}

#btn-hoje {
    margin-left: 6px;
}

#btn-hoje[data-mes-actual="1"] {
    color: var(--texto-3);
}

#btn-registar {
    min-height: 44px;
    padding: 0 20px;
    font-size: 1rem;
}

/* ───────────────────────── conteúdo ───────────────────────── */

.conteudo {
    max-width: 1180px;
    margin: 0 auto;
    padding: 16px 16px 56px;
}

.conteudo:focus {
    outline: none;
}

.vista {
    min-width: 0;
}

.vista .cartoes,
.vista .tabela,
.vista .grafico {
    transition: opacity 0.15s ease;
}

.vista[aria-busy="true"] .cartoes,
.vista[aria-busy="true"] .tabela,
.vista[aria-busy="true"] .grafico {
    opacity: 0.55;
}

.painel {
    padding: 14px 16px;
    border-radius: var(--raio);
    border: 1px solid var(--linha);
    background: var(--superficie);
}

.painel--erro {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 16px;
    margin-bottom: 16px;
    border-color: var(--perigo-linha);
    background: var(--perigo-fundo);
    color: var(--neg-texto);
    font-weight: 600;
}

/* cartões do resumo */

.cartoes {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}

.cartao {
    min-width: 0;
    padding: 14px 16px;
    border: 1px solid var(--linha);
    border-radius: var(--raio);
    background: var(--superficie);
    box-shadow: var(--sombra);
}

.cartao__rotulo {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--texto-2);
}

.cartao__valor {
    margin-top: 4px;
    font-size: clamp(1.1875rem, 4.6vw, 1.5rem);
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.2;
    white-space: nowrap;
}

.cartao__nota {
    margin-top: 6px;
    font-size: 0.8125rem;
    color: var(--texto-3);
}

.cartao__nota .estado {
    margin-right: 2px;
}

/* blocos (tabela, gráfico) */

.bloco {
    margin-top: 16px;
    border: 1px solid var(--linha);
    border-radius: var(--raio);
    background: var(--superficie);
    box-shadow: var(--sombra);
    min-width: 0;
}

.bloco__cabecalho {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 4px 16px;
    padding: 14px 16px 12px;
}

.bloco__titulo {
    font-size: 1rem;
    font-weight: 700;
}

.bloco__nota {
    font-size: 0.8125rem;
    color: var(--texto-3);
}

.bloco__nota--transporte {
    padding: 0 16px 10px;
    color: var(--texto-2);
}

.bloco__rodape {
    padding: 12px 16px 14px;
    font-size: 0.8125rem;
    color: var(--texto-2);
}

.a-carregar {
    padding: 0 16px 10px;
    font-size: 0.875rem;
    color: var(--texto-3);
}

.aviso-vazio {
    margin: 0 16px 12px;
    padding: 10px 12px;
    border: 1px solid var(--linha);
    border-radius: 8px;
    background: var(--superficie-2);
    color: var(--texto-2);
    font-size: 0.9375rem;
}

/* ───────────────────────── tabela do mês ───────────────────────── */

.tabela-contentor {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-top: 1px solid var(--linha);
    border-bottom: 1px solid var(--linha);
}

.tabela-contentor:focus-visible {
    outline-offset: -3px;
}

.tabela {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.9375rem;
    font-variant-numeric: tabular-nums;
}

.tabela th,
.tabela td {
    padding: 7px 11px;
    border-bottom: 1px solid var(--linha);
    background: var(--fundo-linha, var(--superficie));
    text-align: right;
    vertical-align: top;
    white-space: nowrap;
    font-weight: 400;
}

.tabela thead th {
    padding-top: 9px;
    padding-bottom: 8px;
    border-bottom-color: var(--linha-forte);
    background: var(--superficie-2);
    color: var(--texto-2);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    vertical-align: bottom;
}

.tabela thead th[title] {
    cursor: help;
}

.tabela .col-dia {
    position: sticky;
    left: 0;
    z-index: 1;
    width: 92px;
    min-width: 92px;
    border-right: 1px solid var(--linha);
    text-align: left;
}

.tabela thead .col-dia {
    z-index: 2;
}

.tabela .col-dif {
    padding-left: 16px;
    text-align: left;
}

.tabela tbody tr:last-child th,
.tabela tbody tr:last-child td {
    border-bottom: 0;
}

.linha {
    --fundo-linha: var(--superficie);
    cursor: pointer;
}

.linha--domingo {
    --fundo-linha: var(--superficie-2);
}

.linha:hover {
    --fundo-linha: var(--superficie-3);
}

.linha--futuro,
.linha--futuro:hover {
    --fundo-linha: var(--superficie);
    cursor: default;
}

.linha--futuro.linha--domingo,
.linha--futuro.linha--domingo:hover {
    --fundo-linha: var(--superficie-2);
}

.linha--vazia td,
.linha--vazia .dia {
    color: var(--texto-3);
}

.linha--futuro .dia {
    opacity: 0.6;
}

.dia {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    color: inherit;
    font: inherit;
}

.dia--botao {
    min-height: 30px;
    margin: -4px -6px;
    padding: 4px 6px;
    border: 0;
    border-radius: 6px;
    background: none;
    cursor: pointer;
}

.dia--botao:focus-visible {
    outline-offset: 0;
}

.dia__num {
    min-width: 1.5em;
    font-weight: 700;
    text-align: right;
}

.dia__sem {
    font-size: 0.8125rem;
    color: var(--texto-2);
}

.linha--vazia .dia__sem {
    color: var(--texto-3);
}

.linha--domingo .dia__sem {
    font-weight: 700;
}

.linha--hoje .col-dia {
    box-shadow: inset 3px 0 0 var(--primario);
}

.linha--hoje .dia__num {
    min-width: 1.9em;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--primario);
    color: var(--primario-texto);
    text-align: center;
}

.dia__nota {
    margin-left: 6px;
    font-size: 0.8125rem;
    color: var(--texto-3);
    cursor: help;
}

.num--vazio {
    color: var(--texto-3);
}

.cel-valor {
    display: block;
    font-weight: 600;
}

.cel-valor--fraco {
    font-weight: 400;
    color: var(--texto-2);
}

.cel-sub {
    display: block;
    margin-top: 1px;
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--texto-3);
}

.dif {
    display: grid;
    grid-template-columns: minmax(5.2em, auto) auto;
    align-items: center;
    justify-content: start;
    gap: 10px;
}

.dif__valor {
    font-weight: 600;
    text-align: right;
}

.dif__valor--nf {
    font-weight: 400;
    color: var(--texto-3);
}

.col-dif .cel-sub {
    margin-top: 3px;
}

.linha-totais th,
.linha-totais td {
    border-top: 2px solid var(--linha-forte);
    border-bottom: 0;
    background: var(--superficie-2);
    font-weight: 700;
}

.tabela .linha-totais .col-dif {
    text-align: left;
}

.linha-totais .col-dif .cel-valor {
    display: inline-block;
    min-width: 5.2em;
    text-align: right;
}

/* etiqueta de estado: ícone + texto, nunca só cor */

.estado {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 1px 9px 1px 7px;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.45;
    white-space: nowrap;
}

.estado__icone {
    font-size: 0.85em;
    line-height: 1;
}

.estado--ok {
    background: var(--ok-fundo);
    color: var(--ok-texto);
}

.estado--alerta_negativo {
    background: var(--neg-fundo);
    color: var(--neg-texto);
}

.estado--alerta_positivo {
    background: var(--pos-fundo);
    color: var(--pos-texto);
}

.estado--nao_fiavel {
    background: var(--nf-fundo);
    color: var(--nf-texto);
}

.estado--incompleto {
    border-color: var(--linha-forte);
    color: var(--inc-texto);
}

/* ───────────────────────── gráfico ───────────────────────── */

.legenda {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
    padding: 0;
    list-style: none;
    font-size: 0.8125rem;
    color: var(--texto-2);
}

.legenda li {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.legenda__cor {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

.legenda__cor--pos,
.dica__chave--pos {
    background: var(--g-pos);
}

.legenda__cor--neg,
.dica__chave--neg {
    background: var(--g-neg);
}

.legenda__cor--nf,
.dica__chave--nf {
    background: var(--g-nf);
}

.grafico {
    position: relative;
    min-width: 0;
    padding: 8px 0 6px;
    border-top: 1px solid var(--linha);
    border-radius: 0 0 var(--raio) var(--raio);
    background: var(--g-superficie);
}

.grafico__svg {
    display: block;
    max-width: 100%;
    height: auto;
    overflow: visible;
}

.grafico__vazio {
    padding: 28px 16px;
    text-align: center;
    font-size: 0.9375rem;
    color: var(--texto-3);
}

.g-grelha {
    stroke: var(--g-grelha);
    stroke-width: 1;
    shape-rendering: crispEdges;
}

.g-base {
    stroke: var(--g-base);
    stroke-width: 1;
    shape-rendering: crispEdges;
}

.g-texto {
    fill: var(--texto-3);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

.g-rotulo {
    fill: var(--texto);
    font-size: 11.5px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    paint-order: stroke;
    stroke: var(--g-superficie);
    stroke-width: 3px;
    stroke-linejoin: round;
}

.g-barra--pos {
    fill: var(--g-pos);
}

.g-barra--neg {
    fill: var(--g-neg);
}

.g-barra--nf {
    fill: var(--g-nf);
}

.g-barra.activa {
    filter: brightness(1.12);
}

.g-corte {
    fill: var(--g-superficie);
}

.g-realce {
    fill: var(--texto);
    opacity: 0.06;
}

.g-alvo {
    fill: transparent;
    outline: none;
}

.g-alvo:focus-visible {
    stroke: var(--foco);
    stroke-width: 2px;
}

.grafico__dica {
    position: absolute;
    z-index: 5;
    min-width: 180px;
    max-width: 270px;
    padding: 10px 12px;
    border: 1px solid var(--linha-forte);
    border-radius: 8px;
    background: var(--superficie);
    box-shadow: var(--sombra-alta);
    color: var(--texto);
    font-size: 0.8125rem;
    pointer-events: none;
}

.dica__titulo {
    margin-bottom: 2px;
    font-size: 0.75rem;
    color: var(--texto-2);
}

.dica__valor {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 6px;
    font-size: 1.0625rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.dica__chave {
    flex: none;
    width: 12px;
    height: 3px;
    border-radius: 2px;
}

.dica__linha {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    color: var(--texto-2);
}

.dica__num {
    color: var(--texto);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.dica__estado {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--linha);
    color: var(--texto-2);
}

/* ───────────────────────── aviso breve ───────────────────────── */

.aviso {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 50;
    max-width: calc(100vw - 32px);
    padding: 11px 18px;
    border-radius: 999px;
    background: var(--aviso-fundo);
    color: var(--aviso-texto);
    box-shadow: var(--sombra-alta);
    font-size: 0.9375rem;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 8px);
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.aviso:empty {
    padding: 0;
}

.aviso--visivel {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* ───────────────────────── diálogos ───────────────────────── */

.dialogo {
    width: min(680px, calc(100vw - 32px));
    max-width: none;
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--linha-forte);
    border-radius: 14px;
    background: var(--superficie);
    color: var(--texto);
    box-shadow: var(--sombra-alta);
}

.dialogo[open] {
    display: flex;
    flex-direction: column;
}

.dialogo--estreito {
    width: min(500px, calc(100vw - 32px));
}

.dialogo::backdrop {
    background: var(--fundo-modal);
}

.dialogo__form {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
}

.dialogo__cabecalho {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 10px 10px 20px;
    border-bottom: 1px solid var(--linha);
}

.dialogo__titulo {
    font-size: 1.125rem;
    font-weight: 700;
}

.dialogo__titulo:focus {
    outline: none;
}

.dialogo__corpo {
    flex: 1 1 auto;
    min-height: 0;
    padding: 16px 20px 20px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.dialogo__rodape {
    flex: none;
    padding: 12px 20px;
    border-top: 1px solid var(--linha);
    background: var(--superficie-2);
}

.dialogo__mensagens {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
}

.dialogo__mensagens .form__erro {
    margin-bottom: 10px;
}

.dialogo__mensagens .botao {
    margin-bottom: 10px;
}

.dialogo__botoes {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.dialogo__espaco {
    flex: 1 1 0;
}

.dialogo__rodape .botao--primario {
    min-width: 120px;
}

/* ───────────────────────── campos ───────────────────────── */

.campo {
    min-width: 0;
    margin: 0 0 14px;
}

.campo label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.875rem;
    font-weight: 600;
}

.opcional {
    font-weight: 400;
    color: var(--texto-3);
}

.campo input[type="text"],
.campo input[type="password"],
.campo input[type="date"],
.campo textarea {
    display: block;
    width: 100%;
    min-height: 48px;
    padding: 10px 12px;
    border: 1px solid var(--linha-forte);
    border-radius: 8px;
    background: var(--superficie);
    color: var(--texto);
    font-size: 1.0625rem;
    font-variant-numeric: tabular-nums;
    line-height: 1.3;
}

.campo textarea {
    min-height: 64px;
    font-size: 1rem;
    resize: vertical;
}

.campo input:hover,
.campo textarea:hover {
    border-color: var(--texto-3);
}

.campo input:focus-visible,
.campo textarea:focus-visible {
    outline-offset: 0;
    border-color: var(--foco);
}

.campo--erro input,
.campo--erro textarea {
    border-color: var(--perigo);
    box-shadow: inset 0 0 0 1px var(--perigo);
}

.campo__dica {
    margin-top: 6px;
    font-size: 0.8125rem;
    color: var(--texto-3);
}

.campo__erro,
.form__erro {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--perigo);
}

.campo__erro {
    margin-top: 6px;
}

.campo__erro:empty,
.form__erro:empty,
.form__ok:empty {
    display: none;
}

.form__erro {
    font-size: 0.875rem;
}

.form__ok {
    margin-top: 10px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--ok-texto);
}

.entrada-euro {
    position: relative;
}

.entrada-euro input[type="text"] {
    padding-right: 34px;
}

.entrada-euro__sufixo {
    position: absolute;
    top: 50%;
    right: 13px;
    color: var(--texto-3);
    pointer-events: none;
    transform: translateY(-50%);
}

.campo-data {
    display: flex;
    align-items: center;
    gap: 6px;
}

.campo-data input {
    flex: 1 1 auto;
    min-width: 0;
}

.campo-data .botao--icone {
    flex: none;
    width: 48px;
    min-height: 48px;
}

.grupo {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.grupo:disabled {
    opacity: 0.55;
}

.passo {
    margin-top: 6px;
    padding-top: 16px;
    border-top: 1px solid var(--linha);
}

.dialogo__corpo > .passo:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
}

.passo + .passo,
.passo + .campo,
.grupo > .campo {
    margin-top: 18px;
}

.grupo > .campo {
    padding-top: 16px;
    border-top: 1px solid var(--linha);
}

.passo__titulo {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--texto-2);
}

.passo__num {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--superficie-3);
    color: var(--texto);
    font-size: 0.75rem;
    letter-spacing: 0;
}

.campos-par {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 12px;
}

.campos-par label {
    display: flex;
    align-items: flex-end;
    min-height: 2.7em;
    line-height: 1.3;
}

/* valores calculados ao vivo */

.calculos {
    padding: 8px 12px;
    border: 1px solid var(--linha);
    border-radius: 8px;
    background: var(--superficie-2);
    font-size: 0.9375rem;
}

.calculos--resultado {
    border-color: var(--linha-forte);
}

.calculos__linha {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 2px 12px;
    padding: 3px 0;
}

.calculos dt {
    color: var(--texto-2);
}

.calculos dd {
    margin-left: auto;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
}

.calculos__linha--forte dt {
    color: var(--texto);
    font-weight: 700;
}

.calculos__linha--forte dd {
    font-size: 1.0625rem;
    font-weight: 700;
}

.calculos .calculos__vazio {
    font-weight: 400;
    color: var(--texto-3);
}

.calculos .estado {
    margin-left: 6px;
    vertical-align: 1px;
}

.calculos + .campo__dica {
    margin-top: 8px;
}

.nota-cadeia {
    margin-top: 8px;
    padding: 8px 10px;
    border-left: 3px solid var(--g-nf);
    border-radius: 4px;
    background: var(--nf-fundo);
    color: var(--nf-texto);
    font-size: 0.8125rem;
}

/* alternador "Euro manual" (checkbox com role=switch) */

.alternador {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    margin-top: 8px;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
}

.alternador input {
    position: absolute;
    left: 0;
    top: 50%;
    width: 42px;
    height: 24px;
    margin: -12px 0 0;
    opacity: 0;
    cursor: pointer;
}

.alternador__pista {
    position: relative;
    flex: none;
    width: 42px;
    height: 24px;
    border: 1px solid var(--texto-3);
    border-radius: 999px;
    background: var(--superficie-3);
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.alternador__pista::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--texto-3);
    transition: transform 0.15s ease, background-color 0.15s ease;
}

.alternador input:checked + .alternador__pista {
    border-color: var(--primario);
    background: var(--primario);
}

.alternador input:checked + .alternador__pista::after {
    background: var(--primario-texto);
    transform: translateX(18px);
}

.alternador input:focus-visible + .alternador__pista {
    outline: 3px solid var(--foco);
    outline-offset: 2px;
}

/* ───────────────────────── login / configurar ───────────────────────── */

body.entrada {
    display: grid;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 16px;
    place-items: center;
}

.entrada__cartao {
    width: min(400px, 100%);
    padding: 28px 24px 24px;
    border: 1px solid var(--linha);
    border-radius: 14px;
    background: var(--superficie);
    box-shadow: var(--sombra);
}

.entrada__titulo {
    font-size: 1.25rem;
    font-weight: 700;
}

.entrada__texto {
    margin: 8px 0 20px;
    color: var(--texto-2);
}

.entrada__form .form__erro {
    margin-bottom: 12px;
}

/* ───────────────────────── ecrãs estreitos ───────────────────────── */

@media (max-width: 640px) {
    .topo__dentro {
        padding: 8px 12px 12px;
    }

    .topo__titulo {
        font-size: 1rem;
    }

    .topo__accoes {
        margin-left: -8px;
        margin-right: -8px;
    }

    .topo__accoes .botao {
        padding: 0 8px;
        font-size: 0.8125rem;
    }

    .mes-nav {
        flex: 1 1 100%;
    }

    .mes-nav__titulo {
        flex: 1 1 auto;
        min-width: 0;
        font-size: 1.1875rem;
    }

    #btn-registar {
        flex: 1 1 100%;
        min-height: 48px;
    }

    .conteudo {
        padding: 12px 12px 48px;
    }

    .cartoes {
        gap: 8px;
    }

    .cartao {
        padding: 12px;
    }

    .tabela {
        font-size: 0.875rem;
    }

    .tabela th,
    .tabela td {
        padding: 8px 9px;
    }

    .tabela .col-dia {
        width: 74px;
        min-width: 74px;
    }

    .dia {
        gap: 4px;
    }

    .dia__nota {
        margin-left: 3px;
    }

    /* formulário em ecrã inteiro no telemóvel */
    .dialogo,
    .dialogo--estreito {
        width: 100vw;
        max-width: 100vw;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        margin: 0;
        border: 0;
        border-radius: 0;
    }

    .dialogo__cabecalho {
        padding-left: 16px;
    }

    .dialogo__corpo {
        padding: 14px 16px 20px;
    }

    .dialogo__rodape {
        padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
    }

    .dialogo__rodape .botao--primario {
        flex: 1 1 auto;
    }

    .campos-par {
        grid-template-columns: 1fr;
    }

    .campos-par label {
        min-height: 0;
    }

    .aviso {
        bottom: 16px;
    }
}

/* ───────────────────────── movimento reduzido ───────────────────────── */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition: none !important;
        animation: none !important;
        scroll-behavior: auto !important;
    }
}

/* ───────────────────────── impressão: título do mês + tabela + totais, A4 vertical ───────────────────────── */

@page {
    size: A4 portrait;
    margin: 12mm;
}

@media print {
    :root {
        --fundo: #ffffff;
        --superficie: #ffffff;
        --superficie-2: #ffffff;
        --superficie-3: #ffffff;
        --texto: #000000;
        --texto-2: #000000;
        --texto-3: #333333;
        --linha: #999999;
        --linha-forte: #000000;
        --primario: #000000;
        --primario-texto: #ffffff;
    }

    body {
        background: #ffffff;
        color: #000000;
        font-size: 9pt;
    }

    .topo,
    .saltar,
    .resumo,
    .painel,
    .bloco--grafico,
    .bloco__cabecalho,
    .bloco__nota--transporte,
    .bloco__rodape,
    .a-carregar,
    .aviso-vazio,
    .aviso,
    .dia__nota,
    dialog,
    noscript {
        display: none !important;
    }

    .so-impressao {
        display: block;
        margin: 0 0 4mm;
        font-size: 13pt;
        font-weight: 700;
    }

    .conteudo {
        max-width: none;
        padding: 0;
    }

    .vista[aria-busy="true"] .tabela {
        opacity: 1;
    }

    .bloco {
        margin: 0;
        border: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .tabela-contentor {
        overflow: visible;
        border: 0;
    }

    .tabela {
        width: 100%;
        font-size: 8.5pt;
    }

    .tabela th,
    .tabela td {
        padding: 1.1mm 1.6mm;
        border-bottom: 0.2mm solid #999999;
        background: #ffffff !important;
        color: #000000 !important;
    }

    .tabela thead th {
        border-bottom: 0.4mm solid #000000;
        font-size: 7pt;
    }

    .tabela .col-dia {
        position: static;
        width: auto;
        min-width: 0;
        border-right: 0;
        box-shadow: none !important;
    }

    .tabela tr {
        break-inside: avoid;
    }

    .dia--botao {
        min-height: 0;
        margin: 0;
        padding: 0;
    }

    .dia,
    .dia__sem,
    .linha--futuro .dia {
        color: #000000 !important;
        opacity: 1;
    }

    .linha--hoje .dia__num {
        min-width: 1.5em;
        padding: 0;
        background: none;
        color: #000000;
        text-align: right;
    }

    /* a decomposição fica na mesma linha para as 31 linhas caberem numa folha */
    .cel-valor,
    .cel-sub {
        display: inline;
    }

    .cel-sub {
        margin-left: 1.5mm;
        font-size: 6.5pt;
        color: #000000;
    }

    .col-dif .cel-sub {
        margin-top: 0;
    }

    .dif {
        display: inline-grid;
        gap: 2mm;
    }

    .estado {
        padding: 0;
        border: 0;
        background: none !important;
        color: #000000 !important;
        font-size: 7.5pt;
        font-weight: 400;
    }

    .linha-totais th,
    .linha-totais td {
        border-top: 0.4mm solid #000000;
    }
}
