/* ══════════════════════════════════════════════════════════════════════════
   Nexo · Reset, base tipográfica e utilitários
   ══════════════════════════════════════════════════════════════════════════ */

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

  * {
    margin: 0;
    padding: 0;
  }

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    tab-size: 2;
  }

  body {
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
  }

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

  input,
  button,
  textarea,
  select {
    font: inherit;
    color: inherit;
    letter-spacing: inherit;
  }

  button {
    background: none;
    border: none;
    cursor: pointer;
  }

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

  ul,
  ol {
    list-style: none;
  }

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

  hr {
    border: 0;
    border-top: 1px solid var(--border-subtle);
  }

  :where(h1, h2, h3, h4, h5, h6) {
    font-size: inherit;
    font-weight: inherit;
  }

  /* Um único tratamento de foco em toda a aplicação. :focus-visible e não
     :focus — o anel não deve aparecer em clique de mouse. */
  :focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--r-xs);
  }

  :focus:not(:focus-visible) {
    outline: none;
  }

  ::selection {
    background: var(--accent-subtle);
    color: var(--text-primary);
  }

  /* Durante a troca de tema, nada transiciona. O atributo é posto e removido
     por core/theme.js em dois quadros. */
  :root[data-theme-switching] *,
  :root[data-theme-switching] *::before,
  :root[data-theme-switching] *::after {
    transition: none !important;
  }

  /* prefers-reduced-motion zera tudo. Vale para transição, animação e rolagem
     suave — não adianta desligar só metade. */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }
  }
}

@layer base {
  body {
    font-family: var(--font-sans);
    font-size: var(--fs-ui);
    line-height: var(--lh-ui);
    font-weight: var(--fw-regular);
    /* cv05 e cv11 desligam a perna curva do "l" e ajustam o "a" — diferença
       pequena que melhora bastante a leitura em 12–13px. */
    font-feature-settings: "cv05" 1, "cv11" 1, "ss03" 1;
    color: var(--text-primary);
    background: var(--surface-canvas);
    overflow-wrap: break-word;
  }

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

  code,
  pre,
  kbd,
  samp {
    font-family: var(--font-mono);
    font-size: 0.9em;
  }

  code {
    padding: 0.1em 0.35em;
    background: var(--surface-inset);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xs);
  }

  pre {
    padding: var(--sp-5);
    background: var(--surface-inset);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-lg);
    overflow-x: auto;
  }

  pre code {
    padding: 0;
    background: none;
    border: none;
  }

  kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    font-size: var(--fs-micro);
    font-family: var(--font-sans);
    font-weight: var(--fw-medium);
    color: var(--text-secondary);
    background: var(--surface-inset);
    border: 1px solid var(--border-default);
    border-bottom-width: 2px;
    border-radius: var(--r-xs);
  }

  /* ── Escala tipográfica ─────────────────────────────────────────────────── */

  .t-display {
    font-size: var(--fs-display);
    line-height: var(--lh-display);
    font-weight: var(--fw-bold);
    letter-spacing: -0.022em;
  }

  .t-title {
    font-size: var(--fs-title);
    line-height: var(--lh-title);
    font-weight: var(--fw-bold);
    letter-spacing: -0.016em;
  }

  .t-heading {
    font-size: var(--fs-heading);
    line-height: var(--lh-heading);
    font-weight: var(--fw-semibold);
    letter-spacing: -0.009em;
  }

  .t-body {
    font-size: var(--fs-body);
    line-height: var(--lh-body);
  }

  .t-ui {
    font-size: var(--fs-ui);
    line-height: var(--lh-ui);
  }

  .t-small {
    font-size: var(--fs-small);
    line-height: var(--lh-small);
  }

  .t-micro {
    font-size: var(--fs-micro);
    line-height: var(--lh-micro);
    font-weight: var(--fw-semibold);
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  .t-secondary { color: var(--text-secondary); }
  .t-tertiary  { color: var(--text-tertiary); }
  .t-danger    { color: var(--danger-text); }
  .t-success   { color: var(--success-text); }
  .t-accent    { color: var(--accent-text); }

  .t-medium   { font-weight: var(--fw-medium); }
  .t-semibold { font-weight: var(--fw-semibold); }
  .t-bold     { font-weight: var(--fw-bold); }

  /* Timestamp e número em tabela: dígitos de largura fixa não fazem a coluna
     dançar a cada atualização. */
  .t-nums { font-variant-numeric: tabular-nums; }

  /* Parágrafo de leitura corrida nunca passa de 72 caracteres por linha. */
  .t-prose {
    max-width: 72ch;
    font-size: var(--fs-body);
    line-height: 1.65;
    color: var(--text-secondary);
  }

  .t-prose + .t-prose { margin-top: var(--sp-5); }

  .link {
    color: var(--accent-text);
    font-weight: var(--fw-medium);
    text-decoration: none;
    border-radius: var(--r-xs);
    transition: color var(--t-fast) var(--ease);
  }

  .link:hover { text-decoration: underline; text-underline-offset: 2px; }

  /* ── Ícones ─────────────────────────────────────────────────────────────── */

  .icon {
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .icon--filled {
    fill: currentColor;
    stroke: none;
  }

  /* ── Barra de rolagem ───────────────────────────────────────────────────── */

  .scroll-y {
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
  }

  .scroll-y::-webkit-scrollbar { width: 10px; }
  .scroll-y::-webkit-scrollbar-track { background: transparent; }

  .scroll-y::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border: 3px solid transparent;
    border-radius: var(--r-full);
    background-clip: padding-box;
  }

  .scroll-y::-webkit-scrollbar-thumb:hover { background-color: var(--scrollbar-thumb-hover); }

  /* Só aparece quando o ponteiro está sobre a área — menos ruído visual numa
     tela cheia de listas. */
  .scroll-y--quiet { scrollbar-color: transparent transparent; }
  .scroll-y--quiet::-webkit-scrollbar-thumb { background: transparent; }
  .scroll-y--quiet:hover { scrollbar-color: var(--scrollbar-thumb) transparent; }
  .scroll-y--quiet:hover::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); }
}

@layer utilities {
  /* Conjunto pequeno de propósito. Utilitário aqui resolve composição —
     não substitui componente. */

  .stack { display: flex; flex-direction: column; }
  .row { display: flex; align-items: center; }
  .row-start { display: flex; align-items: flex-start; }
  .between { justify-content: space-between; }
  .center { align-items: center; justify-content: center; }
  .wrap { flex-wrap: wrap; }
  .grow { flex: 1 1 auto; min-width: 0; }
  .none { flex: none; }

  .g-1 { gap: var(--sp-1); }
  .g-2 { gap: var(--sp-2); }
  .g-3 { gap: var(--sp-3); }
  .g-4 { gap: var(--sp-4); }
  .g-5 { gap: var(--sp-5); }
  .g-6 { gap: var(--sp-6); }
  .g-8 { gap: var(--sp-8); }
  .g-9 { gap: var(--sp-9); }

  .mt-2 { margin-top: var(--sp-2); }
  .mt-4 { margin-top: var(--sp-4); }
  .mt-5 { margin-top: var(--sp-5); }
  .mt-6 { margin-top: var(--sp-6); }
  .mt-8 { margin-top: var(--sp-8); }
  .mt-9 { margin-top: var(--sp-9); }
  .mb-4 { margin-bottom: var(--sp-4); }
  .mb-6 { margin-bottom: var(--sp-6); }
  .mb-8 { margin-bottom: var(--sp-8); }

  .full { width: 100%; }
  .hidden { display: none !important; }

  /* Corta com reticências. min-width:0 porque item de flex não encolhe abaixo
     do conteúdo sem isso — a causa nº 1 de texto vazando de barra lateral. */
  .truncate {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  /* Visível só para leitor de tela. */
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  /* Link de pular navegação: aparece ao receber foco pelo teclado. */
  .skip-link {
    position: absolute;
    top: var(--sp-4);
    left: var(--sp-4);
    z-index: var(--z-tooltip);
    padding: var(--sp-4) var(--sp-6);
    background: var(--surface-overlay);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-lg);
    transform: translateY(-200%);
    transition: transform var(--t-base) var(--ease);
  }

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

  .divider {
    height: 1px;
    background: var(--border-subtle);
    border: 0;
  }

  .divider--v {
    width: 1px;
    height: 20px;
    background: var(--border-default);
  }

  .dot-sep::before {
    content: "·";
    margin: 0 var(--sp-3);
    color: var(--text-tertiary);
  }
}
