/* Base: reset, tipografia, foco, utilitários mínimos e tela de abertura */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: var(--lh-base);
  font-weight: var(--fw-regular);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
h1, h2, h3, h4, h5, p { margin: 0; }
h1, h2, h3, h4 { font-weight: var(--fw-semibold); line-height: var(--lh-tight); letter-spacing: -0.005em; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img, svg { display: block; max-width: 100%; }
a { color: var(--accent); }
table { border-collapse: collapse; }
ul, ol { margin: 0; padding: 0; list-style: none; }
[hidden] { display: none !important; }
::selection { background: var(--accent-soft-2); }

:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--r-sm); }

/* Rolagem discreta */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }

.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; }
.skip-link { position: absolute; left: 8px; top: -48px; z-index: 1000; background: var(--accent); color: var(--on-accent); padding: 8px 12px; border-radius: var(--r-md); text-decoration: none; }
.skip-link:focus { top: 8px; }

/* Utilitários */
.row { display: flex; align-items: center; gap: var(--sp-3); }
.row-wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--sp-2); }
.grow { flex: 1 1 auto; min-width: 0; }
.spacer { flex: 1; }
.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.text-sm { font-size: var(--fs-sm); }
.text-xs { font-size: var(--fs-xs); }
.fw-medium { font-weight: var(--fw-medium); }
.fw-semibold { font-weight: var(--fw-semibold); }
.hide-mobile { }
.show-mobile { display: none !important; }
@media (max-width: 720px) {
  .hide-mobile { display: none !important; }
  .show-mobile { display: initial !important; }
  .show-mobile.row { display: flex !important; }
}

/* Tela de abertura / erro de inicialização */
#boot { position: fixed; inset: 0; z-index: 2000; background: var(--bg); display: grid; place-items: center; padding: var(--sp-6); }
#boot-loading { display: grid; justify-items: center; gap: var(--sp-4); color: var(--text-2); }
.boot-spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--accent-soft-2); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
#boot-error { max-width: 560px; width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-6); box-shadow: var(--sh-2); display: grid; gap: var(--sp-3); }
#boot-error h2 { font-size: var(--fs-xl); }
#boot-error p { color: var(--text-2); }
#boot-error pre { margin: 0; max-height: 200px; overflow: auto; background: var(--surface-3); border-radius: var(--r-md); padding: var(--sp-3); font: var(--fs-xs)/1.5 var(--font-mono); white-space: pre-wrap; word-break: break-word; }
.boot-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.boot-actions button { height: 40px; padding: 0 var(--sp-4); border-radius: var(--r-md); border: 1px solid var(--border-strong); background: var(--surface); }
.boot-actions button:first-child { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes drawer-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

@media print {
  body { background: #fff; }
  .app-sidebar, .app-topbar, .bottom-nav, .toast-region, .no-print { display: none !important; }
  .app-main { margin: 0 !important; }
}

dl, dd { margin: 0; }
.stack > *, .grow { min-width: 0; }
