/* =========================================================
   Layout — app shell, sidebar, cabeçalho e navegação mobile
   ========================================================= */
.app-shell { min-height: 100vh; display: flex; }

/* ---------- Sidebar (desktop) ---------- */
.app-sidebar {
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border-default);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  padding: var(--space-5) var(--space-3) var(--space-4);
  z-index: 1040;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 17px;
  margin: 0 var(--space-2) var(--space-5);
  color: var(--text-primary);
}
.app-brand:hover { color: var(--text-primary); text-decoration: none; }

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: var(--color-on-primary);
  flex-shrink: 0;
}
.brand-mark i { font-size: 17px; }

.app-nav { flex: 1 1 auto; display: flex; flex-direction: column; gap: 2px; }

.app-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.12s ease, color 0.12s ease;
}
.app-nav-item i { font-size: 16px; color: var(--text-muted); transition: color 0.12s ease; }
.app-nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  text-decoration: none;
}
.app-nav-item:hover i { color: var(--text-primary); }
.app-nav-item.active {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}
.app-nav-item.active i { color: var(--color-primary); }

/* ---------- Rodapé da sidebar: usuário + logout ---------- */
.app-sidebar-footer {
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}
.app-user {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 4px 6px;
}
.app-user .avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--bg-hover);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}
.app-user .name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-user .role { font-size: 12px; color: var(--text-muted); }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-icon.danger:hover { background: var(--color-danger-soft); color: var(--color-danger); }

/* ---------- Área principal ---------- */
.app-main {
  flex: 1 1 auto;
  margin-left: 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Sidebar existe apenas em telas médias+ */
@media (min-width: 768px) {
  .app-shell.has-sidebar .app-main { margin-left: var(--sidebar-width); }
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6) var(--space-4);
  flex-wrap: wrap;
}
.app-header .titleblock { min-width: 0; }
.app-header .titleblock h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
}
.app-header .titleblock .desc {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 14px;
}
.app-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.app-body {
  padding: 0 var(--space-6) var(--space-6);
  width: 100%;
  max-width: var(--content-max);
}

.app-shell.has-mobile-nav .app-body {
  padding-bottom: calc(var(--mobile-nav-height) + var(--space-6));
}

/* ---------- Navegação inferior (mobile) ---------- */
.app-nav-mobile {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--bg-surface);
  border-top: 1px solid var(--border-default);
  z-index: 1035;
  display: flex;
  justify-content: space-around;
  align-items: stretch;
}
.app-nav-mobile .nav-mobile-item {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 48px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}
.app-nav-mobile .nav-mobile-item i { font-size: 20px; }
.app-nav-mobile .nav-mobile-item.active { color: var(--color-primary); }
.app-nav-mobile .nav-mobile-item:hover { text-decoration: none; color: var(--text-primary); }
.app-nav-mobile .nav-mobile-item.active:hover { color: var(--color-primary); }
.app-nav-mobile .fab {
  flex: 0 0 56px;
  color: var(--color-primary);
}
.app-nav-mobile .fab i { font-size: 34px; }

/* Menu flutuante do bottom nav (dropup) */
.nav-mobile-menu {
  min-width: 240px;
  padding: var(--space-2);
}
.nav-mobile-menu .dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  border-radius: var(--radius-md);
  font-size: 14px;
}
.nav-mobile-menu .dropdown-item i { font-size: 16px; color: var(--text-muted); }

/* Grupo segmentado do seletor de tema (dentro de menus) */
.theme-segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg-hover);
  border-radius: var(--radius-md);
}
.theme-segmented .theme-option {
  flex: 1 1 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.theme-segmented .theme-option:hover { color: var(--text-primary); }
.theme-segmented .theme-option.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-card);
}

/* Toggle de tema no cabeçalho (desktop) */
.theme-toggle-btn {
  width: 40px; height: 40px;
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
}
.theme-toggle-btn:hover { border-color: var(--border-strong); }

/* ---------- Página de autenticação ---------- */
.auth-page {
  min-height: calc(100vh - 64px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5) 0;
}
.auth-box { width: 100%; max-width: 380px; }
.auth-brand {
  text-align: center;
  margin-bottom: var(--space-5);
}
.auth-brand .brand-mark { width: 44px; height: 44px; border-radius: var(--radius-lg); }
.auth-brand .brand-mark i { font-size: 22px; }
.auth-brand h1 { margin: var(--space-3) 0 0; font-size: 22px; font-weight: 600; }
.auth-brand p { margin: 2px 0 0; font-size: 13px; color: var(--text-muted); }

/* ---------- Indicador global de carregamento HTMX ---------- */
#htmx-progress {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 2px;
  z-index: 2000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}
#htmx-progress::before {
  content: "";
  display: block;
  height: 100%;
  width: 40%;
  background: var(--color-primary);
  border-radius: 999px;
  animation: htmx-progress-slide 0.9s ease-in-out infinite;
}
#htmx-progress.active { opacity: 1; }
@keyframes htmx-progress-slide {
  0% { margin-left: -40%; }
  100% { margin-left: 100%; }
}
