/* ==========================================================================
   Base: reset, tipografia, fundo e layout do shell (sidebar + conteúdo)
   ========================================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* Reserva o espaço do cabeçalho fixo da tabela ao rolar até um elemento focado. */
  scroll-padding-top: 64px;
  scroll-padding-bottom: 24px;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image:
    radial-gradient(1200px 600px at 78% -10%, rgba(212, 178, 106, 0.07), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(169, 150, 230, 0.05), transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .83 0 0 0 0 .7 0 0 0 0 .42 0 0 0 .045 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  font-variant-numeric: lining-nums;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

[hidden] {
  display: none !important;
}

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

a {
  color: var(--gold);
  text-decoration-color: rgba(212, 178, 106, 0.4);
  text-underline-offset: 3px;
  transition: color var(--dur-1) var(--ease);
}

a:hover {
  color: var(--gold-bright);
}

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

[data-page-title]:focus,
[data-page-title]:focus-visible {
  box-shadow: none;
  outline: none;
}

::selection {
  background: rgba(212, 178, 106, 0.32);
  color: var(--text);
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.2;
  color: var(--text);
}

p {
  margin: 0;
}

.icon {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: var(--sp-3);
  left: var(--sp-3);
  z-index: 100;
  padding: var(--sp-2) var(--sp-4);
  background: var(--gold);
  color: var(--text-on-gold);
  font-weight: 700;
  border-radius: var(--radius-sm);
  transform: translateY(-160%);
  transition: transform var(--dur-2) var(--ease);
}

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

/* --------------------------------------------------------------------------
   Shell
   -------------------------------------------------------------------------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  /* Coluna da sidebar contínua mesmo em páginas longas */
  background: linear-gradient(90deg, var(--surface-1) calc(var(--sidebar-w) - 1px), var(--line) calc(var(--sidebar-w) - 1px), var(--line) var(--sidebar-w), transparent var(--sidebar-w));
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
  padding: var(--sp-6) var(--sp-4) var(--sp-4);
  background:
    linear-gradient(180deg, rgba(212, 178, 106, 0.05), transparent 30%),
    var(--surface-1);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-4) transparent;
}

.sidebar__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
}

.sidebar__head .sidebar__close {
  display: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-2);
  color: var(--text);
  text-decoration: none;
}

.brand:hover {
  color: var(--text);
}

.brand__mark {
  width: 44px;
  height: 44px;
  flex: none;
  color: var(--gold);
  filter: drop-shadow(0 0 10px var(--gold-glow));
  transition: transform var(--dur-3) var(--ease);
}

.brand:hover .brand__mark {
  transform: rotate(-12deg);
}

.brand__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand__name {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.15;
}

.brand__tagline {
  font-size: 0.7rem;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

.nav__group-label {
  margin: 0 0 var(--sp-2);
  padding: 0 var(--sp-3);
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.nav__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav__link {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  min-height: 40px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: background-color var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}

.nav__link .icon {
  color: var(--text-dim);
  transition: color var(--dur-1) var(--ease);
}

.nav__link:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav__link:hover .icon {
  color: var(--gold);
}

.nav__link[aria-current='page'] {
  background: linear-gradient(90deg, rgba(212, 178, 106, 0.14), rgba(212, 178, 106, 0.03));
  color: var(--gold-bright);
}

.nav__link[aria-current='page'] .icon {
  color: var(--gold);
}

.nav__link[aria-current='page']::before {
  content: '';
  position: absolute;
  left: -16px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--gold);
  box-shadow: 0 0 12px var(--gold-glow);
}

.nav__count {
  margin-left: auto;
  min-width: 2ch;
  font-size: var(--fs-xs);
  font-variant-numeric: lining-nums tabular-nums;
  color: var(--text-dim);
  text-align: right;
}

.sidebar__footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: none;
  align-items: center;
  gap: var(--sp-3);
  height: var(--topbar-h);
  padding: 0 var(--sp-4);
  background: rgba(14, 12, 10, 0.86);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar .brand__mark {
  width: 32px;
  height: 32px;
}

.topbar .brand__name {
  font-size: 0.95rem;
}

.content {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--sp-8) var(--sp-8) var(--sp-12);
  flex: 1;
}

.content:focus {
  outline: none;
}

.app-footer {
  padding: var(--sp-6) var(--sp-8);
  border-top: 1px solid var(--line);
  color: var(--text-dim);
  font-size: var(--fs-sm);
  text-align: center;
}

.scrim {
  display: none;
}

/* --------------------------------------------------------------------------
   Responsivo: sidebar vira gaveta abaixo de 1024px
   -------------------------------------------------------------------------- */
@media (max-width: 1023.98px) {
  :root {
    --sticky-top: var(--topbar-h);
  }

  html {
    scroll-padding-top: calc(var(--topbar-h) + 64px);
  }

  .app {
    grid-template-columns: minmax(0, 1fr);
    background: none;
  }

  .topbar {
    display: flex;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: min(86vw, var(--sidebar-w));
    transform: translateX(-102%);
    transition: transform var(--dur-3) var(--ease), visibility 0s linear var(--dur-3);
    visibility: hidden;
    box-shadow: var(--shadow-3);
  }

  .sidebar__head .sidebar__close {
    display: inline-grid;
    flex: none;
  }

  .app[data-drawer='open'] .sidebar {
    transform: translateX(0);
    visibility: visible;
    transition: transform var(--dur-3) var(--ease), visibility 0s;
  }

  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 30;
    background: var(--overlay);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-3) var(--ease);
  }

  .app[data-drawer='open'] .scrim {
    opacity: 1;
    pointer-events: auto;
  }

  .content {
    padding: var(--sp-6) var(--sp-5) var(--sp-10);
  }
}

@media (max-width: 599.98px) {
  .content {
    padding: var(--sp-5) var(--sp-4) var(--sp-10);
  }
}
