:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --hover: #f0f3f7;
  --border: #e4e8ee;
  --border-strong: #ccd3dc;
  --text: #111827;
  --muted: #667085;
  --accent: #1f6feb;
  --accent-soft: #eaf2ff;

  /* Uma cor por vista, para orientação imediata. */
  --via-variaveis: #7c3aed;
  --via-dados: #0d9488;
  --via-analises: #1f6feb;

  --nominal: #7c3aed;
  --ordinal: #0d9488;
  --scale: #c2410c;
  --unknown: #64748b;

  --file: #15803d;
  --inferred: #b45309;
  --user: #1d4ed8;

  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --warn-soft: #fffbeb;
  --warn-border: #fde68a;

  --radius: 10px;
  /* Sombras em camadas: a linha ténue define a aresta, a difusa dá elevação. */
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 2px 8px rgba(16,24,40,.05);
  --shadow-lg: 0 2px 4px rgba(16,24,40,.04), 0 12px 28px rgba(16,24,40,.09);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1a2029;
    --hover: #1e242d;
    --border: #262c34;
    --border-strong: #39414b;
    --text: #e6edf3;
    --muted: #9198a1;
    --accent: #58a6ff;
    --accent-soft: #16243c;

    --via-variaveis: #a78bfa;
    --via-dados: #2dd4bf;
    --via-analises: #58a6ff;

    --nominal: #c4b5fd;
    --ordinal: #5eead4;
    --scale: #fdba74;
    --unknown: #94a3b8;

    --file: #86efac;
    --inferred: #fcd34d;
    --user: #93c5fd;

    --danger: #fca5a5;
    --danger-soft: #2a1618;
    --warn-soft: #241d10;
    --warn-border: #4d3d16;

    /* No escuro, sombras difusas não se veem: a aresta é que define o volume. */
    --shadow: 0 0 0 1px rgba(255,255,255,.03), 0 2px 8px rgba(0,0,0,.3);
    --shadow-lg: 0 0 0 1px rgba(255,255,255,.04), 0 12px 28px rgba(0,0,0,.45);
  }
}

* { box-sizing: border-box; }

/* O `hidden` traz apenas `display: none` do agente do utilizador, que qualquer
   regra `display:` posterior sobrepõe. Sem isto, elementos com `display: flex`
   ficam visíveis mesmo escondidos. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection { background: var(--accent-soft); }

/* Foco visível apenas por teclado: o rato não deve deixar anéis pelo caminho. */
:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px;
}

/* ---------- Cabeçalho ---------- */
.top {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  padding: 13px 26px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 13px; }
.mark {
  display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff; font-weight: 700; font-size: 15px; letter-spacing: .4px;
  box-shadow: 0 2px 8px rgba(31,111,235,.28);
}
.top h1 {
  margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -.2px;
}
/* Curta o suficiente para funcionar como subtítulo: mais espaçada, para não
   parecer texto cortado. */
.tagline {
  margin: 1px 0 0; font-size: 12px; color: var(--muted);
  letter-spacing: .6px; text-transform: uppercase; font-weight: 550;
}

/* margin-left: auto mantém este bloco encostado à direita mesmo com a marca
   oculta (sem ela, o space-between do .top não tem nada para empurrar). */
.top-dir { display: flex; align-items: center; gap: 16px; margin-left: auto; }
.file-info { font-size: 13px; color: var(--muted); text-align: right; }

/* Menu principal, à esquerda: a entrada para os guias. */
.menu-topo { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.menu-link {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 12px; border-radius: 8px;
  font-size: 14px; font-weight: 600; color: var(--text);
  text-decoration: none; white-space: nowrap;
  transition: background .15s, color .15s;
}
.menu-link:hover { background: var(--hover); color: var(--accent); }
.menu-link svg {
  width: 17px; height: 17px; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.menu-destaque { background: var(--accent-soft); color: var(--accent); }
.menu-destaque:hover { filter: brightness(1.05); background: var(--accent-soft); }
/* Com um ficheiro aberto, os cartões de resumo precisam do espaço. */
.top:has(.summary:not(:empty)) .menu-extra { display: none; }
@media (max-width: 560px) {
  .menu-extra { display: none; }
  .menu-link { padding: 7px 10px; font-size: 13.5px; }
}
.file-info strong { color: var(--text); font-weight: 600; }

/* ---------- Autenticação ---------- */
.btn-google {
  display: inline-flex; align-items: center; gap: 9px;
  font: inherit; font-size: 13.5px; font-weight: 550;
  padding: 8px 15px; border-radius: 8px; cursor: pointer;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong);
  transition: border-color .13s, box-shadow .13s;
}
.btn-google:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.g-icon { width: 17px; height: 17px; flex-shrink: 0; }

.user-menu { position: relative; }
.user-btn {
  display: inline-flex; align-items: center; gap: 9px;
  font: inherit; font-size: 13.5px; font-weight: 550;
  padding: 5px 12px 5px 5px; border-radius: 24px; cursor: pointer;
  background: transparent; color: var(--text);
  border: 1px solid var(--border);
  transition: border-color .13s, background .13s;
}
.user-btn:hover { border-color: var(--border-strong); background: var(--hover); }

.user-foto, .user-inicial {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
}
.user-inicial {
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff; font-weight: 650; font-size: 13px;
}
.user-nome { max-width: 130px; overflow: hidden; text-overflow: ellipsis;
             white-space: nowrap; }

.user-drop {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 40;
  min-width: 232px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: cai .13s ease-out;
}
@keyframes cai { from { opacity: 0; transform: translateY(-4px); } }

.user-info { padding: 13px 15px; border-bottom: 1px solid var(--border); }
.user-info-nome { font-size: 13.5px; font-weight: 600; }
.user-info-email {
  font-size: 12.5px; color: var(--muted); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis;
}
.user-info-plano {
  font-size: 11.5px; font-weight: 600; color: var(--muted);
  margin-top: 6px;
}
.user-info-plano.e-pago { color: var(--accent); }
.user-acao {
  display: block; width: 100%; text-align: left;
  font: inherit; font-size: 13.5px; padding: 11px 15px; cursor: pointer;
  background: transparent; color: var(--text); border: none;
  /* Serve tanto para <button> como para <a>. */
  text-decoration: none; box-sizing: border-box;
}
.user-acao:hover { background: var(--hover); }

@media (max-width: 640px) {
  .user-nome, .file-info { display: none; }
}

/* As grelhas de Variáveis e de Dados são o conteúdo mais largo do produto —
   dez colunas, e mais largas ainda com o texto ampliado. O que se ganha em
   largura poupa-lhes deslocamento horizontal. Os blocos de texto corrido não
   são arrastados: a entrada limita-se a 840px e os resultados a 680px. */
main { max-width: 1800px; margin: 0 auto; padding: 26px; }

/* ---------- Entrada ---------- */
.entrada { max-width: 840px; margin: 0 auto; }

.hero { text-align: center; padding: 44px 16px 36px; }
.hero-h {
  margin: 0 0 18px; font-size: clamp(30px, 4.8vw, 44px);
  font-weight: 680; line-height: 1.2; letter-spacing: -.8px;
}
.hero-destaque {
  background: linear-gradient(120deg, var(--accent), #7c3aed);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
/* As três palavras que dizem o que a pessoa leva daqui. Peso e cor cheia
   fazem-nas saltar da frase sem roubar o gradiente do «em 5 minutos». */
.hero-chave {
  color: var(--text); font-weight: 800;
  position: relative; white-space: nowrap;
}
.hero-chave::after {
  content: ''; position: absolute;
  left: 0; right: 0; bottom: .04em; height: .34em; z-index: -1;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  border-radius: 3px;
}
.hero-sub {
  margin: 0 auto; max-width: 620px;
  font-size: 18.5px; line-height: 1.62; color: var(--muted);
}
.hero-sub strong { color: var(--text); font-weight: 650; }

.btn-grande { font-size: 17px; padding: 14px 34px; font-weight: 600; }

/* ---------- Gestão de planos e configurações (painel) ---------- */
.planos-conceder { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }

/* Configurações: rótulo, campo e botão de gravar, um por linha. */
.config-form { display: flex; flex-direction: column; gap: 10px; margin: 4px 0 12px; }
.config-linha {
  display: grid; grid-template-columns: 1fr 140px auto;
  align-items: center; gap: 10px; max-width: 460px;
}
.config-rotulo { font-size: 13px; color: var(--text); }
@media (max-width: 560px) {
  .config-linha { grid-template-columns: 1fr auto; }
  .config-linha .config-rotulo { grid-column: 1 / -1; }
}

/* ---------- Fronteira do plano ---------- */
/* Não é um ecrã de bloqueio: é um catálogo do que existe do outro lado. O
   utilizador vê os resultados descritivos por inteiro, com os dados dele —
   só os testes de hipóteses é que exigem plano. Nada é ocultado com blur,
   porque num produto estatístico esconder números destrói a confiança que é
   precisamente o que se está a tentar ganhar. */
.an-plano {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 28px 30px; text-align: center;
}
.an-plano-principal { min-width: 0; }
.an-plano-icone { font-size: 28px; line-height: 1; margin-bottom: 10px; }
.an-plano h3 {
  margin: 0 0 4px; font-size: 16.5px; font-weight: 640;
}
.an-plano-sub {
  margin: 0 auto 14px !important; max-width: 430px;
  font-size: 13.5px; font-weight: 550; color: var(--text) !important;
}
.an-plano-principal > p {
  margin: 0 auto 18px; max-width: 430px;
  font-size: 13px; color: var(--muted); line-height: 1.55;
}
.an-plano.pagar-ativo .an-plano-sub {
  margin-left: 0 !important; font-size: 12.5px; margin-bottom: 8px !important;
}

/* Ao pedir o plano, o cartão de pagamento aparece ao lado — não por baixo —
   para caber tudo num ecrã sem rolar. O cabeçalho e os grupos encolhem. */
.an-plano.pagar-ativo {
  display: grid;
  grid-template-columns: 1fr minmax(320px, 380px);
  gap: 28px;
  align-items: start;
  text-align: left;
  padding: 24px 26px;
}
.an-plano.pagar-ativo .an-plano-icone { display: none; }
.an-plano.pagar-ativo h3 { font-size: 15px; margin-bottom: 6px; }
.an-plano.pagar-ativo .an-plano-principal > p {
  margin-left: 0; font-size: 12px; margin-bottom: 14px;
}
.an-plano.pagar-ativo .an-plano-grupos {
  grid-template-columns: 1fr;
  gap: 7px; margin: 0; max-width: none;
}
.an-plano.pagar-ativo .an-plano-grupo {
  padding: 8px 11px 9px 30px;
}
.an-plano.pagar-ativo .an-plano-grupo::before { top: 8px; }
.an-plano.pagar-ativo .an-plano-grupo-d { font-size: 11px; }
/* O botão «Quero o plano» e a nota já não fazem sentido depois de aberto. */
.an-plano.pagar-ativo .an-plano-acoes,
.an-plano.pagar-ativo .an-plano-nota { display: none; }
.an-plano.pagar-ativo .an-plano-passo {
  margin: 0; padding: 0; border: 0;
}
.an-plano.pagar-ativo .pg-cartao { margin: 0; max-width: none; }

@media (max-width: 720px) {
  .an-plano.pagar-ativo {
    grid-template-columns: 1fr;
    gap: 18px;
  }
  /* No telemóvel o pagamento vem primeiro: é o que a pessoa quer ver. */
  .an-plano.pagar-ativo .an-plano-passo { order: -1; }
}

/* O que se ganha, por grupo de tarefa. Organizado como o utilizador pensa
   — «preciso de comparar grupos», «preciso de verificar pressupostos» —
   não como uma lista solta de nomes de testes. */
.an-plano-grupos {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  text-align: left;
  margin: 4px auto 22px;
  max-width: 560px;
}
.an-plano-grupo {
  padding: 11px 13px 12px 32px;
  position: relative;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
}
.an-plano-grupo::before {
  content: '✓';
  position: absolute; left: 12px; top: 11px;
  color: var(--accent); font-weight: 700; font-size: 13px;
}
.an-plano-grupo-t {
  display: block;
  font-size: 13px; font-weight: 620; color: var(--text);
  margin-bottom: 2px;
}
.an-plano-grupo-d {
  display: block;
  font-size: 11.5px; color: var(--muted); line-height: 1.45;
}

.an-plano-acoes {
  display: flex; gap: 9px; justify-content: center; flex-wrap: wrap;
}
.an-plano-nota {
  margin: 16px 0 0; font-size: 12px; color: var(--muted);
}
.an-plano-passo {
  margin-top: 18px; padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 13px; line-height: 1.6;
}
.an-plano-passo p { margin: 0 0 6px; }
.an-plano-passo a { color: var(--accent); }

/* ---------- Pagamento M-Pesa ---------- */
/* Identidade M-Pesa: vermelho. O cartão distingue-se do resto da interface
   (azul) para o utilizador reconhecer «isto é o pagamento». */
.pg-cartao {
  --mpesa: #e2062c;
  --mpesa-escuro: #b30320;
  --mpesa-suave: #fdecef;
  max-width: 380px;
  margin: 4px auto 0;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(16,24,40,.04), 0 10px 30px rgba(226,6,44,.08);
  overflow: hidden;
}
@media (prefers-color-scheme: dark) {
  .pg-cartao { --mpesa: #ff2d4d; --mpesa-suave: #2a1015; }
}

.pg-cartao-topo {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px;
  background: linear-gradient(135deg, var(--mpesa), var(--mpesa-escuro));
  color: #fff;
}
.pg-marca {
  display: inline-flex; align-items: center; gap: 7px;
  font-weight: 700; font-size: 14px; letter-spacing: .2px;
}
.pg-marca-ponto {
  width: 9px; height: 9px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.28);
}
.pg-seguro { font-size: 11px; opacity: .9; font-weight: 500; }

.pg-resumo {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.pg-resumo-rotulo { font-size: 12.5px; color: var(--muted); }
.pg-resumo-valor {
  font-size: 17px; font-weight: 700; color: var(--text);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}

.pg-corpo { padding: 18px; }
.pg-centro { text-align: center; }

.pg-label {
  display: block; font-size: 12.5px; font-weight: 550;
  color: var(--text); margin-bottom: 7px;
}
.pg-numero-campo {
  display: flex; align-items: stretch;
  border: 1px solid var(--border-strong); border-radius: 9px;
  overflow: hidden;
  transition: border-color .12s, box-shadow .12s;
}
.pg-numero-campo:focus-within {
  border-color: var(--mpesa);
  box-shadow: 0 0 0 3px var(--mpesa-suave);
}
.pg-prefixo {
  display: flex; align-items: center; white-space: nowrap;
  padding: 0 11px; font-size: 13px; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border-right: 1px solid var(--border);
}
.pg-numero-campo input {
  flex: 1; min-width: 0;
  padding: 11px 12px; font-size: 15px; letter-spacing: .5px;
  border: 0; background: var(--surface); color: var(--text);
}
.pg-numero-campo input:focus { outline: none; }
.pg-hint {
  margin: 7px 0 0; font-size: 11.5px; color: var(--muted);
}
.pg-erro {
  margin: 9px 0 0;
  font-size: 12.5px; color: var(--danger); font-weight: 500;
}

.pg-botao {
  width: 100%; margin-top: 16px;
  padding: 12px 18px;
  font: inherit; font-size: 14.5px; font-weight: 650; color: #fff;
  background: linear-gradient(135deg, var(--mpesa), var(--mpesa-escuro));
  border: 0; border-radius: 9px; cursor: pointer;
  box-shadow: 0 2px 8px rgba(226,6,44,.28);
  transition: filter .12s, transform .08s, box-shadow .12s;
}
.pg-botao:hover:not(:disabled) { filter: brightness(1.06); }
.pg-botao:active:not(:disabled) { transform: translateY(1px); }
.pg-botao:disabled { opacity: .6; cursor: default; box-shadow: none; }

.pg-rodape {
  margin: 12px 0 0; font-size: 11.5px; color: var(--muted);
  line-height: 1.5; text-align: center;
}

.pg-spinner {
  width: 34px; height: 34px; margin: 2px auto 14px;
  border: 3px solid var(--border);
  border-top-color: var(--mpesa, #e2062c);
  border-radius: 50%; animation: pg-gira .8s linear infinite;
}
@keyframes pg-gira { to { transform: rotate(360deg); } }

.pg-sucesso-icone {
  width: 46px; height: 46px; margin: 0 auto 12px;
  display: grid; place-items: center;
  font-size: 22px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, #16a34a, #12833c);
  border-radius: 50%;
  box-shadow: 0 2px 10px rgba(22,163,74,.3);
}
.pg-estado-titulo {
  margin: 0 0 6px; font-size: 14.5px; font-weight: 650; color: var(--text);
}
.pg-estado-texto {
  margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.55;
}
.pg-estado-texto strong { color: var(--text); font-weight: 650; }
#pgSucesso .pg-botao { margin-top: 16px; }

.pg-indisponivel {
  font-size: 12.5px; color: var(--muted); line-height: 1.6;
  text-align: center;
}
.pg-indisponivel a { color: var(--mpesa, #e2062c); font-weight: 600; }

/* ---------- Base de demonstração ---------- */
/* Cor de alerta (âmbar) e barra lateral: o utilizador tem de reparar bem que
   os dados não são dele antes de tomar os resultados por seus. Não é a
   vermelha de erro — nada está errado — mas exige atenção. */
.aviso-demo {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: color-mix(in srgb, var(--inferred) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--inferred) 45%, transparent);
  border-left: 5px solid var(--inferred);
  border-radius: var(--radius);
  padding: 13px 17px; margin-bottom: 16px;
  font-size: 13px; line-height: 1.55;
}
.aviso-demo strong { color: var(--inferred); white-space: nowrap; }
.aviso-demo span { flex: 1; min-width: 220px; color: var(--text); }

.entrada-demo {
  text-align: center; margin: 18px 0 0;
  font-size: 13.5px; color: var(--muted);
}
/* Um botão que se lê como ligação: a ação é secundária e não deve competir
   com «Analisar os meus dados». */
.ligacao {
  font: inherit; background: none; border: none; padding: 0;
  color: var(--accent); cursor: pointer; text-decoration: underline;
  text-underline-offset: 2px;
}
.ligacao:hover { color: var(--text); }

/* ---------- Convite para criar conta ---------- */
/* Dispensável por decisão: quem não quiser conta continua a ver e a
   exportar tudo. A conta serve para guardar, não para desbloquear. */
.convite {
  display: flex; align-items: center; justify-content: space-between;
  gap: 18px; flex-wrap: wrap;
  margin-top: 24px; padding: 18px 22px;
  background: linear-gradient(
    120deg, color-mix(in srgb, var(--accent) 6%, var(--surface)),
    var(--surface) 60%);
  border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  animation: sobe .3s ease-out;
}
@keyframes sobe { from { opacity: 0; transform: translateY(8px); } }

.convite-txt { min-width: 240px; flex: 1; }
.convite-txt strong { display: block; font-size: 14.5px; font-weight: 620; }
.convite-txt span {
  display: block; font-size: 13px; color: var(--muted);
  line-height: 1.5; margin-top: 3px;
}
.convite-acoes { display: flex; align-items: center; gap: 10px; }

.btn-texto {
  font: inherit; font-size: 13px; color: var(--muted);
  background: none; border: none; cursor: pointer; padding: 8px 6px;
}
.btn-texto:hover { color: var(--text); text-decoration: underline; }

/* ---------- Painel de administração ---------- */

.painel-body { background: var(--bg); }

/* O cabeçalho fica colado ao topo; a barra de navegação cola logo por
   baixo. `--alt-topo` é medido em JS noutras páginas, mas aqui o cabeçalho
   do painel tem altura estável, por isso um valor fixo chega. */
.painel-top { position: sticky; top: 0; z-index: 30; }

.painel-nav {
  position: sticky; top: 63px; z-index: 25;
  display: flex; gap: 2px; overflow-x: auto;
  justify-content: center;
  padding: 0 26px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}
.painel-nav::-webkit-scrollbar { display: none; }
/* Num ecrã estreito as abas passam a rolar; aí encostam à esquerda para não
   cortar a primeira. */
@media (max-width: 620px) {
  .painel-nav { justify-content: flex-start; }
}

.painel-tab {
  flex-shrink: 0;
  font: inherit; font-size: 13.5px; font-weight: 550;
  color: var(--muted); background: none; border: none; cursor: pointer;
  padding: 13px 15px 11px;
  border-bottom: 2px solid transparent;
  transition: color .12s, border-color .12s;
}
.painel-tab:hover { color: var(--text); }
.painel-tab.ativo {
  color: var(--accent); border-bottom-color: var(--accent);
}

.painel-main {
  max-width: 1180px; margin: 0 auto; padding: 24px 26px 40px;
}

.painel-vista { animation: painel-fade .18s ease; }
@keyframes painel-fade { from { opacity: 0; transform: translateY(4px); } }

.painel-grelha {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 18px; margin-bottom: 18px;
}
.painel-bloco {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 22px;
  box-shadow: var(--shadow); min-width: 0;
  margin-bottom: 18px;
}
.painel-bloco:last-child { margin-bottom: 0; }
.painel-grelha .painel-bloco { margin-bottom: 0; }
.painel-bloco .grafico {
  border: none; box-shadow: none; padding: 0; background: transparent;
  max-width: none;
}
.painel-bloco .table-wrap { box-shadow: none; }
.painel-bloco > .res-t:first-child { margin-bottom: 16px; }

.painel-bloco-acoes {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}

.painel-sub { font-size: 12px; color: var(--muted); }

@media (max-width: 780px) {
  .painel-nav { top: 0; }
  .painel-main { padding: 18px 14px 32px; }
  .painel-grelha { grid-template-columns: 1fr; gap: 14px; }
  .painel-bloco { padding: 16px; }
}

/* ---------- Funil ---------- */
.funil { display: flex; flex-direction: column; gap: 14px; padding: 6px 0; }
.funil-cab {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 10px; margin-bottom: 5px;
}
.funil-rotulo { font-size: 13.5px; }
.funil-valor {
  font-size: 13px; font-weight: 620; color: var(--muted);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.funil-barra {
  height: 9px; border-radius: 5px; background: var(--hover); overflow: hidden;
}
.funil-preenchida {
  height: 100%; border-radius: 5px;
  transition: width .5s cubic-bezier(.4, 0, .2, 1);
  min-width: 3px;
}

.sim, .nao {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600;
  border: 1px solid currentColor;
  background: color-mix(in srgb, currentColor 10%, transparent);
}
.sim { color: var(--file); }
.nao { color: var(--muted); }

/* ---------- Rodapé ---------- */
.rodape {
  text-align: center; padding: 32px 24px 40px;
  border-top: 1px solid var(--border); margin-top: 40px;
  font-size: 12.5px; color: var(--muted);
}
.rodape p { margin: 0; }
.rodape-guias {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 6px 18px; margin: 0 auto 16px; max-width: 720px;
}
.rodape-guias a { color: var(--muted); text-decoration: none; }
.rodape-guias a:hover { color: var(--accent); text-decoration: underline; }
.rodape-marca {
  margin-top: 4px !important; font-weight: 640; font-size: 13.5px;
  background: linear-gradient(120deg, var(--accent), #7c3aed);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* ---------- Análises acumuladas ---------- */
/* Barra fixa no canto: acompanha o trabalho sem ocupar a área de leitura. */
.pilha {
  position: fixed; bottom: 20px; right: 20px; z-index: 35;
  width: min(320px, calc(100vw - 40px));
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 12px; box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: sobe .25s ease-out;
}
.pilha-cab {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; font: inherit; font-size: 13.5px; font-weight: 600;
  padding: 13px 16px; cursor: pointer;
  background: transparent; color: var(--text); border: none;
}
.pilha-cab:hover { background: var(--hover); }
.pilha-conta { display: flex; align-items: center; gap: 8px; }
.pilha-conta::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
}
.pilha-seta { color: var(--muted); font-size: 11px; transition: transform .15s; }
.pilha.is-aberta .pilha-seta { transform: rotate(180deg); }

.pilha-corpo {
  max-height: 210px; overflow-y: auto;
  border-top: 1px solid var(--border); padding: 6px 10px;
}
.pilha-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 7px 6px; font-size: 12.5px;
  border-bottom: 1px solid var(--border);
}
.pilha-item:last-child { border-bottom: none; }
.pilha-nome {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pilha-item .btn-mini { opacity: 1; padding: 1px 7px; font-size: 14px; }

.pilha-acoes {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 14px; border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.pilha-acoes .btn-primary { flex: 1; font-size: 13px; padding: 8px 14px; }

/* ---------- Projetos guardados ---------- */
.btn-guardar { font-size: 13px; padding: 7px 14px; }

.btn-nova {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; padding: 7px 14px;
}
.icone-mais {
  width: 14px; height: 14px; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 2.2;
  stroke-linecap: round;
}

.proj-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 13px 0;
  border-bottom: 1px solid var(--border);
}
.proj-item:last-child { border-bottom: none; }
.proj-info { min-width: 0; flex: 1; }
.proj-nome {
  font-size: 14px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.proj-meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.proj-data { font-size: 12px; color: var(--muted); opacity: .8; margin-top: 1px; }

.proj-acoes { display: flex; gap: 6px; flex-shrink: 0; }
.btn-mini-solido {
  font: inherit; font-size: 12px; font-weight: 550;
  padding: 5px 12px; border-radius: 6px; cursor: pointer;
  background: var(--accent); color: #fff; border: 1px solid var(--accent);
}
.btn-mini-solido:hover { filter: brightness(1.07); }
/* No painel os botões estão sempre visíveis: não há linha para percorrer. */
.proj-acoes .btn-mini { opacity: 1; }

.proj-vazio {
  font-size: 13.5px; color: var(--muted); line-height: 1.6;
  text-align: center; padding: 32px 12px; margin: 0;
}
.proj-espaco { font-size: 12.5px; color: var(--muted); }

/* ---------- Carregamento ---------- */
.dropzone {
  background: var(--surface);
  border: 2px dashed var(--border-strong);
  border-radius: 16px;
  padding: 64px 24px;
  text-align: center;
  transition: border-color .18s, background .18s, transform .18s;
}
.dropzone.is-over {
  border-color: var(--accent); background: var(--accent-soft);
  transform: scale(1.006);
}
.dropzone.is-over .dz-icon { stroke: var(--accent); }
.dz-inner { max-width: 540px; margin: 0 auto; }
.dz-icon {
  width: 52px; height: 52px; margin-bottom: 14px;
  fill: none; stroke: var(--muted); stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}
/* O h3 é o título dentro da área de carregamento; o h2 fica na headline. */
.dropzone h3 {
  margin: 0 0 8px; font-size: 22px; font-weight: 620; letter-spacing: -.3px;
}
.dropzone p { margin: 0 0 22px; color: var(--muted); font-size: 16px; }
code {
  background: var(--bg); border: 1px solid var(--border);
  padding: 2px 7px; border-radius: 5px; font-size: .92em;
}

/* ---------- Botões ---------- */
.btn-primary, .btn-ghost {
  font: inherit; font-size: 14px; font-weight: 550;
  padding: 9px 17px; border-radius: 8px; cursor: pointer;
  transition: background .13s, border-color .13s, transform .1s,
              box-shadow .13s;
}
.btn-primary {
  background: var(--accent); color: #fff; border: 1px solid var(--accent);
  box-shadow: 0 1px 3px rgba(31,111,235,.25);
}
.btn-primary:hover {
  filter: brightness(1.07); box-shadow: 0 2px 8px rgba(31,111,235,.32);
}
.btn-primary:active, .btn-ghost:active { transform: translateY(1px); }
.btn-ghost {
  background: var(--surface); color: var(--text); border: 1px solid var(--border-strong);
}
.btn-ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-ghost:disabled { opacity: .45; cursor: default; }

/* ---------- Estados ---------- */
.loading { text-align: center; padding: 48px; color: var(--muted); }
.spinner {
  width: 26px; height: 26px; margin: 0 auto 12px;
  border: 2.5px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.alert {
  padding: 12px 16px; border-radius: var(--radius);
  margin-bottom: 18px; font-size: 14px;
}
.alert-error {
  background: var(--danger-soft); color: var(--danger);
  border: 1px solid currentColor;
}
.alert-ok {
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid currentColor;
}
.note {
  background: var(--warn-soft); border: 1px solid var(--warn-border);
  border-radius: var(--radius); padding: 11px 15px;
  margin-bottom: 10px; font-size: 13.5px; line-height: 1.5;
}

/* ---------- Resumo ---------- */
/* Faixa fixa: cartões-resumo + abas acompanham o cabeçalho. `--alt-topo` é a
   altura real do cabeçalho, medida em JS (ele muda de altura ao passar a
   várias linhas em ecrãs estreitos). Os margens negativos esticam a faixa até
   às margens do `main`, para o conteúdo não se ver a passar pelos lados. */
.barra-fixa {
  position: sticky; top: var(--alt-topo, 66px); z-index: 20;
  margin: -26px -26px 0; padding: 26px 26px 0;
  background: var(--bg);
}
/* Os cartões-resumo vivem no cabeçalho, centrados no espaço que sobra entre
   a marca (oculta) e as ações à direita. Ficam compactos para o cabeçalho
   não crescer demais. */
.summary {
  flex: 1 1 auto; min-width: 0;
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 8px; margin: 0;
}
.stat {
  display: flex; align-items: center; gap: 9px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px 12px; min-width: 0;
  box-shadow: var(--shadow);
  transition: transform .14s, box-shadow .14s;
}
.stat:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.stat-texto { min-width: 0; }
.stat-icone {
  width: 18px; height: 18px; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
  color: var(--muted); opacity: .85;
}
/* Os círculos do ícone nominal são preenchidos, não traçados. */
.stat-icone circle { fill: currentColor; stroke: none; }
.stat-value {
  font-size: 16px; font-weight: 640; line-height: 1.1;
  font-variant-numeric: tabular-nums; letter-spacing: -.3px;
}
.stat-label {
  font-size: 10px; color: var(--muted); margin-top: 1px;
  text-transform: uppercase; letter-spacing: .5px; font-weight: 550;
}
/* O cartão «lidas do ficheiro» é o indicador central do produto. */
.stat.highlight {
  border-color: var(--file);
  background: linear-gradient(
    to bottom, color-mix(in srgb, var(--file) 7%, var(--surface)), var(--surface));
}
.stat.highlight .stat-value { color: var(--file); }

/* Sinal de identificador provável, junto ao nível de medida e na lista de
   escolha de variáveis. Reaproveita o âmbar de `--inferred`, que já é a cor
   do «isto precisa da sua confirmação» em todo o produto. */
.sinal-id {
  display: inline-grid; place-items: center;
  width: 1.19em; height: 1.19em; margin-left: .44em;
  border-radius: 50%; cursor: help; flex-shrink: 0;
  font-size: .815em; font-weight: 700; line-height: 1;
  color: var(--inferred);
  background: color-mix(in srgb, var(--inferred) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--inferred) 40%, transparent);
}

/* ---------- Separadores ---------- */
/* As abas e o tamanho do texto partilham a linha: o seletor encosta à direita
   e alinha-se pela base das abas, para não empurrar o conteúdo. */
.tabs-linha {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
}
.tam-texto { margin-bottom: 7px; flex-shrink: 0; }

/* Abas coloridas como as folhas do Excel: a cor está na própria aba, não só
   no texto. A inativa fica esbatida, a ativa ganha a cor cheia e liga-se ao
   conteúdo por baixo. */
.tabs { display: flex; gap: 3px; margin-bottom: -1px; padding-left: 2px; }
.tab {
  position: relative;
  display: inline-flex; align-items: center; gap: 8px;
  font: inherit; font-size: 14px; font-weight: 600;
  padding: 11px 22px 10px; cursor: pointer;
  color: color-mix(in srgb, var(--cor-aba) 78%, var(--text));
  background: color-mix(in srgb, var(--cor-aba) 12%, var(--bg));
  border: 1px solid color-mix(in srgb, var(--cor-aba) 24%, transparent);
  border-bottom: none;
  border-radius: 9px 9px 0 0;
  transition: background .14s, color .14s, padding .14s;
}
.tab:hover {
  background: color-mix(in srgb, var(--cor-aba) 20%, var(--bg));
}
.tab .tab-dot {
  width: 9px; height: 9px; border-radius: 2.5px;
  background: var(--cor-aba); opacity: .65;
  transition: opacity .14s;
}

.tab.is-active {
  background: var(--surface);
  color: var(--cor-aba);
  border-color: var(--border);
  padding-top: 13px;   /* sobressai ligeiramente, como uma folha à frente */
}
.tab.is-active::before {
  content: ''; position: absolute; inset: 0 0 auto; height: 3px;
  border-radius: 9px 9px 0 0; background: var(--cor-aba);
}
/* Tapa a linha do contentor por baixo: a aba ativa fica ligada ao conteúdo. */
.tab.is-active::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px;
  height: 2px; background: var(--surface);
}
.tab.is-active .tab-dot { opacity: 1; }

/* Cores fixas, uma por vista. */
.tab[data-view="variables"] { --cor-aba: var(--via-variaveis); }
.tab[data-view="data"]      { --cor-aba: var(--via-dados); }
.tab[data-view="analyses"]  { --cor-aba: var(--via-analises); }

/* A área de conteúdo recebe a mesma cor no topo, ligando-a à aba ativa.
   Quando existe barra de rolagem por cima, é ela o topo visível e é ela que
   leva a cor — senão a linha ficava escondida a meio do bloco. */
.view > .table-wrap, .view .analyses > .an-side, .view > .scroll-topo {
  border-top: 2px solid var(--cor-vista, var(--border));
}
.view > .scroll-topo:not([hidden]) + .table-wrap { border-top-color: var(--border); }
#view-variables { --cor-vista: var(--via-variaveis); }
#view-data      { --cor-vista: var(--via-dados); }
#view-analyses  { --cor-vista: var(--via-analises); }


/* ---------- Tabelas ---------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow);
}

/* Barra de rolagem horizontal por cima da tabela. Com centenas de linhas, a
   barra nativa fica no fundo da grelha — para chegar às colunas da direita
   era preciso primeiro rolar a página até baixo. Esta é um duplicado: um
   elemento vazio, com a mesma largura do conteúdo real, cuja posição é
   sincronizada com a da tabela nos dois sentidos (ver app.js). */
.scroll-topo {
  overflow-x: auto;
  overflow-y: hidden;
  /* Sem conteúdo próprio, só a barra. A altura vem do JS, medida no browser,
     porque a espessura da barra varia com o sistema. */
  height: var(--altura-barra, 12px);
  /* Fica colada por baixo da faixa fixa: descer na lista de casos não a
     leva para fora do ecrã, que é precisamente o problema que resolve.
     `z-index` acima do cabeçalho da grelha (que é 1), para que a barra não
     desapareça por trás dele. */
  position: sticky; top: var(--alt-fixa, 0px); z-index: 2;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 0 var(--radius) 0 0;
}
.scroll-topo > div { height: 1px; }
/* Quando a tabela cabe toda, não há barra nenhuma a mostrar. */
.scroll-topo[hidden] { display: none; }

/* A tabela e a barra ficam coladas: a barra por cima, a grelha por baixo. */
.scroll-topo + .table-wrap { border-top-left-radius: 0; border-top-right-radius: 0; }
.grid { width: 100%; border-collapse: collapse; font-size: 13.5px; }
/* Nas Vistas de Variáveis e de Dados a grelha segue «Tamanho do texto». Os
   tamanhos internos (badges, etiquetas, botões) passam a `em` mais abaixo,
   para crescerem com ela em vez de ficarem para trás. */
#view-variables .grid, #view-data .grid {
  font-size: calc(13.5px * var(--escala-texto, 1));
}
.grid thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2);
  text-align: left; font-weight: 600; font-size: .852em;
  color: var(--muted); text-transform: uppercase; letter-spacing: .5px;
  padding: .815em .963em; white-space: nowrap;
  border-bottom: 1px solid var(--border-strong);
}
.grid td {
  padding: .667em .963em; border-bottom: 1px solid var(--border);
}
.grid tbody tr:last-child td { border-bottom: none; }
.grid tbody tr { transition: background .1s; }
.grid tbody tr:hover { background: var(--hover); }
.grid .num, .grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
.col-num { width: 42px; }
.col-origin { width: 96px; }

.row-num { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .926em; }
.var-name {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: .926em; font-weight: 550;
}
/* «Etiqueta» é a coluna elástica da Vista de Variáveis: as restantes têm
   conteúdo de tamanho previsível, esta pode trazer uma frase inteira vinda
   do .sav. É aqui que se absorve a falta de espaço — corta com reticências
   em vez de alargar a tabela e obrigar tudo a rolar. O texto completo fica
   na dica e no painel de edição. */
.var-label {
  color: var(--text);
  max-width: 1px;  /* Com `width: 100%` na tabela, obriga a coluna a ceder. */
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.var-label.empty { color: var(--muted); font-style: italic; }

/* ---------- Etiquetas ---------- */
.badge {
  display: inline-block; padding: .185em .74em; border-radius: 20px;
  font-size: .852em; font-weight: 600; white-space: nowrap;
  border: 1px solid currentColor;
  /* Fundo esbatido da própria cor: legível sem gritar. */
  background: color-mix(in srgb, currentColor 9%, transparent);
}
.m-nominal { color: var(--nominal); }
.m-ordinal { color: var(--ordinal); }
.m-scale   { color: var(--scale); }
.m-unknown { color: var(--unknown); }

.origin { font-size: .852em; font-weight: 600; }
.o-file     { color: var(--file); }
.o-inferred { color: var(--inferred); }
.o-user     { color: var(--user); }

/* «Valores» só tem a contagem e o botão, por isso ocupa o que precisa e
   nada mais: é o que permite à Vista de Variáveis caber sem rolagem
   horizontal. A largura é fixa porque o conteúdo também o é. */
.col-values { width: 118px; }
.vl-cell { display: flex; align-items: center; gap: 8px; }
.vl-vazio { color: var(--muted); }

/* Texto secundário que corta em vez de alargar a coluna. Usado no painel de
   acompanhamento, na coluna de detalhe dos eventos. */
.vl-preview {
  font-size: .926em; color: var(--muted);
  max-width: 1px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.vl-count {
  flex: none;
  font-size: .852em; color: var(--accent);
  background: var(--accent-soft); border-radius: 4px;
  padding: 1px 6px; font-weight: 600;
}

/* `margin-left: auto` encosta-o à direita mesmo quando não há etiquetas
   para pré-visualizar; `flex: none` impede que encolha até ficar ilegível. */
.btn-edit {
  flex: none; margin-left: auto;
  font: inherit; font-size: .926em; padding: .222em .74em;
  border: 1px solid var(--border-strong); border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer;
  white-space: nowrap;
}
.btn-edit:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Vista de Dados ---------- */
.data-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  padding: 10px 2px 14px;
}
.switch { display: flex; align-items: center; gap: 8px; font-size: 13.5px; cursor: pointer; }
.switch input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.pager { display: flex; align-items: center; gap: 10px; }
.page-info { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.data-grid td { font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-grid .is-label { font-variant-numeric: normal; }
.cell-user, .cell-system { font-style: italic; }
.cell-user { color: var(--inferred); }
.cell-system { color: var(--muted); }

.legend {
  display: flex; align-items: center; gap: 8px;
  font-size: calc(12.5px * var(--escala-texto, 1));
  color: var(--muted); margin: 12px 2px 0;
}
.chip {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 3px; margin-left: 10px;
}
.chip:first-child { margin-left: 0; }
.chip-user { background: var(--inferred); }
.chip-system { background: var(--muted); }

/* ---------- Análises ---------- */
/* Painel de controlo fixo à esquerda, resultados à direita: o utilizador
   mexe nas opções e vê o efeito sem perder de vista nenhum dos dois. */
.analyses {
  display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 20px;
  align-items: start;
}
/* Com a coluna de publicidade activa (visitante sem sessão, ecrã largo), a
   grelha ganha uma 3ª faixa fixa à direita — o espaço que os resultados,
   presos à medida de leitura, não ocupavam. */
.analyses:has(.an-ads:not([hidden])) {
  grid-template-columns: 300px minmax(0, 1fr) 320px;
}
.an-ads { min-width: 0; }
.an-ads .ad-slot-lateral {
  position: sticky; top: calc(var(--alt-fixa, 0px) + 16px);
  margin: 0; width: 100%; max-width: 320px;
  min-height: 250px;
}

@media (max-width: 1180px) {
  /* Sem espaço para a 3ª coluna: a publicidade lateral desliga. */
  .analyses:has(.an-ads:not([hidden])) {
    grid-template-columns: 320px minmax(0, 1fr);
  }
  .an-ads { display: none !important; }
}
@media (max-width: 980px) {
  .analyses,
  .analyses:has(.an-ads:not([hidden])) { grid-template-columns: 1fr; }
  .an-side-in { position: static !important; max-height: none !important; }
}

.an-side {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  box-shadow: var(--shadow);
}
.an-side-in {
  position: sticky; top: calc(var(--alt-fixa, 0px) + 16px);
  max-height: calc(100vh - var(--alt-fixa, 0px) - 32px); overflow-y: auto;
  padding: 16px;
}

.an-sec { margin-bottom: 18px; }
.an-sec-h {
  display: block; font-size: 11.5px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .4px; margin-bottom: 7px;
}
.an-picker {
  width: 100%; font: inherit; font-size: 13.5px; font-weight: 550;
  padding: 9px 11px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--bg); color: var(--text);
}
.an-picker:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.an-when {
  font-size: 12.5px; line-height: 1.5; padding: 9px 12px;
  background: var(--accent-soft); border-radius: 8px;
  margin: 9px 0 0;
}

.an-auto {
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; color: var(--muted); cursor: pointer;
  padding-top: 12px; border-top: 1px solid var(--border);
}
.an-auto input { width: 14px; height: 14px; accent-color: var(--accent); cursor: pointer; }
.an-run { width: 100%; margin-top: 10px; }

/* Coluna dos resultados */
.an-main { min-width: 0; }
.an-empty, .an-calc {
  color: var(--muted); font-size: 14px; text-align: center;
  padding: 60px 20px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.an-empty p, .an-calc p { margin: 0; }
.an-calc { padding: 40px 20px; }

.an-field { margin-bottom: 16px; }
.an-field-h { margin-bottom: 7px; }
.an-field-t {
  font-size: 11.5px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .4px;
}
.an-opt { font-weight: 400; color: var(--muted); }
.an-field-a {
  display: block; font-size: 12.5px; color: var(--muted);
  margin-top: 2px; line-height: 1.45;
}
.an-none { font-size: 13px; color: var(--muted); font-style: italic; }

/* Lista vertical: no painel estreito, chips lado a lado partiriam os nomes
   e as etiquetas das variáveis deixariam de se ler. */
.an-vars {
  display: flex; flex-direction: column; gap: 3px;
  max-height: 220px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 8px; padding: 5px;
  background: var(--bg);
}
.an-var {
  display: flex; align-items: center; gap: 7px; width: 100%;
  font: inherit; font-size: 12.5px; cursor: pointer; text-align: left;
  padding: 6px 9px; border-radius: 6px;
  background: transparent; color: var(--text);
  border: 1px solid transparent;
  transition: background .12s;
}
.an-var:hover { background: var(--surface); border-color: var(--border); }
.an-var.is-on {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.an-var.is-on .an-var-l, .an-var.is-on .dot { color: #fff; opacity: .85; }
.an-var-n {
  font-family: ui-monospace, Consolas, monospace; font-weight: 550;
  flex-shrink: 0;
}
.an-var-l {
  color: var(--muted); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; flex-shrink: 0;
}

.an-actions { margin-top: 4px; }

/* ---------- Opções ---------- */
/* Realçadas com a cor da vista: distinguem-se da escolha de variáveis, que
   é o passo anterior. */
.an-opts {
  border: 1px solid color-mix(in srgb, var(--via-analises) 26%, transparent);
  border-left: 3px solid var(--via-analises);
  border-radius: 8px;
  margin: 4px 0 18px;
  background: color-mix(in srgb, var(--via-analises) 6%, var(--surface));
}
.an-opts-h {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 10px 13px; cursor: pointer;
  font-size: 13px; font-weight: 600; list-style: none;
  color: color-mix(in srgb, var(--via-analises) 65%, var(--text));
}
.an-opts-h::-webkit-details-marker { display: none; }
.an-opts-h::before {
  content: '▸'; color: var(--muted); font-size: 11px;
  transition: transform .15s;
}
.an-opts[open] .an-opts-h::before { transform: rotate(90deg); }
.an-opts-h > span:first-of-type { flex: 1; }
.an-opts-n { font-size: 12px; font-weight: 400; color: var(--muted); }

.an-opts-body { padding: 4px 13px 14px; }
.an-opts-g { margin-bottom: 14px; }
.an-opts-g:last-child { margin-bottom: 0; }
.an-opts-gt {
  font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .4px; margin-bottom: 7px;
}
.an-opts-l { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
/* Só dentro do painel de opções da análise é que cada linha ocupa a largura
   toda e o seletor estica. Antes esta regra não tinha o prefixo `.an-opts-l`
   e apanhava também o «Tamanho do texto» da barra das abas, esticando-o e
   empurrando-o para baixo das abas (a linha da vista descolava). */
.an-opts-l .an-opt-s { width: 100%; justify-content: space-between; }
.an-opts-l .an-opt-s select { flex: 1; margin-left: 8px; min-width: 0; }

.an-opt-b {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; cursor: pointer;
}
.an-opt-b input { width: 14px; height: 14px; accent-color: var(--accent); cursor: pointer; }

.an-opt-s { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; }
.an-opt-st { color: var(--muted); }
.an-opt-s select, .an-opt-num {
  font: inherit; font-size: 12.5px; padding: 4px 8px;
  border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--surface); color: var(--text); cursor: pointer;
}
.an-opt-num { max-width: 110px; cursor: text; }
.an-opt-s select:focus, .an-opt-num:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------- Resultados ---------- */
/* Largura útil de uma A4 retrato com margens de 2,5 cm ≈ 16 cm. É a largura
   de referência do texto — a leitura fica confortável e aproxima-se do que
   cabe na folha. Não é, porém, um limite rígido: com o texto ampliado uma
   tabela pode precisar de mais e não faz sentido pô-la a rolar enquanto
   sobra ecrã à direita. Por isso o limite aplica-se ao texto, não às
   tabelas. */
/* Sem margem superior: o painel de controlo está ao lado, não por cima. */
/* `--escala-texto` é definida em JS no `<html>`, a partir do seletor «Tamanho
   do texto» junto às abas, e vale para as três vistas. Aqui governa todo o
   resultado — tabelas, notas, hipóteses e interpretação — não só os gráficos.
   Os tamanhos abaixo são `em` para que uma única variável os mova a todos. */
.results { font-size: calc(15px * var(--escala-texto, 1)); }

/* Os blocos de texto corrido — notas, avisos — mantêm a medida de leitura:
   linhas muito longas cansam a vista. */
.results > *:not(.res-bloco):not(.res-hip):not(.res-interp) { max-width: 680px; }
.res-bloco > *:not(.table-wrap) { max-width: 680px; }

/* As hipóteses e a interpretação são exceção: o texto traz os nomes das
   variáveis do utilizador, que podem ser longos («Satisfação com as
   condições de trabalho»). Presos a 680px, partiam-se em muitas linhas
   curtas enquanto sobrava ecrã à direita. Ficam com uma medida maior — o
   suficiente para uma hipótese caber em poucas linhas, sem chegar ao ponto
   em que o olho se perde a saltar de linha. */
.results > .res-hip, .results > .res-interp { max-width: 940px; }

/* A tabela ocupa o necessário até ao limite do espaço disponível: nunca
   menos do que a medida de leitura, nunca mais do que a coluna. Assim a
   barra de rolagem só aparece quando o espaço à direita se esgotou mesmo. */
.results .table-wrap { width: fit-content; min-width: min(680px, 100%); max-width: 100%; }
.res-cab {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-bottom: 16px;
}
.res-h { margin: 0; font-size: 19px; font-weight: 640; }
/* Dentro dos resultados os títulos acompanham a escala; no painel de
   acompanhamento, que reutiliza estas classes, ficam no tamanho fixo. */
.results .res-h { font-size: 1.267em; }
.results .res-t { font-size: .933em; }
.res-bloco { margin-bottom: 22px; }

/* Título e ações na mesma linha: os botões só aparecem ao passar o rato,
   para não competirem com o conteúdo. */
.res-t-linha {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 9px;
}
.res-t { margin: 0; font-size: 14px; font-weight: 600; }
.graf-acoes { display: flex; gap: 4px; }

.btn-mini {
  font: inherit; font-size: 11.5px; font-weight: 550;
  padding: 3px 9px; border-radius: 5px; cursor: pointer;
  background: transparent; color: var(--muted);
  border: 1px solid var(--border);
  opacity: 0; transition: opacity .13s, border-color .13s, color .13s;
}
.res-bloco:hover .btn-mini, .res-hip:hover .btn-mini,
.btn-mini:focus { opacity: 1; }
.btn-mini:hover { border-color: var(--accent); color: var(--accent); }

.res-export { display: flex; gap: 7px; }
.btn-export {
  font: inherit; font-size: 13px; font-weight: 550;
  padding: 7px 15px; border-radius: 7px; cursor: pointer;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong);
  transition: border-color .13s, color .13s;
}
.btn-export:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-export:disabled { opacity: .55; cursor: default; }

@media (hover: none) {
  /* Em ecrãs táteis não há «passar o rato»: os botões ficam sempre visíveis. */
  .btn-mini { opacity: 1; }
}

/* Tabelas de resultados: compactas e legíveis em A4, ao contrário da grelha
   de dados, que é para consulta em ecrã. */
.results .grid { font-size: .833em; }
.results .grid thead th { padding: .47em .6em; font-size: .733em; }
.results .grid td { padding: .4em .6em; }
.results .table-wrap { border-radius: var(--radius); }
.res-nota {
  margin: 8px 2px 0; font-size: .833em; color: var(--muted); line-height: 1.5;
}
/* Linha de fecho (Total, Omissos): fundo próprio e negrito, para se ler de
   relance como fecho do bloco e não como mais uma categoria. O `:hover` da
   grelha é anulado — destacá-la ao passar o rato sugeria que era clicável. */
.linha-total td {
  font-weight: 700;
  background: var(--surface-2);
  border-top: 1px solid var(--border-strong);
  border-bottom-color: var(--border-strong);
}
.grid tbody tr.linha-total:hover { background: transparent; }
.grid tbody tr.linha-total:hover td { background: var(--surface-2); }

.grafico {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px; box-shadow: var(--shadow);
  /* A largura vem do JS, em px, conforme o tamanho escolhido. */
}

/* ---------- Avisos ---------- */
/* A gravidade tem de se ver antes de se ler. Um pressuposto violado põe em
   causa o resultado que a pessoa vai copiar para a tese — apresentá-lo na
   mesma caixa cinzenta de uma nota de método é deixá-lo passar despercebido,
   que é justamente o engano que este produto existe para evitar. */
.aviso {
  display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap;
  border-radius: var(--radius); padding: 13px 16px;
  margin-bottom: 10px; font-size: .889em; line-height: 1.55;
  border: 1px solid var(--border); background: var(--surface-2);
}
.aviso-corpo {
  flex: 1; min-width: 240px;
  display: flex; align-items: flex-start; gap: 10px;
}
/* O ícone dá a gravidade num relance, antes de o texto ser lido. Sem ele, a
   diferença entre um pressuposto violado e uma nota de método só se percebe
   depois de ler as duas — e a essa altura já leu ambas como iguais. */
.aviso-icone { flex: none; font-size: 1.05em; line-height: 1.45; }
.aviso-texto { flex: 1; min-width: 0; }
.aviso-rotulo {
  display: block; font-size: .9em; margin-bottom: 3px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .4px;
}

/* Crítico: o resultado que ele está prestes a copiar para a tese não é de
   fiar. Não é um erro — o cálculo correu bem — mas tem de parar aqui, e
   por isso leva o mesmo peso visual de um alerta. */
.aviso-critico {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
  border-left: 5px solid var(--danger);
  color: var(--text);
}
.aviso-critico .aviso-rotulo { color: var(--danger); }

.aviso-atencao {
  background: var(--warn-soft);
  border-color: var(--warn-border);
  border-left: 5px solid color-mix(in srgb, var(--warn-border) 80%, #000 20%);
  color: var(--text);
}
.aviso-atencao .aviso-rotulo {
  color: color-mix(in srgb, var(--warn-border) 45%, #000 55%);
}
@media (prefers-color-scheme: dark) {
  /* No escuro o amarelo da borda é demasiado escuro para servir de texto. */
  :root:not([data-theme="light"]) .aviso-atencao .aviso-rotulo {
    color: color-mix(in srgb, var(--warn-border) 55%, #fff 45%);
  }
}
:root[data-theme="dark"] .aviso-atencao .aviso-rotulo {
  color: color-mix(in srgb, var(--warn-border) 55%, #fff 45%);
}

.aviso-nota { color: var(--muted); }

/* O botão que resolve. Sempre visível, ao contrário dos `.btn-mini` que só
   aparecem ao passar o rato: aqui é a saída para o problema, não uma ação
   acessória. */
.aviso-troca {
  opacity: 1; flex: none; align-self: center;
  border-color: var(--danger); color: var(--danger);
  background: var(--surface);
}
.aviso-troca:hover { border-color: var(--danger); background: var(--danger-soft); }

/* As hipóteses são contexto, não resultado: ficam num bloco discreto, sem o
   destaque da interpretação, para não competirem com as tabelas. */
.res-hip {
  margin-bottom: 22px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.hip-item + .hip-item {
  margin-top: 12px; padding-top: 12px;
  border-top: 1px solid var(--border);
}
.hip-ctx {
  margin: 0 0 5px; font-size: .833em; font-weight: 600; color: var(--muted);
}
.hip-linha {
  margin: 0 0 4px; font-size: .933em; line-height: 1.6;
  padding-left: 30px; text-indent: -30px;
}
.hip-linha:last-of-type { margin-bottom: 0; }
.hip-simbolo {
  display: inline-block; width: 30px; text-indent: 0;
  font-weight: 650; color: var(--accent);
}
.hip-nota {
  margin: 7px 0 0; font-size: .8em; color: var(--muted); line-height: 1.5;
}

/* A interpretação é o coração do produto: distingue-se do resto com uma
   barra lateral e um fundo ligeiramente destacado. */
.res-interp {
  background: linear-gradient(
    to right, color-mix(in srgb, var(--accent) 4%, var(--surface)),
    var(--surface) 40%);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: 20px 22px;
  box-shadow: var(--shadow);
}
.res-interp-h {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px;
}
.res-interp-h h3 { margin: 0; font-size: .933em; font-weight: 620; }
.res-p {
  margin: 0 0 12px; font-size: .967em; line-height: 1.7;
  text-align: justify;
}
.res-p:last-of-type { margin-bottom: 0; }
.res-aviso {
  margin: 16px 0 0; padding-top: 12px; border-top: 1px solid var(--border);
  font-size: .8em; color: var(--muted); line-height: 1.5;
}

/* ---------- Painel ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(10,14,20,.42);
  z-index: 40; animation: fade .15s;
}
@keyframes fade { from { opacity: 0; } }

.panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50;
  width: min(420px, 100vw);
  background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  box-shadow: -8px 0 28px rgba(10,14,20,.16);
  animation: slide .18s ease-out;
}
@keyframes slide { from { transform: translateX(100%); } }

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.panel-head h3 {
  margin: 0; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.panel-var {
  font-size: 15px; font-weight: 620;
  font-family: ui-monospace, Consolas, monospace;
}
.panel-sub {
  font-size: 12.5px; font-weight: 400; color: var(--muted);
  font-family: inherit;
}
.btn-close {
  background: none; border: none; color: var(--muted);
  font-size: 24px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.btn-close:hover { color: var(--text); }

.panel-body { padding: 20px; overflow-y: auto; flex: 1; }
.field { display: block; margin-bottom: 18px; }
.field > span {
  display: block; font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .4px; margin-bottom: 6px;
}
.field input[type=text], .field select {
  width: 100%; font: inherit; font-size: 14px;
  padding: 8px 11px; border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: var(--bg); color: var(--text);
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.panel-note {
  font-size: 12.5px; line-height: 1.5; padding: 10px 13px;
  border-radius: 8px; margin: -8px 0 18px;
  border: 1px solid var(--border);
}
/* Alterar algo declarado no SPSS merece mais destaque do que confirmar
   uma dedução — daí o realce só na origem "ficheiro". */
.note-file { background: var(--warn-soft); border-color: var(--warn-border); }
.note-inferred, .note-user { background: var(--bg); color: var(--muted); }

.vl-list { display: flex; flex-direction: column; gap: 7px; }
.vl-row { display: flex; align-items: center; gap: 8px; }
.vl-key {
  min-width: 46px; padding: 5px 9px; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--border);
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12.5px; text-align: center; color: var(--muted);
}
.vl-row input {
  flex: 1; font: inherit; font-size: 13.5px;
  padding: 6px 10px; border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg); color: var(--text);
}
.vl-empty { font-size: 13px; color: var(--muted); font-style: italic; }

.panel-foot {
  display: flex; justify-content: flex-end; gap: 9px; align-items: center;
  padding: 14px 20px; border-top: 1px solid var(--border);
}
/* O rodapé dos projetos tem só o resumo de espaço: alinha à esquerda. */
#projPanel .panel-foot { justify-content: flex-start; }

/* ---------- Ecrãs pequenos ---------- */
@media (max-width: 780px) {
  main { padding: 10px; }
  .top {
    padding: 10px 12px; gap: 8px;
  }
  .mark { width: 32px; height: 32px; font-size: 13px; }
  .top h1 { font-size: 14.5px; }
  .top-dir { gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

  .hero { padding: 24px 6px 22px; }
  .hero-h { font-size: clamp(23px, 6.5vw, 30px); }
  .hero-sub { font-size: 15px; }
  .dropzone { padding: 30px 14px; }
  .dropzone h3 { font-size: 18px; }
  .dropzone p { font-size: 14px; }
  .btn-grande { width: 100%; font-size: 16px; padding: 13px; }

  /* A FAIXA FIXA deixa de ser fixa no telemóvel: rola com a página. Assim
     as abas nunca ficam meio cortadas por baixo do cabeçalho. */
  .barra-fixa {
    position: static;
    margin: -10px -10px 0; padding: 10px 10px 0;
  }
  /* A faixa fixa deixou de ser sticky: os cabeçalhos de tabela colam
     directamente por baixo do cabeçalho da app (só ele continua fixo). */
  .scroll-topo { top: var(--alt-topo, 54px); }
  .grid thead th { top: var(--alt-topo, 54px); }

  /* Vistas de Variáveis e de Dados: a grelha rola na horizontal em vez de
     comprimir as colunas (era o que sobrepunha badges e texto). As células
     não quebram; a coluna «Etiqueta» corta com reticências. */
  #view-variables .table-wrap,
  #view-data .table-wrap {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
  }
  #view-variables .grid,
  #view-data .grid {
    width: max-content; min-width: 100%;
  }
  #view-variables .grid td,
  #view-data .grid td { white-space: nowrap; }
  /* A etiqueta continua a poder cortar — dá algum fôlego à largura. */
  #view-variables .var-label {
    white-space: nowrap; max-width: 160px;
  }
  /* «#» e nome da variável ficam fixos à esquerda ao rolar — são a âncora
     que diz a que linha pertence cada célula. */
  #view-variables .grid th:first-child,
  #view-variables .grid td:first-child {
    position: sticky; left: 0; z-index: 2;
    background: var(--surface);
  }
  #view-variables .grid th:nth-child(2),
  #view-variables .grid td:nth-child(2) {
    position: sticky; left: 42px; z-index: 2;
    background: var(--surface);
    box-shadow: 1px 0 0 var(--border);
  }
  #view-variables .grid thead th:first-child,
  #view-variables .grid thead th:nth-child(2) { background: var(--surface-2); }

  /* Cartões de resumo: uma tira que desliza na horizontal, em vez de uma
     grelha alta que empurra as abas para baixo do ecrã. */
  /* No telemóvel os cartões passam para uma linha própria do cabeçalho, numa
     tira que desliza na horizontal em vez de crescer em altura. */
  .summary {
    flex: 1 1 100%; order: 3;
    display: flex; flex-wrap: nowrap; justify-content: flex-start;
    gap: 8px; margin: 0;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    /* Sangra até às margens para o utilizador ver que há mais para o lado. */
    margin-inline: -12px; padding-inline: 12px;
  }
  .summary::-webkit-scrollbar { display: none; }
  .stat {
    flex: 0 0 auto; min-width: 0;
    padding: 6px 10px; gap: 7px;
  }
  .stat-value { font-size: 15px; }
  .stat-label { font-size: 9.5px; }
  .stat-icone { width: 16px; height: 16px; }

  /* Abas: sempre visíveis, deslizáveis, com área de toque generosa. */
  .tabs-linha { flex-direction: column; align-items: stretch; gap: 0; }
  .tabs {
    overflow-x: auto; scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    flex: 1 0 auto; justify-content: center;
    padding: 12px 16px 11px; font-size: 13.5px;
    min-height: 44px;
  }
  .tab.is-active { padding-top: 13px; }
  /* O seletor de tamanho do texto vai para baixo das abas, largura total. */
  .tam-texto {
    margin: 10px 0 0; width: 100%;
  }
  .tam-texto select { width: 100%; }

  /* A barra de análises acumuladas ocupa a largura toda, em baixo. */
  .pilha { left: 10px; right: 10px; bottom: 10px; width: auto; }
  .pilha-corpo { max-height: 150px; }

  .res-cab { gap: 10px; flex-wrap: wrap; }
  .results { font-size: calc(13.5px * var(--escala-texto, 1)); }
  .res-h { font-size: 16.5px; }
  .btn-export { font-size: 12.5px; padding: 6px 11px; }

  /* No telemóvel os resultados usam a largura toda: as barreiras de leitura
     (680/940px) não fazem sentido num ecrã já mais estreito que isso. */
  .results > *,
  .res-bloco > *:not(.table-wrap),
  .results > .res-hip,
  .results > .res-interp { max-width: none; }

  /* A tabela de resultados no telemóvel: largura da área, rola na horizontal
     dentro do seu contentor. As células NÃO quebram (era o que sobrepunha o
     texto) — quem quer ver a coluna da direita desliza a tabela. */
  .results .table-wrap {
    width: 100%; min-width: 0; max-width: 100%;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
  }
  .results .grid {
    width: max-content; min-width: 100%;
    font-size: .86em;
  }
  .results .grid th,
  .results .grid td {
    padding: .4em .55em;
    white-space: nowrap;      /* não quebra: desliza-se a tabela */
  }
  /* A primeira coluna (nome da variável / linha) fica fixa ao rolar para o
     lado — é a âncora que diz a que se refere cada número. */
  .results .grid th:first-child,
  .results .grid td:first-child {
    position: sticky; left: 0; z-index: 1;
    background: var(--surface);
    box-shadow: 1px 0 0 var(--border);
  }
  .results .grid thead th:first-child { background: var(--surface-2); }

  .results .grafico { width: 100%; }
  .an-plano.pagar-ativo { grid-template-columns: 1fr; }

  /* Os painéis laterais passam a folha inteira. */
  .panel { width: 100vw; }

  .convite { padding: 15px 16px; }
  .convite-acoes { width: 100%; }
  .convite-acoes .btn-google { flex: 1; justify-content: center; }

  .rodape { padding: 24px 14px 30px; margin-top: 28px; }

  /* Anúncios: sem margens laterais desperdiçadas, altura menor. */
  .ad-slot { margin: 14px auto; }
  .ad-slot-display { min-height: 90px; }
}

/* Telemóveis estreitos. */
@media (max-width: 460px) {
  main { padding: 8px; }
  .barra-fixa { margin: -8px -8px 0; padding: 8px 8px 0; }

  .tagline { display: none; }
  .btn-nova span, .btn-google span { font-size: 12px; }
  .btn-nova, .btn-guardar { padding: 6px 9px; font-size: 12px; gap: 5px; }
  .an-side-in { padding: 12px; }
  .an-vars { max-height: 180px; }

  /* Resultados: o mínimo de moldura, o máximo de conteúdo. */
  .results .table-wrap { border-left: 0; border-right: 0; border-radius: 0; }
  .res-bloco { margin-bottom: 18px; }
}

/* ---------- Contacto por WhatsApp (fixo) ---------- */
.wa-flutua {
  position: fixed; right: 22px; bottom: 22px;
  /* Acima do conteúdo, abaixo dos overlays e painéis (z 40/50). */
  z-index: 35;
  display: flex; flex-direction: column; align-items: flex-end; gap: 12px;
  transition: bottom .2s ease;
}
/* A barra de análises acumuladas (.pilha) vive no mesmo canto. Quando está
   visível, o botão sobe para não a tapar. */
body:has(#pilha:not([hidden])) .wa-flutua {
  bottom: 92px;
}
/* Com a lista expandida a barra é bem mais alta: o botão sai da frente
   deslizando para o lado, encostado à esquerda dela. */
body:has(#pilha.is-aberta) .wa-flutua {
  bottom: 22px;
  right: calc(22px + min(320px, calc(100vw - 40px)) + 14px);
}
@media (max-width: 720px) {
  /* Ecrã estreito: a barra ocupa quase tudo. O botão volta ao fundo, por
     baixo dela. */
  body:has(#pilha.is-aberta) .wa-flutua {
    right: 22px; bottom: 92px;
  }
}
.wa-botao {
  position: relative; flex-shrink: 0;
  width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center;
  background: #25d366; color: #fff;
  box-shadow: 0 6px 20px rgba(37,211,102,.42);
  transition: transform .18s, box-shadow .18s;
}
.wa-botao:hover {
  transform: scale(1.08);
  box-shadow: 0 8px 26px rgba(37,211,102,.55);
}
.wa-pulso {
  position: absolute; inset: -4px; border-radius: 50%;
  border: 3px solid #25d366;
  animation: wa-pulso 2.4s ease-out infinite; opacity: 0;
}
@keyframes wa-pulso {
  0%   { transform: scale(1);   opacity: .55; }
  100% { transform: scale(1.55); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .wa-pulso { animation: none; }
}

.wa-balao {
  max-width: 232px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px 14px 2px 14px;
  padding: 13px 15px 12px;
  box-shadow: var(--shadow-lg);
  font-size: 13px; line-height: 1.45;
  position: relative;
  opacity: 0; transform: translateY(8px) scale(.96);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}
.wa-balao.visivel {
  opacity: 1; transform: translateY(0) scale(1); pointer-events: auto;
}
.wa-balao p { margin: 0 0 10px; }
.wa-balao-btn {
  display: inline-block;
  background: #25d366; color: #fff;
  font-size: 12.5px; font-weight: 600;
  padding: 6px 14px; border-radius: 20px;
  transition: background .18s;
}
.wa-balao-btn:hover { background: #1ebe5d; }
.wa-balao-x {
  position: absolute; top: 5px; right: 8px;
  background: none; border: 0; padding: 0;
  font-size: 17px; line-height: 1; color: var(--muted); cursor: pointer;
}
.wa-balao-x:hover { color: var(--text); }

@media (max-width: 460px) {
  .wa-flutua { right: 16px; bottom: 16px; }
  .wa-botao { width: 50px; height: 50px; }
}

/* ---------- Anúncios (AdSense) ---------- */
/* Discretos e rotulados. Reserva de altura mínima para o anúncio não fazer
   a página saltar quando carrega. Só aparecem para visitantes sem sessão —
   ver ads.js. */
.ad-slot {
  /* O AdSense mexe nos estilos do <ins> e às vezes tenta pô-lo fora do
     fluxo. Isto prende-o dentro do slot: nunca sai da caixa nem se
     sobrepõe ao conteúdo. */
  position: relative;
  display: block;
  width: 100%;
  max-width: 680px;
  margin: 22px auto;
  padding: 0;
  overflow: hidden;
  text-align: center;
  contain: layout paint;
}
/* Reforça o [hidden] contra qualquer `display` que o AdSense injete. */
.ad-slot[hidden] { display: none !important; }

.ad-slot .adsbygoogle {
  display: block !important;
  position: static !important;
  width: 100% !important;
  max-width: 100% !important;
  height: auto;
  margin: 0 !important;
  left: auto !important; right: auto !important; top: auto !important;
}
.ad-slot-display { min-height: 100px; }
.ad-slot-in-article { min-height: 120px; margin: 26px auto; }
.ad-slot-lateral { min-height: 250px; }

/* Anúncio do topo: uma faixa fina, largura da página, logo abaixo do
   cabeçalho — visível em qualquer estado sem rolar. */
.ad-slot-topo {
  max-width: 970px;              /* leaderboard 728 + folga; responsivo abaixo */
  margin: 12px auto 4px;
  min-height: 90px;
}

.ad-rotulo {
  display: block;
  font-size: 10px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); opacity: .7;
  margin-bottom: 6px;
}
.results .ad-slot { max-width: 680px; }

@media (max-width: 980px) {
  .ad-slot-lateral { display: none; }
}
@media (max-width: 780px) {
  .ad-slot { max-width: 100%; margin: 16px auto; }
  .ad-slot-topo { margin: 8px auto 2px; min-height: 70px; }
}
@media (max-width: 460px) {
  .ad-slot { margin: 12px auto; }
}
