/* ==========================================================================
   NEURIS — Estilos Base
   Reset, custom properties, tipografia, grid, utilitários
   ========================================================================== */

/* --- Custom Properties --- */
:root {
  /* Paleta — Tema Claro (principal, default) */
  --color-bg: #ffffff;
  --color-surface: #e4ecf4;
  --color-surface-hover: #d8e3ee;
  --color-accent: #00c8a0;
  --color-accent-hover: #00ddb0;
  --color-accent-dim: rgba(0, 200, 160, 0.10);
  --color-accent-secondary: #f59e0b;
  /* Teal para uso em texto — #00c8a0 só é permitido como texto sobre navy
     ou no tema escuro. Este passa ≥5:1 sobre bg e surface. */
  --color-accent-text: #00705a;
  --color-text: #0d1117;
  --color-text-secondary: #4a5568;
  /* Texto terciário — labels, datas, placeholders, contadores, estados
     neutros. ≥4,5:1 sobre bg, surface e surface-hover. */
  --color-text-tertiary: #56657a;
  /* Exclusivamente decorativo (linhas, separadores, ícones inertes) —
     NUNCA como cor de texto nem de fronteira de componente (2,56:1). */
  --color-muted: #94a3b8;
  /* Separadores entre blocos (não precisam de 3:1) */
  --color-border: rgba(0, 0, 0, 0.10);
  /* Fronteira de componentes (inputs, dropzone, nós, cartões) — ≥3:1 */
  --color-border-strong: rgba(13, 17, 23, 0.48);
  --color-border-accent: rgba(0, 200, 160, 0.25);
  /* Anel de foco — ≥3:1 sobre qualquer fundo do tema; nos contextos navy
     (stats, ficha, footer, hub, login) é forçado para o accent (ver abaixo) */
  --color-focus: var(--color-text);
  /* Erro — o vermelho #ef4444 fica só como borda/fundo */
  --color-danger-text: #b91c1c;
  --color-danger-dim: rgba(239, 68, 68, 0.08);
  --color-danger-border: rgba(239, 68, 68, 0.30);
  /* Aviso — âmbar para texto (o #f59e0b só como fundo/borda) */
  --color-warn-text: #92400e;
  --color-warn-dim: rgba(245, 158, 11, 0.12);
  --color-warn-border: rgba(245, 158, 11, 0.30);
  /* Botão primário — navy + branco no claro (15,2:1) */
  --color-primary-bg: #0F172A;
  --color-primary-bg-hover: #1e293b;
  --color-primary-text: #ffffff;
  --color-navbar-scrolled: rgba(255, 255, 255, 0.92);
  --color-mobile-menu: rgba(255, 255, 255, 0.98);

  /* Footer — Navy institucional da Brand Identity v2 */
  --color-footer-bg: #0F172A;
  --color-footer-text: #e8edf2;
  --color-footer-tagline: #9ca3af;   /* contraste 7.5:1 sobre footer-bg */
  --color-footer-link: #8b949e;      /* contraste 6.3:1 sobre footer-bg */
  --color-footer-muted: #9ca3af;     /* contraste 7.5:1 — copyright e privacidade */
  --color-footer-icon: #9ca3af;
  --color-footer-border: rgba(255, 255, 255, 0.07); /* separadores internos do footer navy */

  /* Contexto Navy (stats + footer) — texto e separadores sobre #0F172A */
  --color-stats-label: rgba(255, 255, 255, 0.65);  /* 5.2:1 sobre navy — WCAG AA large */
  --color-stats-divider: rgba(255, 255, 255, 0.08);

  /* Watermark — número decorativo de fundo nos pilares */
  --color-watermark: rgba(0, 0, 0, 0.045);

  /* Publicitação PRR — placa branca fixa nos dois temas: os logótipos
     oficiais a cores (PRR, República, UE) têm texto escuro e não podem
     levar filtro nem opacidade (OT n.º 5/2021 v6.0, princípios gerais) */
  --color-funding-plate: #ffffff;
  --color-funding-text: #0d1117;            /* 18,9:1 sobre a placa */
  --color-funding-text-secondary: #4a5568;  /* 7,5:1 sobre a placa */
  --color-funding-border: rgba(13, 17, 23, 0.08);

  /* Tipografia */
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Space Grotesk', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 2rem;
  --text-4xl: 2.75rem;
  --text-5xl: 3.5rem;
  --text-6xl: 4.5rem;

  --leading-tight: 1.1;
  --leading-snug: 1.25;
  --leading-normal: 1.6;
  --leading-relaxed: 1.75;

  --weight-light: 300;
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* Espaçamento (base 8px) */
  --space-1: 0.25rem;   /* 4px */
  --space-2: 0.5rem;    /* 8px */
  --space-3: 0.75rem;   /* 12px */
  --space-4: 1rem;      /* 16px */
  --space-5: 1.5rem;    /* 24px */
  --space-6: 2rem;      /* 32px */
  --space-8: 3rem;      /* 48px */
  --space-10: 4rem;     /* 64px */
  --space-12: 5rem;     /* 80px */
  --space-16: 7rem;     /* 112px */
  --space-20: 9rem;     /* 144px */

  /* Layout */
  --container-max: 1200px;
  --container-padding: var(--space-5);

  /* Bordas e sombras */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-2xl: 20px;

  /* Transições — tema (mais suave que animações de UI) */
  --duration-theme: 250ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --duration-fast: 200ms;
  --duration-base: 400ms;
  --duration-slow: 600ms;

  /* Navbar */
  --navbar-height: 64px;

  /* ── Tokens de documento — exclusivos da carta/PDF ────────────────────────
     Não usar na UI do site nem do admin. Representam o "papel" do
     letterhead institucional, fixo independentemente do tema claro/escuro
     (tal como o navy do footer é sempre #0F172A). O utilizador escolhe,
     no editor, entre fundo branco ou bege/creme — ambos definidos aqui. */
  --letter-paper-bg-branco: #ffffff;
  --letter-paper-bg-creme: #f4efe7;
  --letter-paper-text: #0d1117;
  --letter-paper-text-secondary: #4a5568;
  --letter-paper-muted: #94a3b8;
  --letter-paper-border: rgba(13, 17, 23, 0.12);
  --letter-paper-border-soft: rgba(13, 17, 23, 0.08);
  --letter-paper-accent: #00c8a0;
  --letter-paper-highlight: rgba(255, 255, 255, 0.6);
}

/* Fallback quando Lenis CDN falha — evita inline style no <html> */
.scroll-smooth {
  scroll-behavior: smooth;
}

/* --- Tema Escuro (secundário) --- */
[data-theme="dark"] {
  --color-bg: #080a0d;
  --color-surface: #0f1218;
  --color-surface-hover: #161b24;
  --color-accent: #00c8a0;
  --color-accent-dim: rgba(0, 200, 160, 0.12);
  /* Em fundo escuro o teal original passa WCAG AA (8.7:1) — sem necessidade de escurecer */
  --color-accent-text: #00c8a0;
  --color-text: #e8edf2;
  --color-text-secondary: #94a3b8;
  --color-text-tertiary: #8a97a8;
  --color-muted: #4a5568;
  --color-border: rgba(255, 255, 255, 0.10);
  --color-border-strong: rgba(255, 255, 255, 0.38);
  --color-border-accent: rgba(0, 200, 160, 0.20);
  --color-focus: var(--color-accent);
  --color-danger-text: #f87171;
  --color-danger-dim: rgba(239, 68, 68, 0.12);
  --color-danger-border: rgba(248, 113, 113, 0.35);
  --color-warn-text: #fcd34d;
  --color-warn-dim: rgba(245, 158, 11, 0.12);
  --color-warn-border: rgba(245, 158, 11, 0.25);
  /* Botão primário — teal + quase-preto no escuro (8,8:1) */
  --color-primary-bg: var(--color-accent);
  --color-primary-bg-hover: var(--color-accent-hover);
  --color-primary-text: #0d1117;
  --color-navbar-scrolled: rgba(8, 10, 13, 0.92);
  --color-mobile-menu: rgba(8, 10, 13, 0.98);
  --color-watermark: rgba(255, 255, 255, 0.05);
  /* Placa PRR — igual ao claro de propósito (ver :root) */
  --color-funding-plate: #ffffff;
  --color-funding-text: #0d1117;
  --color-funding-text-secondary: #4a5568;
  --color-funding-border: rgba(255, 255, 255, 0.10);
}

/* --- Contextos navy fixos (#0F172A) — iguais nos dois temas ---
   O anel de foco e o botão primário passam a teal (accent sobre navy 8,3:1). */
.stats,
.projeto-page__ficha,
.footer,
.network-hub,
.admin-view--login {
  --color-focus: var(--color-accent);
  --color-primary-bg: var(--color-accent);
  --color-primary-bg-hover: var(--color-accent-hover);
  --color-primary-text: #0d1117;
}

/* --- Transição suave ao mudar de tema --- */
body,
.navbar,
.area-card,
.pilares,
.contacto,
.footer {
  transition: background-color var(--duration-theme) ease,
              color var(--duration-theme) ease,
              border-color var(--duration-theme) ease;
}

/* --- Reset --- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  /* scroll-behavior gerido pelo Lenis; .scroll-smooth é fallback quando o CDN falha */
  scroll-padding-top: var(--navbar-height);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  font-weight: var(--weight-regular);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background-color: var(--color-bg);
  overflow-x: hidden;
}

img,
svg {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
  text-decoration: none;
}

ul, ol {
  list-style: none;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  outline: none;
}

button {
  cursor: pointer;
}

textarea {
  resize: vertical;
}

/* Texto teal sobre branco dava 2,15:1 — inverte texto/fundo do tema */
::selection {
  background: var(--color-text);
  color: var(--color-bg);
}

/* Conteúdo legal (privacidade, acessibilidade) — o reset acima remove os
   marcadores; em listas de direitos/finalidades eles fazem parte da leitura */
.privacy-section ul { list-style: disc; }
.privacy-section ol { list-style: decimal; }

/* Oculto visualmente, mas lido por leitores de ecrã (títulos de secção
   sem equivalente visual, rótulos de apoio) */
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* --- Skip Link (acessibilidade — teclado / screen reader) --- */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  z-index: 9999;
  padding: var(--space-2) var(--space-5);
  background: var(--color-primary-bg);
  color: var(--color-primary-text);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  border-radius: var(--radius-sm);
  text-decoration: none;
  white-space: nowrap;
  transition: top 200ms ease;
}

.skip-link:focus {
  top: var(--space-2);
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

/* Destinos de âncora/skip link recebem foco programático (tabindex="-1")
   para o próximo Tab continuar dali — não são controlos, sem anel */
[tabindex="-1"]:focus {
  outline: none;
}

/* --- Tipografia Base --- */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  letter-spacing: -0.02em;
}

/* --- Container --- */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding-left: var(--container-padding);
  padding-right: var(--container-padding);
}

/* --- Etiquetas de secção — usadas em todos os "0X / NOME" e títulos H2 --- */
.eyebrow {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--color-accent-text);
  margin-bottom: var(--space-4);
}

.eyebrow--muted {
  color: var(--color-text-tertiary);
}

.section-title {
  font-family: var(--font-display);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.03em;
  line-height: 1.1;
  font-size: var(--text-4xl);
  color: var(--color-text);
  margin-bottom: var(--space-6);
  /* Com espaçamento de texto aumentado (1.4.12) "tecnológicas." não cabia
     a 360px — deixa a palavra hifenizar/quebrar em vez de transbordar */
  overflow-wrap: break-word;
  hyphens: auto;
}

/* --- Botões --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  letter-spacing: 0.02em;
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-sm);
  transition: all var(--duration-fast) var(--ease-out);
  white-space: nowrap;
}

/* --- 4 estilos de botão no site público: primary / secondary / ghost / icon --- */
/* Primário: navy + branco no claro; teal + quase-preto no escuro e nos
   contextos navy (tokens --color-primary-*). Cookie "Aceitar tudo" usa-o. */
.btn--primary {
  background: var(--color-primary-bg);
  color: var(--color-primary-text);
  border: 1px solid var(--color-primary-bg);
}

.btn--primary:hover {
  background: var(--color-primary-bg-hover);
  border-color: var(--color-primary-bg-hover);
  transform: translateY(-1px);
}

/* Borda --color-border-accent (1,3:1) é decorativa — o texto teal-escuro
   identifica o botão. No hover o texto mantém --color-accent-text. */
.btn--secondary {
  background: none;
  color: var(--color-accent-text);
  border: 1px solid var(--color-border-accent);
}

.btn--secondary:hover {
  color: var(--color-accent-text);
  border-color: var(--color-accent);
  background-color: var(--color-accent-dim);
}

.btn--icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: var(--radius-sm);
}

.btn--ghost {
  /* Secundário editorial — texto puro com underline, sem caixa */
  padding: 0 0 2px;
  min-height: 44px;
  align-items: flex-end;
  background: none;
  border: none;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-regular);
  letter-spacing: 0.01em;
  gap: var(--space-2);
  border-bottom: 1px solid var(--color-muted);
  border-radius: 0;
  transition: color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out);
}

.btn--ghost::after {
  content: '';
  width: 16px;
  height: 10px;
  display: inline-block;
  background-color: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 8h13M9 3l5 5-5 5'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 8h13M9 3l5 5-5 5'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: transform var(--duration-fast) var(--ease-out);
}

.btn--ghost:hover {
  color: var(--color-text);
  border-color: var(--color-text);
}

.btn--ghost:hover::after {
  transform: translateX(4px);
}

/* :not(.btn--icon) — este padding (48px no total) anulava o padding:0 dos
   botões-ícone de 44px e deixava o SVG com 0px de largura: LinkedIn e
   tema ficavam invisíveis em telemóveis */
@media (max-width: 480px) {
  .btn:not(.btn--icon) {
    padding-left: var(--space-5);
    padding-right: var(--space-5);
  }
}

/* Acessibilidade — focus visível para teclado (qualquer elemento interactivo).
   --color-focus: texto do tema no claro (18,9:1), teal no escuro e nos
   contextos navy (≥8:1). Não redefinir outline abaixo de 3:1 noutros sítios. */
:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
  border-radius: 2px;
}

/* --- Responsivo --- */
@media (min-width: 768px) {
  :root {
    --container-padding: var(--space-8);
  }
}

@media (min-width: 1200px) {
  :root {
    --container-padding: var(--space-10);
  }

  .section-title {
    font-size: var(--text-5xl);
  }
}

/* Honeypot — campo fora do ecrã para deteção de bots */
.honeypot {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* ==========================================================================
   Movimento reduzido (WCAG 2.3.3) — vive aqui porque main.css é a única
   folha carregada por TODAS as páginas (animations.css só em index/projeto).
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  /* Regra global com !important: sem ele, qualquer `animation:` de maior
     especificidade (hero, menu, modal, nós do diagrama) continuaria a correr.
     0.01ms e não 0 — transitionend continua a disparar (o banner de cookies
     depende dele para ficar [hidden] e sair da ordem de tabulação). */
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }

  /* Excepção: indicador de carregamento — informa que algo está a decorrer */
  .admin-btn__spinner {
    animation-duration: 0.6s !important;
    animation-iteration-count: infinite !important;
  }

  /* Skeleton: sem pulsação, opacidade estática */
  .projeto-page__skeleton-back,
  .projeto-page__skeleton-badge,
  .projeto-page__skeleton-title {
    animation: none !important;
    opacity: 0.7;
  }

  /* Conteúdo que entra com animação fica no estado final */
  /* html.js body — mais específico do que a regra de animations.css, que é
     carregada depois de main.css */
  .reveal,
  html.js body .reveal {
    opacity: 1;
    transform: none;
  }

  /* Símbolo do hero — aparece já no estado final (braços desenhados, nós e
     hub à escala 1), sem a entrada animada */
  .simbolo__braco,
  .simbolo__no,
  .simbolo__hub {
    animation: none !important;
    opacity: 1;
    transform: none;
    stroke-dashoffset: 0;
  }

  /* Hovers com deslocação/escala — sem movimento, só cor */
  .btn--primary:hover,
  .area-card:hover {
    transform: none;
  }

  .pilar:hover .pilar__content {
    transform: none;
  }
}
