/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text);
  background: var(--bg);
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  min-height: 100dvh;
}
img, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd, pre { font-family: var(--font-mono); font-size: 0.9em; }

/* Focus visível em todos os controles tabuláveis */
:focus-visible {
  outline: 2px solid transparent;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* ===== Typography helpers ===== */
h1, h2, h3, h4, h5, h6 { line-height: var(--leading-tight); font-weight: 600; color: var(--text); }
h1 { font-size: var(--text-3xl); letter-spacing: -0.02em; }
h2 { font-size: var(--text-2xl); letter-spacing: -0.015em; }
h3 { font-size: var(--text-xl); letter-spacing: -0.01em; }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-base); }
.text-muted { color: var(--text-muted); }
.text-subtle { color: var(--text-subtle); }
.text-mono { font-family: var(--font-mono); font-size: 0.92em; font-variant-numeric: tabular-nums; }
.text-tabular { font-variant-numeric: tabular-nums; }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.text-lg { font-size: var(--text-lg); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== Layout ===== */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}
.app-shell.no-sidebar { grid-template-columns: 1fr; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
}

/* ===== Sidebar ===== */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
}
.sidebar-brand {
  padding: var(--space-5) var(--space-5) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  border-bottom: 1px solid var(--border);
}
.sidebar-brand .brand-mark {
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary), var(--info));
  display: flex; align-items: center; justify-content: center;
  color: var(--on-primary);
  font-weight: 700;
  font-size: var(--text-md);
  letter-spacing: -0.02em;
}
.sidebar-brand .brand-text {
  display: flex; flex-direction: column;
  line-height: 1.15;
}
.sidebar-brand .brand-text strong {
  font-size: var(--text-base);
  font-weight: 600;
}
.sidebar-brand .brand-text small {
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3) var(--space-2);
  display: flex; flex-direction: column; gap: 2px;
}
.sidebar-section-label {
  padding: var(--space-3) var(--space-3) var(--space-1);
  font-size: var(--text-xs);
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 600;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 8px var(--space-3);
  color: var(--text-muted);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}
.nav-link.active {
  background: var(--primary-soft);
  color: var(--primary);
}
.nav-link svg {
  width: 16px; height: 16px;
  flex-shrink: 0;
  stroke-width: 1.75;
}
.nav-link .nav-badge {
  margin-left: auto;
  font-size: var(--text-xs);
  background: var(--surface-3);
  color: var(--text-muted);
  padding: 1px 6px;
  border-radius: var(--radius-full);
  min-width: 18px; text-align: center;
}
.nav-link.active .nav-badge { background: var(--primary); color: var(--on-primary); }

.sidebar-footer {
  padding: var(--space-3);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-2);
}
.user-pill {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2);
  border-radius: var(--radius-md);
  flex: 1; min-width: 0;
}
.user-pill .avatar {
  width: 28px; height: 28px;
  border-radius: var(--radius-full);
  background: var(--primary-soft);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: var(--text-xs);
}
.user-pill .user-info { min-width: 0; line-height: 1.2; }
.user-pill .user-info strong { display: block; font-size: var(--text-sm); font-weight: 500; }
.user-pill .user-info small { color: var(--text-subtle); font-size: var(--text-xs); }

/* ===== Topbar / Main ===== */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--space-6);
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}
[data-theme="dark"] .topbar,
[data-theme="auto"] .topbar { background: rgba(24, 24, 27, 0.72); }
.topbar-title {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--text);
}
.topbar-title small {
  color: var(--text-muted);
  font-weight: 400;
  font-size: var(--text-sm);
  margin-left: var(--space-2);
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.icon-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; stroke-width: 1.75; }

.main-content {
  padding: var(--space-8) var(--space-6) var(--space-16);
  max-width: var(--container-max);
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
}
/* Ritmo vertical consistente entre blocos diretos do main */
.main-content > section,
.main-content > .card,
.main-content > .table-wrap,
.main-content > form,
.main-content > .alert,
.main-content > .grid {
  margin: 0;  /* gap do flex já cuida */
}
.main-content > h1,
.main-content > h2,
.main-content > h3,
.main-content > h4 {
  margin-bottom: calc(-1 * var(--space-4));  /* aproxima do bloco seguinte */
}
/* Sections com vários blocos internos */
section { display: flex; flex-direction: column; gap: var(--space-4); }
section > h2, section > h3, section > h4 { margin: 0; }

@media (max-width: 700px) {
  .topbar { padding: 0 var(--space-4); }
  .main-content { padding: var(--space-5) var(--space-4) var(--space-12); gap: var(--space-6); }
}

/* ===== Page header ===== */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding-bottom: var(--space-2);
}
.page-header h1 { margin-bottom: 4px; }
.page-header .page-subtitle { color: var(--text-muted); font-size: var(--text-sm); }
.page-actions { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }

/* ===== Utility ===== */
.row-flex { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: center; }
.row-flex.justify-end { justify-content: flex-end; }
.col-flex { display: flex; flex-direction: column; gap: var(--space-3); }
.grid { display: grid; gap: var(--space-4); }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
@media (max-width: 900px) {
  .grid-cols-3, .grid-cols-4, .grid-cols-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 540px) {
  .grid-cols-2, .grid-cols-3, .grid-cols-4, .grid-cols-6 { grid-template-columns: 1fr; }
}
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }

/* ===== Skip link (a11y) ===== */
.skip-link {
  position: absolute; left: -9999px; top: 0;
  padding: var(--space-3) var(--space-4);
  background: var(--primary); color: var(--on-primary);
  border-radius: 0 0 var(--radius-md) 0;
  z-index: var(--z-toast);
}
.skip-link:focus { left: 0; }

/* respect reduced-motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0ms !important;
    transition-duration: 0ms !important;
  }
}
