.app-shell { display: grid; grid-template-columns: var(--sidebar-width) 1fr; min-height: 100vh; transition: grid-template-columns var(--duration-normal) var(--ease); }
.app-shell.is-collapsed { grid-template-columns: var(--sidebar-width-collapsed) 1fr; }

/* ---------- Sidebar ---------- */
.sidebar {
  background: hsl(var(--sidebar-background)); color: hsl(var(--sidebar-foreground));
  display: flex; flex-direction: column; padding: var(--space-4) var(--space-3);
  position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 40;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: var(--space-2) var(--space-2) var(--space-3); }
.sidebar-brand-mark { height: 36px; flex: none; display: flex; align-items: center; justify-content: center; }
.sidebar-brand-mark img { height: 100%; width: auto; max-width: 150px; object-fit: contain; display: none; }
.sidebar-brand-mark img.logo-for-dark { display: block; }
.app-shell[data-sidebar-theme="light"] .sidebar-brand-mark img.logo-for-dark { display: none; }
.app-shell[data-sidebar-theme="light"] .sidebar-brand-mark img.logo-for-light { display: block; }
.sidebar-brand-mono {
  display: none; width: 36px; height: 36px; border-radius: 8px; background: hsl(var(--sidebar-primary));
  color: #fff; align-items: center; justify-content: center; font-weight: 800; font-size: 13px; flex: none;
}
.sidebar-powered-by {
  padding: 0 var(--space-2); margin-bottom: var(--space-5); font-size: 10.5px; color: hsl(var(--sidebar-foreground) / 45%);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-powered-by strong { color: hsl(var(--sidebar-foreground) / 70%); font-weight: 700; }
.app-shell.is-collapsed .nav-label, .app-shell.is-collapsed .nav-section-label { display: none; }
.app-shell.is-collapsed .sidebar-brand-mark { display: none; }
.app-shell.is-collapsed .sidebar-brand-mono { display: flex; }

.nav-section { margin-top: var(--space-5); }
.nav-section-label { padding: 0 var(--space-3); font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: hsl(var(--sidebar-foreground) / 45%); margin-bottom: 6px; }
.nav-list { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: hsl(var(--sidebar-foreground) / 78%); text-decoration: none; font-size: 13px; font-weight: 560; cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}
.nav-item svg { flex: none; }
.nav-item:hover { background: hsl(var(--sidebar-accent)); color: hsl(var(--sidebar-accent-foreground)); }
.nav-item.is-active { color: #fff; background: hsl(var(--sidebar-primary)); position: relative; }
.sidebar-footer { margin-top: auto; padding-top: var(--space-4); }
.sidebar-collapse-btn {
  width: 100%; height: 34px; display: flex; align-items: center; justify-content: center; border-radius: 8px;
  border: none; background: transparent; color: hsl(var(--sidebar-foreground) / 65%); cursor: pointer;
}
.sidebar-collapse-btn:hover { background: hsl(var(--sidebar-accent)); color: hsl(var(--sidebar-accent-foreground)); }

/* ---------- Sidebar: variante clara (independente do tema geral) ---------- */
.app-shell[data-sidebar-theme="light"] .sidebar {
  background: hsl(var(--card)); color: hsl(var(--foreground)); border-right: 1px solid hsl(var(--border));
}
.app-shell[data-sidebar-theme="light"] .sidebar-powered-by { color: hsl(var(--muted-foreground)); }
.app-shell[data-sidebar-theme="light"] .sidebar-powered-by strong { color: hsl(var(--foreground) / 80%); }
.app-shell[data-sidebar-theme="light"] .nav-section-label { color: hsl(var(--muted-foreground)); }
.app-shell[data-sidebar-theme="light"] .nav-item:not(.is-active) { color: hsl(var(--muted-foreground)); }
.app-shell[data-sidebar-theme="light"] .nav-item:not(.is-active):hover { background: hsl(var(--secondary)); color: hsl(var(--foreground)); }
.app-shell[data-sidebar-theme="light"] .sidebar-collapse-btn { color: hsl(var(--muted-foreground)); }
.app-shell[data-sidebar-theme="light"] .sidebar-collapse-btn:hover { background: hsl(var(--secondary)); color: hsl(var(--foreground)); }

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-height); display: flex; align-items: center; gap: var(--space-4);
  padding: 0 var(--space-6); background: hsl(var(--card) / 92%); backdrop-filter: blur(8px);
  border-bottom: 1px solid hsl(var(--border)); position: sticky; top: 0; z-index: 30;
}
.topbar-search { flex: 1; max-width: 380px; }
.topbar-search-btn {
  display: flex; align-items: center; gap: 8px; width: 100%; height: 36px; padding: 0 12px;
  border-radius: var(--radius); border: 1px solid hsl(var(--border)); background: hsl(var(--secondary));
  color: hsl(var(--muted-foreground)); font-size: 12.5px; cursor: pointer;
}
.topbar-search-btn kbd { margin-left: auto; font-size: 10.5px; background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: 4px; padding: 1px 5px; }
.topbar-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.topbar-divider { width: 1px; height: 24px; background: hsl(var(--border)); margin: 0 4px; }
.notif-dot { position: absolute; top: 6px; right: 6px; width: 7px; height: 7px; border-radius: 999px; background: hsl(var(--destructive)); border: 2px solid hsl(var(--card)); }
.topbar-actions .btn-icon { position: relative; }
.user-menu-trigger { display: flex; align-items: center; gap: 8px; padding: 4px 8px 4px 4px; border-radius: 999px; }
.user-menu-trigger:hover { background: hsl(var(--secondary)); }
.user-menu-name { font-size: 12.5px; font-weight: 600; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu-role { font-size: 10.5px; color: hsl(var(--muted-foreground)); }

/* ---------- Content ---------- */
.app-main { min-height: 100vh; display: flex; flex-direction: column; }
.page { padding: var(--space-6); max-width: 1320px; width: 100%; margin: 0 auto; flex: 1; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-6); flex-wrap: wrap; }
.page-title-group { display: flex; flex-direction: column; gap: 6px; }
.page-title { font-size: 22px; font-weight: 680; letter-spacing: -0.015em; }
.page-subtitle { font-size: 13px; color: hsl(var(--muted-foreground)); max-width: 60ch; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Mobile ---------- */
.mobile-topbar, .mobile-bottom-nav { display: none; }
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: min(280px, 82vw); transform: translateX(-100%); transition: transform var(--duration-normal) var(--ease); box-shadow: var(--shadow-lg); }
  .app-shell.is-mobile-nav-open .sidebar { transform: none; }
  .app-shell.is-mobile-nav-open::before { content: ""; position: fixed; inset: 0; background: rgb(0 0 0 / 45%); z-index: 39; }
  .topbar-search { display: none; }
  .page { padding: var(--space-4); padding-bottom: 88px; }
  .mobile-bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; height: 64px; background: hsl(var(--card));
    border-top: 1px solid hsl(var(--border)); z-index: 45; align-items: center; justify-content: space-around;
  }
  .mobile-nav-item { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10px; color: hsl(var(--muted-foreground)); text-decoration: none; }
  .mobile-nav-item.is-active { color: hsl(var(--primary)); }
  .mobile-nav-fab {
    width: 48px; height: 48px; border-radius: 999px; background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
    display: flex; align-items: center; justify-content: center; margin-top: -26px; box-shadow: var(--shadow-lg); border: 4px solid hsl(var(--card));
  }
}

@media print {
  .sidebar, .topbar, .mobile-bottom-nav, #modal-root, #drawer-root, #toast-root { display: none !important; }
  .app-shell { display: block; }
  .page { max-width: none; padding: 0; }
}
