body.app-has-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* App root (banner auditoria opcional) */
.app-root {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* Grid: sidebar | (header + corpo) */
.app-shell {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--sp-sidebar-width) 1fr;
  grid-template-rows: 64px 1fr;
  background: var(--sp-bg);
  transition: grid-template-columns 0.22s ease;
}

.app-shell--sidebar-collapsed {
  grid-template-columns: var(--sp-sidebar-width-collapsed) 1fr;
}

/* Sidebar: coluna 1, linhas 1–2 */
.app-sidebar {
  grid-column: 1;
  grid-row: 1 / -1;
  z-index: 1040;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--sp-sidebar-bg);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  transition: width 0.22s ease;
}

.sidebar-brand {
  flex-shrink: 0;
  height: 64px;
  min-height: 64px;
  display: flex;
  align-items: center;
  padding: 0 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand .navbar-logo {
  height: 28px;
  width: auto;
  max-width: 140px;
  object-fit: contain;
}

.app-shell--sidebar-collapsed .sidebar-brand {
  justify-content: center;
  padding: 0 0.5rem;
}

.app-shell--sidebar-collapsed .sidebar-brand .navbar-logo {
  max-width: 40px;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.75rem 0.5rem 1.25rem;
  -webkit-overflow-scrolling: touch;
}

.sidebar-section-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sp-sidebar-muted) !important;
  padding: 0.65rem 0.75rem 0.35rem;
  margin: 0;
  pointer-events: none;
}

.app-shell--sidebar-collapsed .sidebar-section-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sidebar-ico {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  color: inherit;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.75rem;
  margin: 0.125rem 0;
  border-radius: 8px;
  border-left: 3px solid transparent;
  color: var(--sp-sidebar-text) !important;
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.sidebar-link:hover {
  background: var(--sp-sidebar-hover-bg);
  color: #fff !important;
}

.sidebar-link.active {
  background: var(--sp-sidebar-active-bg);
  border-left-color: var(--sp-sidebar-active-border);
  color: #fff !important;
  font-weight: 600;
  padding-left: calc(0.75rem - 3px);
}

.sidebar-link-text {
  flex: 1;
  min-width: 0;
}

.app-shell--sidebar-collapsed .sidebar-link {
  justify-content: center;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

.app-shell--sidebar-collapsed .sidebar-link.active {
  padding-left: calc(0.5rem - 3px);
}

.app-shell--sidebar-collapsed .sidebar-link-text {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Header: coluna 2, linha 1 */
.app-topbar {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 64px;
  height: 64px;
  padding: 0 1.25rem;
  background: var(--sp-surface);
  border-bottom: 1px solid var(--sp-border);
  box-sizing: border-box;
}

.app-sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--sp-border);
  border-radius: 10px;
  background: var(--sp-surface);
  color: var(--sp-text);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.app-sidebar-toggle:hover {
  background: var(--sp-bg);
  border-color: #d1d5db;
}

.app-sidebar-toggle svg {
  width: 22px;
  height: 22px;
}

@media (min-width: 992px) {
  .app-sidebar-toggle {
    display: inline-flex;
  }
}

.app-breadcrumb-wrap {
  flex: 1;
  min-width: 0;
}

.app-breadcrumb {
  margin-bottom: 0;
  font-size: 0.875rem;
}

.app-breadcrumb .breadcrumb-item a {
  color: var(--sp-text-secondary);
  text-decoration: none;
}

.app-breadcrumb .breadcrumb-item a:hover {
  color: var(--sp-accent);
}

.app-breadcrumb .breadcrumb-item.active {
  color: var(--sp-text);
  font-weight: 600;
}

.app-topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.app-header-tenant {
  max-width: 200px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--sp-text-secondary);
}

.app-btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 1px solid var(--sp-border);
  border-radius: 10px;
  background: var(--sp-surface);
  color: var(--sp-text-secondary);
  cursor: not-allowed;
  opacity: 0.85;
}

.app-user-trigger {
  max-width: 200px;
  border: 1px solid var(--sp-border) !important;
  background: var(--sp-bg) !important;
  color: var(--sp-text) !important;
  font-weight: 600;
  font-size: 0.875rem;
  border-radius: 10px;
  padding: 0.4rem 0.75rem;
}

/* Coluna principal: header alinhado ao conteúdo (mesma coluna grid) */
.app-main-column {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--sp-bg);
}

.app-content {
  flex: 1;
  min-height: 0;
  padding: 1.5rem 1.5rem 2rem;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
}

.app-footer {
  flex-shrink: 0;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--sp-border);
  background: var(--sp-surface);
  color: var(--sp-text-secondary);
  font-size: 0.8125rem;
}

.app-footer a {
  color: var(--sp-text-secondary);
}

/* Mobile: overlay sidebar */
.app-menu-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--sp-border);
  border-radius: 10px;
  background: var(--sp-surface);
  color: var(--sp-text);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

@media (min-width: 992px) {
  .app-menu-toggle {
    display: none;
  }
}

.app-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1035;
  background: rgba(17, 24, 39, 0.5);
}

.app-sidebar-backdrop.show {
  display: block;
}

@media (max-width: 991.98px) {
  .app-shell {
    display: block;
    position: relative;
  }

  .app-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sp-sidebar-width);
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }

  .app-sidebar.is-open {
    transform: translateX(0);
  }

  .app-topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    width: 100%;
  }

  .app-main-column {
    width: 100%;
    min-height: calc(100vh - 64px);
  }

  .app-shell--sidebar-collapsed {
    grid-template-columns: unset;
  }

  /* No mobile o colapso desktop não altera largura do overlay */
  .app-sidebar-toggle {
    display: none;
  }

  .app-menu-toggle {
    display: inline-flex;
  }
}

@media (min-width: 992px) {
  .app-sidebar-backdrop {
    display: none !important;
  }
}

/* Página pública */
.app-public-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--sp-bg);
}

.app-public-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--sp-surface);
  border-bottom: 1px solid var(--sp-border);
}

.app-public-main {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
}
