/* ==========================================================================
   PLIMAT — Sistema de Design
   base.css · reset, tipografia base, ligações, foco, movimento

   Depende de: styles/tokens.css (tem de ser carregado antes).
   Só actua sobre selectores de elemento e sobre duas classes utilitárias
   de acessibilidade. Especificidade máxima: 0-1-0.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. RESET
   -------------------------------------------------------------------------- */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: var(--sticky-offset);
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--surface-page);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--text-lg);
  font-weight: var(--weight-regular);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6,
p, figure, blockquote, dl, dd, pre {
  margin: 0;
}

ul, ol {
  margin: 0;
  padding: 0;
}

img, picture, video, canvas, svg, iframe {
  display: block;
  max-width: 100%;
}

img, video {
  height: auto;
}

hr {
  border: 0;
  border-top: 1px solid var(--border-default);
  margin: var(--space-32) 0;
}

/* --------------------------------------------------------------------------
   2. TIPOGRAFIA BASE
   -------------------------------------------------------------------------- */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-display);
  line-height: var(--leading-title);
  color: var(--text-primary);
  text-wrap: balance;
}

h1 { font-size: var(--display-3xl); }
h2 { font-size: var(--display-xl); }
h3 { font-size: var(--display-lg); }
h4 { font-size: var(--display-sm); }
h5 { font-size: var(--display-xs); }
h6 { font-size: var(--text-lg); }

p {
  text-wrap: pretty;
}

small {
  font-size: var(--text-sm);
}

strong, b {
  font-weight: var(--weight-semibold);
}

abbr[title] {
  text-decoration: underline dotted;
  cursor: help;
}

::selection {
  background-color: var(--color-brand-fill);
  color: var(--color-brand-contrast);
}

/* Números tabulares onde a comparação vertical importa. */
table,
time,
data {
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   3. LIGAÇÕES
   -------------------------------------------------------------------------- */

a {
  color: var(--text-link);
  text-decoration-color: color-mix(in srgb, currentColor 40%, transparent);
  text-underline-offset: 0.18em;
  text-decoration-thickness: from-font;
  transition: color var(--motion-fast) var(--easing);
}

a:hover {
  color: var(--text-link-hover);
  text-decoration-color: currentColor;
}

/* --------------------------------------------------------------------------
   4. FORMULÁRIOS
   -------------------------------------------------------------------------- */

input, select, button, textarea {
  font: inherit;
  color: inherit;
  margin: 0;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-align: inherit;
}

textarea {
  resize: vertical;
}

::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

legend {
  padding: 0;
}

/* --------------------------------------------------------------------------
   5. TABELAS
   -------------------------------------------------------------------------- */

table {
  border-collapse: collapse;
  border-spacing: 0;
}

caption, th {
  text-align: left;
}

/* --------------------------------------------------------------------------
   6. FOCO VISÍVEL
   Anel único e consistente. Nunca se remove o contorno sem substituto.
   -------------------------------------------------------------------------- */

:focus-visible {
  outline: var(--focus-width) solid var(--focus-color);
  outline-offset: var(--focus-offset);
}

/* Em superfícies escuras o anel muda de tom, não de existência. */
[data-surface="inverse"] :focus-visible {
  outline-color: var(--focus-color-on-inverse);
}

/* Rato e toque não devem pintar o anel; teclado sim. */
:focus:not(:focus-visible) {
  outline: none;
}

/* --------------------------------------------------------------------------
   7. UTILITÁRIOS DE ACESSIBILIDADE
   -------------------------------------------------------------------------- */

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

/* Ligação de salto para o conteúdo principal. */
.pl-skip-link {
  position: absolute;
  top: var(--space-8);
  left: var(--space-8);
  z-index: var(--z-skip);
  transform: translateY(-200%);
  background-color: var(--surface-raised);
  color: var(--text-link);
  border: 1px solid var(--border-interactive);
  border-radius: var(--radius-9);
  padding: var(--space-12) var(--space-20);
  font-size: var(--text-base-plus);
  font-weight: var(--weight-semibold);
  text-decoration: none;
  transition: transform var(--motion-base) var(--easing);
}

.pl-skip-link:focus-visible {
  transform: translateY(0);
}

/* --------------------------------------------------------------------------
   8. MOVIMENTO REDUZIDO
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms;
    animation-iteration-count: 1;
    transition-duration: 0.01ms;
    scroll-behavior: auto;
  }
}

/* --------------------------------------------------------------------------
   9. IMPRESSÃO
   -------------------------------------------------------------------------- */

@media print {
  body {
    background: #fff;
    color: #000;
  }

  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: var(--text-3xs);
  }
}
