.app-shell {
  --page-gutter: clamp(24px, 2vw, 32px);
  display: grid;
  width: 100%;
  min-height: 100vh;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "sidebar banner"
    "sidebar content";
  background: var(--brand-background);
}

.app-sidebar {
  grid-area: sidebar;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  height: 100vh;
  flex-direction: column;
  border-right: 1px solid var(--brand-border);
  background: var(--brand-background);
}

/* O aviso de assinatura fica FORA de .app-content de propósito: .app-content
   tem overflow-y:auto (usado como salvaguarda de overflow horizontal), e
   qualquer overflow não-visible em um ancestral quebra position:sticky dos
   descendentes contra o scroll real da página. Como item irmão do grid do
   shell, ele gruda no topo do scroll do documento exatamente como .app-sidebar
   já faz, sem depender de .app-content.

   .app-top-bar agrupa o aviso de assinatura E o botão de menu mobile (hambúrguer)
   num único bloco sticky: o botão fica em fluxo normal, logo depois do aviso, então
   ele sempre se posiciona corretamente abaixo do aviso (ou sozinho no topo, se o
   aviso estiver oculto) sem depender da altura do aviso, que varia (mensagem em
   1 ou 2 linhas, com ou sem CTA). Isso evita a faixa sem cobertura sólida entre o
   topo real da viewport e o aviso que existia antes (botão flutuante fixo em cima,
   aviso sticky com offset fixo embaixo, com o conteúdo da página vazando no vão
   entre os dois durante o scroll). */
.app-top-bar {
  grid-area: banner;
  align-self: start;
  position: sticky;
  top: 0;
  z-index: 25;
}

.app-sidebar-header {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: var(--header-height);
  border-bottom: 1px solid var(--brand-border);
  padding: 12px 14px;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-direction: row;
  min-width: 0;
  font-weight: 800;
}

.app-logo-full {
  width: min(100%, 230px);
  min-height: 44px;
  flex: 1 1 auto;
  border-radius: 0;
  background: transparent;
}

.app-logo img {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 10px;
  object-fit: contain;
}

.app-logo-wordmark {
  display: inline-flex;
  align-items: baseline;
  min-width: 0;
  gap: 0;
  color: #04282c;
  font-size: 1.25rem;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

.app-logo-wordmark-primary {
  color: #04282c;
}

.app-logo-wordmark-secondary {
  color: #4c9db1;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.app-sidebar-nav {
  display: grid;
  align-content: start;
  gap: 1px;
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 16px;
}

.page-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.page-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.privacy-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border: 1px solid var(--brand-border);
  border-radius: 10px;
  background: var(--brand-surface);
  color: var(--brand-text);
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.privacy-toggle svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.privacy-toggle:hover,
.privacy-toggle:focus-visible {
  border-color: color-mix(in srgb, var(--brand-primary) 38%, var(--brand-border));
  background: color-mix(in srgb, var(--brand-secondary) 12%, var(--brand-surface));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-secondary) 18%, transparent);
  outline: none;
}

/* Ativado (modo privacidade ligado): tom escuro solido, mesma linguagem dos
   botoes primarios do produto (--brand-primary), para ficar claramente
   diferente do estado neutro/hover - so no botao do olho ([data-privacy-toggle]),
   nao no sino de notificacoes que reaproveita .privacy-toggle com aria-expanded. */
[data-privacy-toggle][aria-pressed="true"] {
  border-color: var(--brand-primary);
  background: var(--brand-primary);
  color: var(--brand-surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-primary) 22%, transparent);
  outline: none;
}

/* Tooltip visivel do olho (o aria-label tem o mesmo texto). */
[data-privacy-toggle] {
  position: relative;
}

[data-privacy-toggle]::after {
  background: var(--brand-primary);
  border-radius: 8px;
  box-shadow: var(--brand-shadow);
  color: var(--brand-surface);
  content: attr(data-tooltip);
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1.35;
  opacity: 0;
  padding: 7px 10px;
  pointer-events: none;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  transition: opacity 0.12s ease;
  visibility: hidden;
  white-space: nowrap;
  z-index: 60;
}

[data-privacy-toggle]:hover::after,
[data-privacy-toggle]:focus-visible::after {
  opacity: 1;
  visibility: visible;
}

[data-privacy-toggle].is-tooltip-dismissed::after {
  opacity: 0;
  visibility: hidden;
}

[data-privacy-toggle][aria-pressed="true"]:hover,
[data-privacy-toggle][aria-pressed="true"]:focus-visible {
  background: color-mix(in srgb, var(--brand-primary) 88%, #000000);
  border-color: color-mix(in srgb, var(--brand-primary) 88%, #000000);
}

/* Sino da Central de Notificacoes (M3B). Reaproveita .privacy-toggle (mesmo
   tamanho visual/estados/breakpoints do olho ao lado - a topbar nao muda) e
   soma: alvo de toque de 44px (pseudo-elemento invisivel em volta do botao
   de 36px no desktop), badge discreto e o estado "central aberta"
   (aria-expanded). */
.notification-bell-wrap {
  position: relative;
  display: inline-flex;
}

.notification-bell {
  position: relative;
}

.notification-bell::before {
  position: absolute;
  inset: min(0px, calc((100% - 44px) / 2));
  content: "";
}

.notification-bell[aria-expanded="true"] {
  border-color: color-mix(in srgb, var(--brand-primary) 38%, var(--brand-border));
  background: color-mix(in srgb, var(--brand-secondary) 12%, var(--brand-surface));
}

/* 1-9 = numero exato; 10+ = "9+" (notifications-center.js/updateBadge). */
.notification-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  display: inline-flex;
  min-width: 18px;
  height: 18px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 2px solid var(--brand-background);
  background: var(--brand-primary);
  color: var(--brand-surface);
  font-size: 0.64rem;
  font-variant-numeric: tabular-nums;
  font-weight: 850;
  line-height: 1;
  padding: 0 4px;
  pointer-events: none;
}

.notification-badge[hidden] {
  display: none;
}

/* Nova notificacao via Realtime: um unico pulso curto, sem loop. */
.notification-badge.is-bumped {
  animation: notification-badge-bump 0.42s ease-out 1;
}

@keyframes notification-badge-bump {
  0% { transform: scale(1); }
  45% { transform: scale(1.22); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .notification-badge.is-bumped {
    animation: none;
  }
}

.privacy-mask-enabled :is(
  .stat-value,
  .clients-summary-value,
  .client-name,
  .client-subtext,
  .appointment-client,
  .appointment-meta,
  .appointment-professional,
  .cash-entry-title,
  .cash-entry-meta,
  .cash-entry-professional,
  .cash-lot-progress-headline strong,
  .cash-history-mobile-total strong,
  .cash-history-mobile-payment strong,
  .cash-flow-matrix tbody td,
  .cash-flow-mobile-row dd,
  .cash-entry-amount,
  .cash-entry-heading strong,
  .cash-outflow-value,
  .cash-kpi-highlight strong,
  .cash-kpi-highlight-grid strong,
  .cash-kpi-row-main strong,
  .cash-kpi-batch-row strong,
  .cash-expense-summary-grid strong,
  .cash-register-client strong,
  .cash-read-row strong,
  .cash-summary-line strong,
  .cash-confirm-line strong,
  .payment-ranking-value,
  .monthly-revenue-value,
  .service-name,
  .user-name,
  .company-context,
  .company-switcher-select,
  .company-avatar,
  [data-privacy-company],
  [data-company-switcher],
  [data-company-combobox-input],
  [data-company-option],
  [data-manage-subtitle],
  .subscription-preset-company,
  .select-company-option-name,
  /* Dashboard: KPIs (Atendimentos hoje/Faturamento previsto/Proximo
     atendimento) e totais de Formas de pagamento/Valor mensal dos agendamentos. */
  .dashboard-summary-kpi-value,
  .dashboard-summary-kpi-note,
  .dashboard-total-value,
  /* D17-B: numeros do Resumo da agenda do modo app. */
  .dashboard-app-banner-sentence strong,
  /* D17-C: valores e identidades do Caixa no modo app. */
  .cash-nd-private,
  /* Contas a Receber do Caixa Web: indicadores, clientes e valores do modal. */
  .cash-receivables-summary strong,
  .cash-receivable-client strong,
  .cash-receivable-client-balance small,
  .cash-receivable-private,
  /* D17-D: nomes, telefones e indicadores do Relacionamento no modo app. */
  .rel-nd-private,
  /* D17-F.1: nomes, telefones, iniciais e indicadores de Clientes no modo app. */
  .cl-nd-private,
  /* Dashboard mobile: primeiro nome do usuario na saudacao (mesmo criterio
     do .user-name da identidade no sidebar). */
  .dashboard-greeting-name,
  /* Agendamentos: so o nome do cliente do card do calendario fica oculto -
     horario, servico, status e o resto do card permanecem visiveis de
     proposito. .calendar-month-event-title e o card compacto da visao Mes
     (renderMonthEvent), um renderer separado de renderAppointmentCardContent
     (usado em Semana/Dia). */
  .appointment-card-client,
  .calendar-month-event-title
) {
  filter: blur(5px);
  user-select: none;
}

.privacy-mask-enabled .table tbody td:not(:last-child),
.privacy-mask-enabled :is(input, textarea)[type="email"],
.privacy-mask-enabled input[name*="email" i],
.privacy-mask-enabled input[name*="phone" i],
.privacy-mask-enabled input[name*="cpf" i],
.privacy-mask-enabled input[name*="name" i],
.privacy-mask-enabled select[name*="company" i],
.privacy-mask-enabled select[name*="empresa" i],
.privacy-mask-enabled [name="company_id"],
.privacy-mask-enabled textarea[name*="notes" i] {
  filter: blur(5px);
}

.privacy-mask-enabled :is(
  .stat-value,
  .clients-summary-value,
  .client-name,
  .client-subtext,
  .appointment-client,
  .appointment-meta,
  .appointment-professional,
  .cash-entry-title,
  .cash-entry-meta,
  .cash-entry-professional,
  .company-context,
  .company-switcher-select,
  .company-avatar,
  [data-privacy-company],
  [data-company-switcher],
  [data-company-combobox-input],
  [data-company-option],
  [data-manage-subtitle],
  .subscription-preset-company,
  .select-company-option-name,
  .dashboard-summary-kpi-value,
  .dashboard-summary-kpi-note,
  .dashboard-total-value,
  .dashboard-app-banner-sentence strong,
  .dashboard-greeting-name,
  .appointment-card-client,
  .calendar-month-event-title,
  .table tbody td:not(:last-child),
  input,
  select,
  textarea
) {
  transition: filter 0.16s ease;
}

.app-sidebar-footer {
  position: relative;
  display: grid;
  gap: var(--space-3);
  margin: 10px;
  border: 1px solid var(--brand-border);
  border-radius: var(--brand-radius);
  background: var(--brand-surface);
  box-shadow: 0 10px 28px rgba(4, 42, 43, 0.08);
  padding: var(--space-3);
}

.theme-control {
  position: static;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--control-height-sm);
  gap: var(--space-2);
  border: 1px solid var(--brand-border);
  border-radius: 9px;
  background: color-mix(in srgb, var(--brand-secondary) 9%, var(--brand-surface));
  color: var(--brand-primary);
  cursor: pointer;
  font-size: var(--font-sm);
  font-weight: 850;
}

.theme-popover {
  position: fixed;
  left: calc(var(--sidebar-width) + 12px);
  bottom: 20px;
  z-index: 90;
  width: min(300px, calc(100vw - 28px));
  border: 1px solid var(--brand-border);
  border-radius: 12px;
  background: var(--brand-surface);
  box-shadow: 0 18px 42px rgba(4, 42, 43, 0.18);
  padding: 12px;
  max-height: min(420px, calc(100vh - 40px));
  overflow-y: auto;
}

.theme-popover-header,
.theme-actions,
.theme-field-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-popover-header {
  justify-content: space-between;
  margin-bottom: 10px;
}

.theme-close {
  display: inline-grid;
  width: 28px;
  height: 28px;
  border: 1px solid var(--brand-border);
  border-radius: 8px;
  background: var(--brand-surface);
  color: var(--brand-muted);
  cursor: pointer;
  place-items: center;
}

.theme-fields {
  display: grid;
  gap: 8px;
}

/* Etapa 5/6 - controle de ativacao de Web Push (mesmo padrao visual do
   seletor de cores acima: .theme-toggle/.theme-popover/.theme-close ja
   cobrem toggle/popover/fechar - so o corpo interno precisa de regra
   propria). */
.push-control {
  position: static;
}

.push-popover-body {
  display: grid;
  gap: 10px;
}

.push-action-button {
  width: 100%;
}

.theme-field {
  display: grid;
  gap: 5px;
  color: var(--brand-text);
  font-size: 0.78rem;
  font-weight: 800;
}

.theme-color-input {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border: 1px solid var(--brand-border);
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
  padding: 2px;
}

.theme-hex-input {
  height: 38px;
  min-height: 38px;
  font-size: 0.82rem;
  padding: 8px 10px;
}

.theme-field small {
  color: #dc2626;
  font-size: 0.72rem;
}

.theme-actions {
  justify-content: flex-end;
  margin-top: 12px;
}

.theme-actions .button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.78rem;
}

.app-sidebar-section {
  display: grid;
  gap: var(--space-2);
}

.app-sidebar-section-items {
  display: grid;
  gap: 2px;
}

.app-sidebar-section-title {
  margin: 14px 12px 5px;
  color: var(--brand-muted);
  font-size: var(--font-xs);
  font-weight: 850;
  letter-spacing: 0.08em;
  line-height: 1.2;
  text-transform: uppercase;
}

.app-sidebar-divider {
  height: 1px;
  margin: 10px 10px 0;
  background: color-mix(in srgb, var(--brand-border) 76%, transparent);
}

.app-nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 34px;
  border-radius: 10px;
  color: var(--brand-muted);
  font-weight: 700;
  padding: 7px 10px;
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.app-nav-item:hover,
.app-nav-item.active,
.app-nav-item.is-active {
  background: color-mix(in srgb, var(--brand-secondary) 20%, var(--brand-surface));
  color: var(--brand-primary);
}

.app-nav-item.is-active-parent {
  color: var(--brand-primary);
}

.app-nav-node {
  min-width: 0;
}

.app-nav-children {
  display: grid;
  gap: 2px;
  margin: 2px 0 4px 17px;
  padding-left: 9px;
  border-left: 1px solid color-mix(in srgb, var(--brand-border) 84%, transparent);
}

.app-nav-children[hidden] {
  display: none;
}

.app-nav-children .app-nav-item {
  min-height: 30px;
  font-size: var(--font-sm);
  padding-block: 5px;
}

.app-nav-children .app-nav-children {
  margin-left: 13px;
}

.app-nav-item.active,
.app-nav-item.is-active {
  box-shadow: inset 3px 0 0 var(--brand-primary);
}

.app-nav-item:hover {
  transform: translateX(2px);
}

.app-nav-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}

.app-nav-icon svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.app-nav-toggle {
  width: 100%;
  appearance: none;
  border: 0;
  background: none;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  text-align: left;
  cursor: pointer;
}

.app-nav-toggle:focus-visible {
  outline: 2px solid var(--brand-secondary);
  outline-offset: 2px;
}

.app-nav-caret {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  margin-left: auto;
  transition: transform 0.16s ease;
}

.app-nav-caret svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.app-nav-toggle[aria-expanded="true"] .app-nav-caret {
  transform: rotate(90deg);
}

.app-nav-badge {
  margin-left: auto;
  flex: 0 0 auto;
  border-radius: 999px;
  background: color-mix(in srgb, var(--brand-accent) 32%, var(--brand-surface));
  color: var(--brand-primary);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  padding: 3px 8px;
  white-space: nowrap;
}

/* Indicador de novidade/destaque (nao mais status ativo/inativo) — pulso
   sutil em aros, tipo ondulacao na agua, na cor de destaque padrao do
   sistema (Neon Ice, ja usada em .app-nav-badge nesta mesma nav). */
.app-nav-status-dot {
  position: relative;
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  margin-left: auto;
  border-radius: 50%;
  background: var(--brand-primary);
  box-shadow: 0 0 0 2px var(--brand-surface);
}

.app-nav-status-dot::before,
.app-nav-status-dot::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: color-mix(in srgb, var(--brand-primary) 55%, transparent);
  opacity: 0;
}

@media (prefers-reduced-motion: no-preference) {
  .app-nav-status-dot::before,
  .app-nav-status-dot::after {
    animation: app-nav-dot-ripple 2.8s ease-out infinite;
  }

  .app-nav-status-dot::after {
    animation-delay: 1.4s;
  }
}

@keyframes app-nav-dot-ripple {
  0% {
    opacity: 0.5;
    transform: scale(1);
  }

  100% {
    opacity: 0;
    transform: scale(2.8);
  }
}

.app-content {
  grid-area: content;
  position: relative;
  display: flex;
  width: 100%;
  min-width: 0;
  flex-direction: column;
  min-height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
}

.app-content::-webkit-scrollbar,
.app-main::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.sidebar-toggle {
  display: none;
  min-width: 56px;
  height: 40px;
  border-radius: 10px;
  background: var(--brand-surface);
  color: var(--brand-text);
  border: 1px solid var(--brand-border);
  cursor: pointer;
}

.hamburger-icon,
.hamburger-icon::before,
.hamburger-icon::after {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  transition: transform 0.2s ease, background 0.2s ease;
}

.hamburger-icon {
  position: relative;
}

.hamburger-icon::before,
.hamburger-icon::after {
  content: "";
  position: absolute;
  left: 0;
}

.hamburger-icon::before {
  top: -6px;
}

.hamburger-icon::after {
  top: 6px;
}

.app-shell.sidebar-open .hamburger-icon {
  background: transparent;
}

.app-shell.sidebar-open .hamburger-icon::before {
  top: 0;
  transform: rotate(45deg);
}

.app-shell.sidebar-open .hamburger-icon::after {
  top: 0;
  transform: rotate(-45deg);
}

/* Em fluxo normal dentro de .app-top-bar (ver comentário acima da
   .app-top-bar): nada de position:fixed aqui, o botão já fica no lugar certo
   (abaixo do aviso de assinatura, ou sozinho no topo sem aviso) só por estar
   depois do aviso no DOM. margin-left:auto (definido no breakpoint mobile,
   onde o botão de fato aparece) que o alinha à direita. */
.floating-sidebar-toggle {
  box-shadow: 0 10px 24px rgba(4, 42, 43, 0.10);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.user-avatar {
  position: relative;
  display: grid;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  place-items: center;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--brand-secondary) 42%, var(--brand-border));
  background: color-mix(in srgb, var(--brand-secondary) 14%, var(--brand-surface));
  color: var(--brand-primary);
  font-size: 0.8rem;
  font-weight: 800;
  overflow: hidden;
}

.user-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-avatar:has(img) .avatar-initials {
  display: none;
}

.user-meta {
  display: grid;
  gap: 1px;
}

.user-name,
.user-role {
  max-width: 172px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-name {
  font-size: var(--font-md);
  font-weight: 800;
}

.user-role {
  color: var(--brand-muted);
  font-size: var(--font-sm);
}

/* Etapa 2.7 - identidade no rodape da sidebar: avatar + nome + perfil (abre
   o menu pessoal), empresa atual e "Voltar ao Hub". */
.sidebar-identity {
  gap: 8px;
  padding: 8px;
}

.identity-trigger {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-width: 0;
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--brand-text);
  cursor: pointer;
  font: inherit;
  padding: 6px 4px 6px 6px;
  text-align: left;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.identity-trigger:hover,
.identity-trigger[aria-expanded="true"] {
  border-color: color-mix(in srgb, var(--brand-secondary) 28%, var(--brand-border));
  background: color-mix(in srgb, var(--brand-secondary) 10%, var(--brand-surface));
}

.identity-trigger:focus-visible,
.current-company.is-switchable:focus-visible,
.identity-hub-link:focus-visible,
.user-menu .theme-toggle:focus-visible,
.user-menu-item:focus-visible {
  outline: 2px solid var(--brand-secondary);
  outline-offset: 2px;
}

.identity-trigger .user-meta {
  flex: 1 1 auto;
  min-width: 0;
}

/* Nome e perfil nunca cortados na sidebar estreita: quebram em ate 2
   linhas (o title do botao traz o texto completo para casos extremos). */
.identity-trigger .user-name,
.identity-trigger .user-role {
  display: -webkit-box;
  max-width: 100%;
  overflow-wrap: break-word;
  white-space: normal;
  line-height: 1.25;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.identity-trigger .user-name {
  font-size: 0.84rem;
}

.identity-trigger .user-role {
  font-size: var(--font-xs);
}

.identity-chevron {
  display: inline-flex;
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  margin-left: -4px;
  color: var(--brand-muted);
  transition: transform 0.16s ease;
}

.identity-chevron svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.identity-trigger[aria-expanded="true"] .identity-chevron {
  transform: rotate(180deg);
}

/* Menu pessoal: abre para cima, dentro da largura do proprio rodape (nunca
   estoura a sidebar nem o viewport). Sem transform de proposito - os
   popovers de Cores/Notificacoes dentro dele sao position:fixed. */
.user-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  left: 0;
  z-index: 30;
  display: grid;
  gap: 2px;
  border: 1px solid var(--brand-border);
  border-radius: 12px;
  background: var(--brand-surface);
  box-shadow: 0 18px 42px rgba(4, 42, 43, 0.18);
  padding: 6px;
}

.user-menu[hidden] {
  display: none;
}

.user-menu .theme-toggle,
.user-menu-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-3);
  width: 100%;
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--brand-text);
  cursor: pointer;
  font: inherit;
  font-size: var(--font-sm);
  font-weight: 750;
  padding: 8px 10px;
  text-align: left;
}

.user-menu .theme-toggle:hover,
.user-menu .theme-toggle[aria-expanded="true"],
.user-menu-item:hover {
  background: color-mix(in srgb, var(--brand-secondary) 14%, var(--brand-surface));
  color: var(--brand-primary);
}

.user-menu-separator {
  height: 1px;
  margin: 4px 6px;
  background: var(--brand-border);
}

.user-menu-logout {
  color: var(--brand-primary);
}

.current-company {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  border: 1px solid color-mix(in srgb, var(--brand-secondary) 48%, var(--brand-border));
  border-radius: 10px;
  background: color-mix(in srgb, var(--brand-secondary) 13%, var(--brand-surface));
  color: var(--brand-primary);
  font: inherit;
  font-size: var(--font-sm);
  font-weight: 800;
  line-height: 1.25;
  padding: 8px 10px;
  text-align: left;
}

.current-company-icon {
  display: inline-flex;
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  color: color-mix(in srgb, var(--brand-primary) 72%, var(--brand-secondary));
}

.current-company-icon svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.current-company-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.current-company.is-switchable {
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.current-company.is-switchable:hover,
.current-company.is-switchable[aria-expanded="true"] {
  border-color: color-mix(in srgb, var(--brand-primary) 42%, var(--brand-secondary));
  background: color-mix(in srgb, var(--brand-secondary) 20%, var(--brand-surface));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-secondary) 16%, transparent);
}

.identity-hub-link {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  border-radius: 8px;
  color: var(--brand-muted);
  font-size: var(--font-sm);
  font-weight: 750;
  padding: 6px 10px;
  transition: background 0.16s ease, color 0.16s ease;
}

.identity-hub-link svg {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.identity-hub-link:hover {
  background: color-mix(in srgb, var(--brand-secondary) 12%, var(--brand-surface));
  color: var(--brand-primary);
}

@media (pointer: coarse), (max-width: 860px) {
  .identity-hub-link,
  .user-menu .theme-toggle,
  .user-menu-item {
    min-height: 44px;
  }
}

/* Modal global "Trocar empresa". Desktop/tablet: dialogo central (radius 24,
   sombra suave, backdrop com blur leve); celular: folha inferior alta. Header
   fixo e lista com scroll interno - o dialogo nunca passa do viewport. */
html.company-switch-scroll-lock,
html.company-switch-scroll-lock body {
  overflow: hidden;
}

.modal.company-switch-modal {
  align-items: center;
  justify-content: center;
  background: rgba(4, 42, 43, 0.32);
  backdrop-filter: blur(6px) saturate(0.9);
  -webkit-backdrop-filter: blur(6px) saturate(0.9);
  padding: 24px;
}

.modal-content.company-switch-dialog {
  display: flex;
  width: min(100%, 920px);
  height: auto;
  max-height: calc(100dvh - 48px);
  flex-direction: column;
  border: 1px solid color-mix(in srgb, var(--brand-primary) 8%, transparent);
  border-radius: 24px;
  background: var(--brand-surface);
  box-shadow: 0 24px 64px rgba(4, 42, 43, 0.18), 0 2px 8px rgba(4, 42, 43, 0.06);
  overflow: hidden;
  padding: 0;
}

/* tabindex="-1" so para o foco nao cair no <body> em clique interno. */
.modal-content.company-switch-dialog:focus {
  outline: none;
}

.company-switch-modal[data-count="2"] .company-switch-dialog {
  width: min(100%, 660px);
}

.company-switch-header {
  position: relative;
  z-index: 1;
  display: flex;
  flex: 0 0 auto;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  background: var(--brand-surface);
  box-shadow: 0 1px 0 color-mix(in srgb, var(--brand-primary) 6%, transparent), 0 8px 16px -14px rgba(4, 42, 43, 0.28);
  padding: 28px 24px 20px 32px;
}

.company-switch-heading {
  min-width: 0;
}

.company-switch-heading h2 {
  margin: 0;
  color: var(--brand-text);
  font-size: 1.5rem;
  font-weight: 850;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

.company-switch-heading p {
  margin: 6px 0 0;
  color: var(--brand-muted);
  font-size: var(--font-md);
  line-height: 1.45;
}

.company-switch-close {
  display: inline-grid;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  margin: -4px -4px 0 0;
  border: 1px solid color-mix(in srgb, var(--brand-primary) 10%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--brand-secondary) 6%, var(--brand-surface));
  color: var(--brand-text);
  cursor: pointer;
  place-items: center;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.company-switch-close svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 2;
}

.company-switch-close:hover,
.company-switch-close:focus-visible {
  border-color: color-mix(in srgb, var(--brand-secondary) 55%, transparent);
  background: color-mix(in srgb, var(--brand-secondary) 16%, var(--brand-surface));
  color: var(--brand-primary);
  outline: none;
}

.company-switch-close:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-secondary) 40%, transparent);
}

.company-switch-close:active {
  transform: scale(0.96);
}

.company-switch-body {
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 24px 32px 32px;
}

.company-switch-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.company-switch-card {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 10px;
  border: 1px solid color-mix(in srgb, var(--brand-primary) 11%, transparent);
  border-radius: 20px;
  background: var(--brand-surface);
  box-shadow: 0 1px 2px rgba(4, 42, 43, 0.04), 0 8px 20px -16px rgba(4, 42, 43, 0.22);
  padding: 20px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.company-switch-card:hover {
  border-color: color-mix(in srgb, var(--brand-secondary) 50%, transparent);
  box-shadow: 0 1px 2px rgba(4, 42, 43, 0.05), 0 14px 28px -18px rgba(4, 42, 43, 0.32);
}

/* Empresa atual: tint teal + borda forte + pill "ATUAL" (nunca so cor). */
.company-switch-card.is-current {
  border: 2px solid color-mix(in srgb, var(--brand-secondary) 78%, var(--brand-primary));
  background: color-mix(in srgb, var(--brand-secondary) 9%, var(--brand-surface));
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand-secondary) 10%, transparent);
  padding: 19px;
}

.company-switch-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  min-height: 52px;
  margin-bottom: 4px;
}

.company-switch-mark {
  display: inline-grid;
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  border-radius: 14px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--brand-primary) 82%, var(--brand-secondary)), var(--brand-primary));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 4px 10px -6px rgba(4, 42, 43, 0.5);
  color: #ffffff;
  font-size: 1.1rem;
  font-weight: 850;
  letter-spacing: 0.02em;
  place-items: center;
}

.company-switch-badge {
  margin-top: 6px;
  border: 1px solid color-mix(in srgb, var(--brand-secondary) 45%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--brand-secondary) 22%, var(--brand-surface));
  color: var(--brand-primary);
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  line-height: 1;
  padding: 6px 11px;
  text-transform: uppercase;
}

.company-switch-name {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: var(--brand-text);
  font-size: 1.08rem;
  font-weight: 850;
  line-height: 1.3;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.company-switch-meta {
  display: grid;
  gap: 4px;
}

.company-switch-segment,
.company-switch-role {
  margin: 0;
  color: var(--brand-muted);
  font-size: var(--font-sm);
  line-height: 1.35;
}

.company-switch-segment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: var(--font-md);
}

.company-switch-segment svg {
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
  fill: none;
  stroke: color-mix(in srgb, var(--brand-muted) 80%, var(--brand-secondary));
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.company-switch-footer {
  display: grid;
  margin-top: auto;
  padding-top: 10px;
}

.modal .company-switch-open {
  width: 100%;
  min-height: 48px;
  border-radius: 12px;
  font-size: var(--font-md);
  font-weight: 800;
}

.company-switch-open.button-primary {
  border-color: var(--theme-button, var(--brand-primary));
  background: var(--theme-button, var(--brand-primary));
  box-shadow: 0 6px 14px -10px rgba(4, 42, 43, 0.7);
  color: #ffffff;
}

.company-switch-open.button-primary:hover {
  background: color-mix(in srgb, var(--theme-button, var(--brand-primary)) 86%, var(--brand-secondary));
}

/* Atual: Abrir continua clicavel (fecha o modal, sem troca), mas secundario. */
.company-switch-open.button-secondary {
  border-color: color-mix(in srgb, var(--brand-secondary) 60%, transparent);
  background: var(--brand-surface);
  color: var(--brand-primary);
}

.company-switch-open.button-secondary:hover {
  border-color: color-mix(in srgb, var(--brand-secondary) 85%, var(--brand-primary));
  background: color-mix(in srgb, var(--brand-secondary) 8%, var(--brand-surface));
}

.company-switch-open:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--brand-secondary) 35%, transparent);
}

.company-switch-open:active {
  transform: translateY(0) scale(0.99);
}

@media (prefers-reduced-motion: reduce) {
  .company-switch-card,
  .company-switch-close,
  .company-switch-open {
    transition: none;
  }
}

@media (min-width: 600px) {
  .company-switch-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .company-switch-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .company-switch-modal[data-count="2"] .company-switch-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 767px) and (min-width: 600px) {
  .company-switch-header {
    padding: 24px 20px 18px 24px;
  }

  .company-switch-body {
    padding: 20px 24px 24px;
  }
}

/* Celular: folha inferior alta (mesmo idioma das folhas do Agenda), acima da
   bottom nav (o .modal fica em z-index 80), com safe-area. */
@media (max-width: 599px) {
  .modal.company-switch-modal {
    align-items: flex-end;
    justify-content: stretch;
    padding: max(12px, env(safe-area-inset-top, 0px)) 0 0;
  }

  .modal-content.company-switch-dialog,
  .company-switch-modal[data-count="2"] .company-switch-dialog {
    width: 100%;
    max-height: calc(100dvh - max(12px, env(safe-area-inset-top, 0px)));
    border-width: 1px 0 0;
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -18px 48px rgba(4, 42, 43, 0.22);
  }

  .company-switch-header {
    padding: 22px 12px 14px 20px;
  }

  .company-switch-header::before {
    position: absolute;
    top: 8px;
    left: 50%;
    width: 40px;
    height: 4px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--brand-primary) 16%, transparent);
    content: "";
    transform: translateX(-50%);
  }

  .company-switch-heading h2 {
    font-size: 1.3rem;
  }

  .company-switch-close {
    margin: -2px 0 0;
  }

  .company-switch-body {
    padding: 16px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  }

  .company-switch-grid {
    gap: 12px;
  }

  .company-switch-card {
    padding: 16px;
  }

  .company-switch-card.is-current {
    padding: 15px;
  }

  .company-switch-top {
    min-height: 44px;
  }

  .company-switch-mark {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
    border-radius: 12px;
    font-size: 1rem;
  }
}

.app-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-content: start;
  gap: clamp(12px, 1.5vw, 18px);
  width: 100%;
  max-width: none;
  min-height: 100vh;
  margin-inline: 0;
  padding: clamp(16px, 2.2vw, 26px) var(--page-gutter, clamp(24px, 2vw, 32px));
  overflow: visible;
  scrollbar-width: none;
}

/* Contrato do shell: cada tela ocupa toda a coluna disponivel depois da
   sidebar. Limites de leitura continuam pertencendo aos componentes internos
   (textos, formularios e modais), nunca ao canvas da pagina. */
.app-main > * {
  width: 100%;
  min-width: 0;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-7);
  border-radius: var(--brand-radius) var(--brand-radius) 0 0;
  padding-top: var(--space-3);
  flex-shrink: 0;
}

.page-title-group {
  display: grid;
  gap: var(--space-2);
}

.module-badge {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  border-radius: 999px;
  background: color-mix(in srgb, var(--brand-secondary) 18%, var(--brand-surface));
  color: var(--brand-primary);
  font-size: var(--font-xs);
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1;
  padding: 5px 10px;
  text-transform: uppercase;
}

.breadcrumb {
  color: var(--brand-muted);
  font-size: var(--font-sm);
  font-weight: 700;
}

.page-title {
  color: var(--brand-text);
  font-size: var(--font-page-title);
  line-height: 1.15;
}

.page-subtitle {
  max-width: 760px;
  color: var(--brand-muted);
}

.grid {
  display: grid;
  gap: 16px;
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.content-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(12, minmax(0, 1fr));
}

.span-4 {
  grid-column: span 4;
}

.span-6 {
  grid-column: span 6;
}

.span-8 {
  grid-column: span 8;
}

.span-12 {
  grid-column: span 12;
}

.centered-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(100%, 420px);
}

@media (max-width: 1100px) {
  .app-shell {
    --page-gutter: 20px;
  }

  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "banner"
      "content";
  }

  /* Abre ABAIXO do aviso de assinatura, nunca por cima/atrás dele —
     --subscription-banner-height é a altura real do aviso, medida via
     ResizeObserver em components.js (varia com a mensagem, e é 0 quando não
     há aviso). Assim o menu nunca precisa disputar z-index com o aviso: eles
     simplesmente não ocupam a mesma região da tela. O botão de menu
     (.floating-sidebar-toggle) continua flutuando por cima — do conteúdo da
     página quando fechado, do topo do próprio menu quando aberto — do mesmo
     jeito que já flutua hoje; só o aviso empurra o início do menu. */
  .app-sidebar {
    position: fixed;
    top: var(--subscription-banner-height, 0px);
    left: 0;
    width: min(84vw, var(--sidebar-width));
    height: calc(100dvh - var(--subscription-banner-height, 0px));
    max-height: calc(100dvh - var(--subscription-banner-height, 0px));
    min-height: 0;
    overflow: hidden;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }

  .app-sidebar-header,
  .app-sidebar-footer {
    flex: 0 0 auto;
  }

  .app-sidebar-nav {
    min-height: 0;
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-bottom: 14px;
  }

  /* "none" (e nao translateX(0)): um transform aberto faria da sidebar o
     containing block dos popovers position:fixed do menu pessoal (Cores,
     Notificacoes), recortados pelo overflow:hidden dela. A transicao continua
     identica - none interpola com translateX(-100%). */
  .app-shell.sidebar-open .app-sidebar {
    transform: none;
  }

  .app-shell.sidebar-open::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 15;
    background: rgba(4, 42, 43, 0.38);
  }

  .sidebar-toggle {
    display: grid;
    place-items: center;
  }

  .floating-sidebar-toggle {
    width: 56px;
    min-width: 56px;
    height: 42px;
    margin: 12px 5% 12px auto;
    border-radius: 11px;
  }

  .theme-popover {
    left: 14px;
    bottom: 160px;
    width: min(320px, calc(100vw - 28px));
    max-height: min(360px, calc(100vh - 200px));
  }

  .page-header {
    display: grid;
  }

  .page-actions {
    width: 100%;
    justify-content: stretch;
  }

  .page-header-actions {
    width: 100%;
    justify-content: stretch;
  }

  .privacy-toggle {
    width: 46px;
    height: 44px;
    flex-basis: 46px;
  }

  .page-actions .button {
    flex: 1 1 180px;
  }

  .page-header-actions .page-actions {
    flex: 1 1 180px;
  }

  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }

  .span-4,
  .span-6,
  .span-8 {
    grid-column: span 12;
  }
}

@media (max-width: 560px) {
  .app-shell {
    --page-gutter: clamp(12px, 4vw, 16px);
  }

  .app-main {
    gap: 16px;
    padding: 16px var(--page-gutter);
  }

  .app-sidebar-header {
    min-height: auto;
    padding: 14px 16px;
  }

  .app-sidebar-footer {
    margin: 8px 10px;
    gap: 8px;
    padding: 8px;
  }

  .floating-sidebar-toggle {
    margin-right: 16px;
  }

  .page-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .page-header-actions {
    display: grid;
    grid-template-columns: 46px 46px 1fr;
  }

  .page-header-actions > .page-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   Etapa 3.7 - Sidebar global (desktop + drawer "Mais" do mobileAppShell).
   So apresentacao: mesmo markup de components.js (grupos, itens, activeKey,
   aria-current, acordeao, identidade, empresa atual, Voltar ao Hub). Nada de
   geometria do offcanvas e alterado aqui (top/bottom/transform continuam nas
   regras do breakpoint de 860px acima). A navegacao central rola quando
   falta altura; cabecalho e identidade ficam sempre visiveis.
   ========================================================================== */
.app-sidebar {
  background: color-mix(in srgb, var(--brand-surface) 55%, var(--brand-background));
}

@media (min-width: 861px) {
  .app-sidebar {
    border-right-color: color-mix(in srgb, var(--brand-border) 70%, transparent);
  }
}

.app-sidebar-header {
  flex: 0 0 auto;
  min-height: 60px;
  border-bottom-color: transparent;
  padding: 12px 18px 6px;
}

.app-sidebar-nav {
  min-height: 0;
  gap: 0;
  padding: 4px 12px 12px;
  scrollbar-color: color-mix(in srgb, var(--brand-primary) 18%, transparent) transparent;
  scrollbar-width: thin;
}

.app-sidebar-section {
  gap: 0;
}

.app-sidebar-section-items {
  gap: 2px;
}

.app-sidebar-section-title {
  margin: 12px 12px 5px;
  color: color-mix(in srgb, var(--brand-text) 52%, transparent);
  font-size: 0.66rem;
  font-weight: 850;
  letter-spacing: 0.11em;
}

.app-sidebar-section:first-child .app-sidebar-section-title {
  margin-top: 6px;
}

.app-sidebar-divider {
  margin: 10px 12px 0;
  background: color-mix(in srgb, var(--brand-border) 55%, transparent);
}

.app-nav-item {
  position: relative;
  gap: 11px;
  min-height: 36px;
  border-radius: 11px;
  color: color-mix(in srgb, var(--brand-text) 70%, var(--brand-muted));
  font-size: 0.86rem;
  font-weight: 600;
  padding: 7px 10px 7px 14px;
  transition: background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.app-nav-item .app-nav-icon {
  color: color-mix(in srgb, var(--brand-text) 58%, transparent);
  transition: color 0.16s ease;
}

.app-nav-item:hover {
  background: color-mix(in srgb, var(--brand-secondary) 10%, transparent);
  color: var(--brand-primary);
  transform: none;
}

.app-nav-item:hover .app-nav-icon,
.app-nav-item.is-active-parent .app-nav-icon {
  color: var(--brand-primary);
}

/* Item ativo: superficie teal/ciano muito leve + Evergreen + indicador. */
.app-nav-item.active,
.app-nav-item.is-active {
  background: color-mix(in srgb, var(--brand-accent) 14%, #ffffff);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand-secondary) 26%, transparent);
  color: var(--brand-primary);
  font-weight: 800;
}

.app-nav-item.active .app-nav-icon,
.app-nav-item.is-active .app-nav-icon {
  color: var(--brand-primary);
}

.app-nav-item.active::before,
.app-nav-item.is-active::before {
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 0;
  width: 3px;
  border-radius: 0 4px 4px 0;
  background: var(--brand-primary);
  content: "";
}

.app-nav-item.is-active-parent {
  font-weight: 750;
}

.app-nav-item:focus-visible {
  outline: 2px solid var(--brand-secondary);
  outline-offset: -2px;
}

.app-nav-icon svg {
  width: 17px;
  height: 17px;
}

.app-nav-children {
  margin: 2px 0 4px 21px;
  padding-left: 8px;
  border-left-color: color-mix(in srgb, var(--brand-border) 70%, transparent);
}

.app-nav-children .app-nav-item {
  min-height: 34px;
  font-size: 0.84rem;
}

/* Rodape / identidade: bloco claro, compacto e sempre visivel. */
.app-sidebar-footer.sidebar-identity {
  flex: 0 0 auto;
  gap: 6px;
  margin: 6px 12px 12px;
  border-color: color-mix(in srgb, var(--brand-border) 75%, transparent);
  border-radius: 18px;
  background: var(--brand-surface);
  box-shadow: 0 1px 2px rgba(4, 42, 43, 0.04), 0 10px 26px rgba(4, 42, 43, 0.06);
  padding: 6px;
}

.sidebar-identity .identity-trigger {
  border-radius: 12px;
  padding: 6px 6px 6px 6px;
}

.sidebar-identity .user-avatar {
  width: 36px;
  height: 36px;
  flex-basis: 36px;
  border-color: transparent;
  background: color-mix(in srgb, var(--brand-accent) 24%, #ffffff);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand-secondary) 30%, transparent);
  font-size: 0.78rem;
  font-weight: 850;
}

.sidebar-identity .identity-trigger .user-name {
  color: var(--brand-primary);
  font-size: 0.8rem;
  font-weight: 800;
}

.sidebar-identity .identity-trigger .user-role {
  font-size: 0.72rem;
  font-weight: 650;
}

.sidebar-identity .identity-chevron {
  margin-left: 0;
}

.sidebar-identity .current-company {
  border-color: color-mix(in srgb, var(--brand-secondary) 34%, var(--brand-border));
  border-radius: 12px;
  background: color-mix(in srgb, var(--brand-secondary) 9%, #ffffff);
  font-size: 0.82rem;
  padding: 8px 10px;
}

.sidebar-identity .current-company-icon {
  display: grid;
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  place-items: center;
  border-radius: 8px;
  background: #ffffff;
  color: var(--brand-primary);
}

.sidebar-identity .identity-hub-link {
  border-radius: 10px;
  font-size: 0.8rem;
}

/* Drawer "Mais" e legado mobile: alvos de toque confortaveis. */
@media (pointer: coarse), (max-width: 860px) {
  .app-nav-item {
    min-height: 44px;
  }

  .app-nav-children .app-nav-item {
    min-height: 44px;
  }
}

@media (max-width: 860px) {
  .app-sidebar-footer.sidebar-identity {
    margin: 6px 10px 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-nav-item,
  .app-nav-item .app-nav-icon {
    transition: none;
  }
}

/* ==========================================================================
   Shell mobile de app (opt-in) - renderAppShell({ mobileAppShell: true }).
   Etapa 3.1: ativado SOMENTE no Dashboard. Todas as regras ficam presas a
   .app-shell.has-mobile-app-shell (ou a elementos que so existem nesse modo),
   entao telas que nao aderiram continuam com o shell anterior (hamburguer
   flutuante + offcanvas) sem nenhuma diferenca. Mesmo breakpoint do shell
   compartilhado (860px).
   ========================================================================== */
.mobile-app-topbar,
.mobile-bottom-nav {
  display: none;
}

@media (max-width: 860px) {
  .app-shell.has-mobile-app-shell {
    --mobile-bottom-nav-height: 64px;
    --mobile-bottom-nav-offset: calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom, 0px));
  }

  /* Sem o respiro transparente do mount: a topbar encosta no aviso, sem
     faixa por onde o conteudo apareceria durante o scroll. */
  .app-shell.has-mobile-app-shell .subscription-banner-mount {
    padding-bottom: 0;
  }

  .app-shell.has-mobile-app-shell .mobile-app-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 60px;
    border-bottom: 1px solid color-mix(in srgb, var(--brand-border) 70%, transparent);
    background: color-mix(in srgb, var(--brand-background) 90%, transparent);
    -webkit-backdrop-filter: saturate(1.3) blur(14px);
    backdrop-filter: saturate(1.3) blur(14px);
    padding: 8px max(var(--page-gutter), env(safe-area-inset-right, 0px)) 8px max(var(--page-gutter), env(safe-area-inset-left, 0px));
  }

  .mobile-app-topbar-brand {
    display: flex;
    align-items: center;
    min-width: 0;
  }

  .mobile-app-topbar .app-logo-full {
    width: auto;
    min-height: 40px;
    flex: 0 1 auto;
    gap: 9px;
  }

  .mobile-app-topbar .app-logo img {
    width: 32px;
    height: 32px;
    flex-basis: 32px;
  }

  .mobile-app-topbar .app-logo-wordmark {
    font-size: 1.18rem;
  }

  /* Offcanvas ("Mais"): o MESMO sidebar. O mobileAppShell reserva a area
     inferior ocupada pela bottom navigation para que a sidebar de "Mais"
     nunca a sobreponha: top/bottom vem das alturas REAIS medidas via
     ResizeObserver em components.js (--mobile-app-top-bar-height = aviso de
     assinatura + topbar; --mobile-app-bottom-nav-height = bottom nav ja com
     padding e safe-area, que por isso nao e somada de novo aqui). Os
     fallbacks so valem antes da primeira medicao.
     Dentro dele: cabecalho e rodape/identidade fixos (flex 0 0 auto, regra
     do breakpoint acima) e so a navegacao rola - o rodape nunca e
     escondido para caber.
     Pilha (z-index): topbar 25 > bottom nav 21 > sidebar 20 > backdrop 15
     > conteudo. Sidebar e bottom nav nao se sobrepoem geometricamente, e o
     backdrop fica abaixo da bottom nav, que continua utilizavel. */
  .app-shell.has-mobile-app-shell .app-sidebar {
    top: var(--mobile-app-top-bar-height, var(--subscription-banner-height, 0px));
    bottom: var(--mobile-app-bottom-nav-height, var(--mobile-bottom-nav-offset));
    height: auto;
    max-height: none;
    border-right: 0;
    border-radius: 0 22px 22px 0;
  }

  .app-shell.has-mobile-app-shell.sidebar-open .app-sidebar {
    box-shadow: 18px 0 44px rgba(4, 42, 43, 0.16);
  }

  /* A marca ja esta na topbar, logo acima do offcanvas. */
  .app-shell.has-mobile-app-shell .app-sidebar-header {
    display: none;
  }

  .app-shell.has-mobile-app-shell .app-main {
    padding-bottom: calc(var(--mobile-app-bottom-nav-height, var(--mobile-bottom-nav-offset)) + 28px);
  }

  .app-shell.has-mobile-app-shell .mobile-bottom-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 21;
    display: flex;
    align-items: stretch;
    gap: 2px;
    min-height: var(--mobile-bottom-nav-offset);
    border-top: 1px solid var(--brand-border);
    background: color-mix(in srgb, var(--brand-surface) 94%, transparent);
    box-shadow: 0 -10px 28px rgba(4, 42, 43, 0.07);
    -webkit-backdrop-filter: saturate(1.3) blur(16px);
    backdrop-filter: saturate(1.3) blur(16px);
    padding: 6px max(6px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(6px, env(safe-area-inset-left, 0px));
  }

  .mobile-bottom-nav-item {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    min-height: 52px;
    border: 0;
    border-radius: 14px;
    background: transparent;
    color: var(--brand-muted);
    cursor: pointer;
    font: inherit;
    font-size: clamp(0.64rem, 2.9vw, 0.72rem);
    font-weight: 750;
    letter-spacing: -0.005em;
    line-height: 1.1;
    padding: 4px 2px;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
  }

  /* "Relacionamento" e o rotulo mais longo: um pouco mais de largura para
     nao truncar em 320px (5 itens desde o M2.1; os demais seguem >= 44px). */
  .mobile-bottom-nav-item[data-mobile-nav="relacionamento"] {
    flex-grow: 1.6;
  }

  .mobile-bottom-nav-icon {
    display: grid;
    width: 46px;
    height: 28px;
    place-items: center;
    border-radius: 999px;
    transition: background 0.18s ease, color 0.18s ease;
  }

  .mobile-bottom-nav-icon svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.9;
  }

  .mobile-bottom-nav-more .mobile-bottom-nav-icon svg {
    fill: currentColor;
    stroke: none;
  }

  .mobile-bottom-nav-label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-bottom-nav-item:hover {
    color: var(--brand-primary);
  }

  .mobile-bottom-nav-item.is-active,
  .mobile-bottom-nav-more[aria-expanded="true"] {
    color: var(--brand-primary);
    font-weight: 850;
  }

  .mobile-bottom-nav-item.is-active .mobile-bottom-nav-icon,
  .mobile-bottom-nav-more[aria-expanded="true"] .mobile-bottom-nav-icon {
    background: color-mix(in srgb, var(--brand-accent) 30%, var(--brand-surface));
  }

  .mobile-bottom-nav-item:focus-visible {
    outline: 2px solid var(--brand-primary);
    outline-offset: -2px;
  }
}

@media (max-width: 860px) and (prefers-reduced-motion: reduce) {
  .app-shell.has-mobile-app-shell .app-sidebar,
  .mobile-bottom-nav-icon {
    transition: none;
  }
}

/* ==========================================================================
   Modo app mobile do Gestao (Mobile M2.1 / M2.1.1). Regra de produto:
   layout = viewport (ate 860px, o breakpoint do shell); PWA = runtime.
   - Arquitetura visual (header compacto, bloco superior unico, tab bar):
     qualquer celular, navegador ou instalado, nas paginas que aderiram com
     <body data-mobile-app-mode> (hoje o Dashboard; cada tela entra no seu
     checkpoint). Telas sem o atributo seguem o shell opt-in anterior.
   - So o que e do app instalado fica em html[data-pwa-display="standalone"]
     (pwa-runtime.js): sem "elastico"/pull-to-refresh do navegador. A cor
     da status bar e do runtime (components.js). Safe areas via env(), que
     vale 0 no navegador e o recorte real no app.
   Tudo preso a .app-shell.has-mobile-app-shell; desktop nao muda.
   ========================================================================== */
@media (max-width: 860px) {
  /* Indicador de conexao do runtime: logo acima da bottom nav. */
  .app-shell.has-mobile-app-shell {
    --pwa-connection-bottom: calc(var(--mobile-app-bottom-nav-height, var(--mobile-bottom-nav-offset)) + 10px);
  }

  body[data-mobile-app-mode] .app-shell.has-mobile-app-shell {
    min-height: 100dvh;
    -webkit-tap-highlight-color: transparent;
  }

  /* Bloco sticky (aviso + topbar) com um unico fundo, comecando abaixo da
     status bar/notch quando houver. A altura medida
     (--mobile-app-top-bar-height) ja inclui esse respiro. */
  body[data-mobile-app-mode] .app-shell.has-mobile-app-shell .app-top-bar {
    background: color-mix(in srgb, var(--brand-background) 90%, transparent);
    -webkit-backdrop-filter: saturate(1.3) blur(14px);
    backdrop-filter: saturate(1.3) blur(14px);
    padding-top: env(safe-area-inset-top, 0px);
  }

  /* Header de app: compacto, sem segundo desfoque sobre o bloco. */
  body[data-mobile-app-mode] .app-shell.has-mobile-app-shell .mobile-app-topbar {
    min-height: 0;
    background: transparent;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    padding-top: 6px;
    padding-bottom: 6px;
  }

  body[data-mobile-app-mode] .app-shell.has-mobile-app-shell .mobile-app-topbar,
  body[data-mobile-app-mode] .app-shell.has-mobile-app-shell .mobile-bottom-nav {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }

  body[data-mobile-app-mode] .app-shell.has-mobile-app-shell .mobile-bottom-nav-item {
    touch-action: manipulation;
  }

  /* Somente app instalado: sem o pull-to-refresh/elastico do navegador. */
  html[data-pwa-display="standalone"]:has(.app-shell.has-mobile-app-shell),
  html[data-pwa-display="standalone"]:has(.app-shell.has-mobile-app-shell) body {
    overscroll-behavior-y: none;
  }
}

/* ==========================================================================
   Mobile M2.6 - tela "Mais" do app + "voltar" na topbar (shell
   mobileAppShell, ate 860px; desktop nao muda).
   - O "Mais" deixou de abrir o sidebar desktop: no celular o sidebar sai de
     cena e a tela [data-mobile-more] (components.js) ocupa a area entre a
     topbar e a bottom nav (alturas reais medidas), que continua utilizavel.
   - Telas abertas pelo Mais mostram "< Mais" a esquerda da marca.
   ========================================================================== */
.mobile-more,
.mobile-app-back {
  display: none;
}

@media (max-width: 860px) {
  .app-shell.has-mobile-app-shell .app-sidebar {
    display: none;
  }

  html.mobile-more-scroll-lock,
  html.mobile-more-scroll-lock body {
    overflow: hidden;
  }

  /* ---- Topbar: voltar ---------------------------------------------------- */
  .app-shell.has-mobile-app-shell .mobile-app-topbar.has-back .mobile-app-topbar-brand {
    gap: 4px;
  }

  .app-shell.has-mobile-app-shell .mobile-app-back {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    flex: 0 0 auto;
    height: 40px;
    min-width: 44px;
    margin-left: -8px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--brand-primary);
    cursor: pointer;
    font: inherit;
    font-size: 0.95rem;
    font-weight: 800;
    padding: 0 10px 0 4px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  /* Alvo de toque de 44px sem crescer a topbar compacta. */
  .app-shell.has-mobile-app-shell .mobile-app-back::before {
    content: "";
    position: absolute;
    inset: -2px 0;
  }

  .app-shell.has-mobile-app-shell .mobile-app-back svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2.2;
  }

  .app-shell.has-mobile-app-shell .mobile-app-back:hover {
    background: color-mix(in srgb, var(--brand-accent) 18%, transparent);
  }

  .app-shell.has-mobile-app-shell .mobile-app-back:focus-visible {
    outline: 2px solid var(--brand-primary);
    outline-offset: 0;
  }

  .app-shell.has-mobile-app-shell .mobile-app-topbar.has-back .app-logo-full {
    padding-left: 10px;
    border-left: 1px solid var(--brand-border);
  }

  /* ---- Tela Mais --------------------------------------------------------- */
  .app-shell.has-mobile-app-shell .mobile-more:not([hidden]) {
    position: fixed;
    top: var(--mobile-app-top-bar-height, 60px);
    right: 0;
    bottom: var(--mobile-app-bottom-nav-height, var(--mobile-bottom-nav-offset));
    left: 0;
    z-index: 20;
    display: block;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--brand-background);
    outline: none;
    -webkit-overflow-scrolling: touch;
    animation: mobile-more-in 0.18s ease-out;
  }

  /* So opacidade: sem transform a geometria e final desde o 1o quadro e a
     tela nunca vira containing block dos popovers fixos (Cores/Notificacoes). */
  @keyframes mobile-more-in {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  .mobile-more-scroll {
    display: grid;
    gap: 18px;
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
    padding: 16px max(var(--page-gutter), env(safe-area-inset-right, 0px)) 28px max(var(--page-gutter), env(safe-area-inset-left, 0px));
  }

  .mobile-more-title {
    margin: 0;
    color: var(--brand-primary);
    font-size: clamp(1.3rem, 5.6vw, 1.55rem);
    font-weight: 850;
    letter-spacing: -0.02em;
    line-height: 1.15;
  }

  .mobile-more-profile,
  .mobile-more-list {
    overflow: hidden;
    border: 1px solid var(--brand-border);
    border-radius: 18px;
    background: var(--brand-surface);
    box-shadow: 0 6px 18px rgba(4, 42, 43, 0.05);
  }

  .mobile-more-list {
    display: grid;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .mobile-more .mobile-more-list > * + * {
    border-top: 1px solid color-mix(in srgb, var(--brand-border) 75%, transparent);
  }

  .mobile-more-identity {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
  }

  .mobile-more-identity .user-avatar {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
  }

  .mobile-more-identity-text,
  .mobile-more-company-text {
    display: grid;
    flex: 1 1 auto;
    gap: 2px;
    min-width: 0;
  }

  .mobile-more-identity-name {
    overflow: hidden;
    color: var(--brand-text);
    font-size: 1rem;
    font-weight: 850;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-more-identity-role,
  .mobile-more-company-hint {
    color: var(--brand-muted);
    font-size: 0.82rem;
    font-weight: 700;
  }

  .mobile-more-group {
    display: grid;
    gap: 8px;
  }

  .mobile-more-group-title {
    margin: 0;
    padding: 0 4px;
    color: var(--brand-muted);
    font-size: 0.74rem;
    font-weight: 850;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  /* Linha de app: icone + rotulo + chevron, alvo >= 54px. */
  .mobile-more-row,
  .mobile-more-company,
  .mobile-more .theme-toggle {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    width: 100%;
    min-height: 54px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--brand-text);
    cursor: pointer;
    font: inherit;
    font-size: 0.98rem;
    font-weight: 750;
    padding: 8px 14px 8px 12px;
    text-align: left;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  .mobile-more-company {
    border-top: 1px solid color-mix(in srgb, var(--brand-border) 75%, transparent);
    cursor: default;
  }

  .mobile-more-company.is-switchable {
    cursor: pointer;
  }

  .mobile-more-company-name {
    overflow: hidden;
    color: var(--brand-primary);
    font-weight: 850;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-more-row-icon,
  .mobile-more .theme-toggle .app-nav-icon {
    display: grid;
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    place-items: center;
    border-radius: 11px;
    background: color-mix(in srgb, var(--brand-accent) 22%, var(--brand-surface));
    color: var(--brand-primary);
  }

  .mobile-more-row-icon svg,
  .mobile-more .theme-toggle .app-nav-icon svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.9;
  }

  .mobile-more-row-label {
    flex: 1 1 auto;
    min-width: 0;
  }

  .mobile-more-chevron {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    margin-left: auto;
    fill: none;
    stroke: var(--brand-muted);
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
  }

  .mobile-more-row:hover,
  .mobile-more-company.is-switchable:hover,
  .mobile-more .theme-toggle:hover,
  .mobile-more .theme-toggle[aria-expanded="true"] {
    background: color-mix(in srgb, var(--brand-secondary) 10%, var(--brand-surface));
  }

  .mobile-more-row:focus-visible,
  .mobile-more-company.is-switchable:focus-visible,
  .mobile-more .theme-toggle:focus-visible {
    outline: 2px solid var(--brand-primary);
    outline-offset: -3px;
  }

  .mobile-more-row[aria-current="page"] {
    background: color-mix(in srgb, var(--brand-accent) 16%, var(--brand-surface));
    color: var(--brand-primary);
    font-weight: 850;
  }

  .mobile-more-row[aria-current="page"] .mobile-more-row-icon {
    background: var(--brand-primary);
    color: var(--brand-surface);
  }

  .mobile-more-logout {
    color: #b42318;
  }

  .mobile-more-logout .mobile-more-row-icon {
    background: #fdecea;
    color: #b42318;
  }

  /* Com a tela Mais aberta, so o Mais aparece como aba atual. */
  .app-shell.mobile-more-open .mobile-bottom-nav-item.is-active:not(.mobile-bottom-nav-more) {
    color: var(--brand-muted);
    font-weight: 750;
  }

  .app-shell.mobile-more-open .mobile-bottom-nav-item.is-active:not(.mobile-bottom-nav-more) .mobile-bottom-nav-icon {
    background: transparent;
  }

  /* A tela Cadastros/Mais ocupa toda a area de conteudo. Nenhum FAB da tela
     que ficou por baixo pode continuar visivel ou interceptar toques nela. */
  :root[data-app-experience="native"] .app-shell.mobile-more-open :is(
    .app-fab,
    .calendar-action-primary,
    .cash-nd-fab,
    .clinical-app-fab
  ) {
    visibility: hidden;
    pointer-events: none;
  }

  /* Toast acima da bottom nav em qualquer tela do app (Agenda, Caixa e
     Relacionamento mantem as proprias regras, mais especificas: :where()
     deixa esta com especificidade minima). O toast vive no body, fora do
     shell, por isso usa a altura nominal da nav + safe area. */
  :where(body[data-mobile-app-mode]:has(.app-shell.has-mobile-app-shell)) > .app-toast {
    right: 12px !important;
    bottom: calc(64px + env(safe-area-inset-bottom, 0px) + 12px) !important;
    left: 12px;
    max-width: none !important;
  }

  /* Popovers de Cores/Notificacoes: cartao na largura da tela, dentro da
     faixa entre topbar e bottom nav (o top vem de placePopoverVertically). */
  .mobile-more .theme-popover {
    right: 12px !important;
    left: 12px !important;
    width: auto !important;
    z-index: 30;
  }
}

@media (max-width: 860px) and (prefers-reduced-motion: reduce) {
  .app-shell.has-mobile-app-shell .mobile-more:not([hidden]) {
    animation: none;
  }
}

/* ==========================================================================
   D17 - Entrada do Gestao com a apresentacao do app nativo
   (mobile/src/screens/gestao/gestao-header.tsx + components/ui/bottom-nav.tsx).
   So sob html[data-app-experience="native"] (celular/tablet, ver
   assets/js/app-experience.js) e no shell mobile de app (ate 860px):
   - topbar = cabecalho de marca compacto: logo, empresa atual (abre o
     "Trocar empresa" de sempre quando ha 2+), privacidade e avatar que abre
     a folha "Conta e opcoes" (components.js);
   - o olho de privacidade sai do cabecalho da pagina para o do app;
   - barra inferior solida, nos tokens do app.
   Fora desse modo os blocos novos da topbar nao existem visualmente.
   ========================================================================== */
.mobile-app-topbar-company,
.mobile-app-topbar-actions {
  display: none;
}

@media (max-width: 860px) {
  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell {
    background: var(--ah-canvas);
  }

  :root[data-app-experience="native"] body[data-mobile-app-mode] .app-shell.has-mobile-app-shell .app-top-bar,
  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .app-top-bar {
    border-radius: 0 0 var(--ah-radius-header) var(--ah-radius-header);
    background: var(--ah-brand-gradient);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    box-shadow: none;
    padding-top: env(safe-area-inset-top, 0px);
  }

  :root[data-app-experience="native"] body[data-mobile-app-mode] .app-shell.has-mobile-app-shell .mobile-app-topbar,
  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-app-topbar {
    justify-content: flex-start;
    gap: 10px;
    min-height: 0;
    border-bottom: 0;
    background: transparent;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    color: #FFFFFF;
    padding:
      4px
      calc(env(safe-area-inset-right, 0px) + var(--ah-gutter))
      16px
      calc(env(safe-area-inset-left, 0px) + var(--ah-gutter));
  }

  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-app-topbar .app-logo-full {
    min-height: 0;
    gap: 0;
  }

  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-app-topbar .app-logo img {
    width: 36px;
    height: 36px;
    flex-basis: 36px;
    border-radius: 10px;
  }

  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-app-topbar .app-logo-wordmark {
    display: none;
  }

  /* Telas abertas pelo Mais: "voltar" no lugar do logo. */
  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-app-topbar.has-back .app-logo-full {
    display: none;
  }

  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-app-back {
    margin-left: -8px;
    color: var(--ah-neon-ice);
    font-size: 13px;
  }

  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-app-back:hover {
    background: rgba(255, 255, 255, 0.07);
  }

  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-app-back:focus-visible {
    outline-color: var(--ah-neon-ice);
  }

  /* Empresa atual (pilula clara quando troca de empresa e permitida). */
  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-app-topbar-company {
    display: grid;
    flex: 1 1 auto;
    gap: 1px;
    min-width: 0;
    min-height: 48px;
    border: 0;
    border-radius: var(--ah-radius-control);
    background: transparent;
    color: #FFFFFF;
    font: inherit;
    padding: 6px 10px;
    text-align: left;
    -webkit-tap-highlight-color: transparent;
  }

  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-app-topbar-company.is-switchable {
    background: rgba(255, 255, 255, 0.07);
    cursor: pointer;
  }

  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-app-topbar-company.is-switchable:active {
    opacity: 0.76;
  }

  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-app-topbar-company:focus-visible {
    outline: 2px solid var(--ah-neon-ice);
    outline-offset: 2px;
  }

  :root[data-app-experience="native"] .mobile-app-topbar-company-overline {
    color: var(--ah-neon-ice);
    font-size: 9px;
    font-weight: 900;
    letter-spacing: 0.14em;
    line-height: 13px;
    text-transform: uppercase;
  }

  :root[data-app-experience="native"] .mobile-app-topbar-company-line {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
  }

  :root[data-app-experience="native"] .mobile-app-topbar-company-name {
    overflow: hidden;
    color: #FFFFFF;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.012em;
    line-height: 22px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  :root[data-app-experience="native"] .mobile-app-topbar-company-chevron {
    width: 16px;
    height: 16px;
    flex: 0 0 16px;
    fill: none;
    stroke: var(--ah-neon-ice);
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  :root[data-app-experience="native"] .mobile-app-topbar-company-role {
    overflow: hidden;
    color: var(--ah-on-brand-muted);
    font-size: 12px;
    font-weight: 500;
    line-height: 17px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-app-topbar.has-back .mobile-app-topbar-company {
    padding-left: 6px;
  }

  /* Privacidade + conta. */
  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-app-topbar-actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 8px;
  }

  :root[data-app-experience="native"] .mobile-app-topbar-actions .privacy-toggle {
    width: 40px;
    min-width: 40px;
    height: 40px;
    min-height: 40px;
    border: 1px solid rgba(84, 242, 242, 0.35);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    box-shadow: none;
    color: var(--ah-neon-ice);
    padding: 0;
  }

  :root[data-app-experience="native"] .mobile-app-topbar-actions .privacy-toggle[aria-pressed="true"] {
    border-color: var(--ah-neon-ice);
    background: var(--ah-neon-ice);
    box-shadow: 0 0 0 3px rgba(84, 242, 242, 0.22);
    color: var(--ah-evergreen);
  }

  /* Tooltip de hover nao existe no toque (e passaria do cabecalho). */
  :root[data-app-experience="native"] .mobile-app-topbar-actions .privacy-toggle::after,
  :root[data-app-experience="native"] .mobile-app-topbar-actions .privacy-toggle::before {
    display: none;
  }

  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-app-topbar-account {
    display: inline-grid;
    place-items: center;
    border: 1.5px solid rgba(84, 242, 242, 0.35);
    border-radius: 999px;
    background: transparent;
    cursor: pointer;
    padding: 2px;
    -webkit-tap-highlight-color: transparent;
  }

  :root[data-app-experience="native"] .mobile-app-topbar-account .app-avatar {
    width: 40px;
    height: 40px;
    font-size: 15px;
  }

  :root[data-app-experience="native"] .mobile-app-topbar-account:active {
    opacity: 0.76;
  }

  :root[data-app-experience="native"] .mobile-app-topbar-account:focus-visible {
    outline: 2px solid var(--ah-neon-ice);
    outline-offset: 2px;
  }

  /* O olho de privacidade vive no cabecalho do app. */
  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .app-main [data-privacy-toggle] {
    display: none;
  }

  /* ---------- Barra inferior (BottomNav do app) ---------- */

  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-bottom-nav {
    border-top: 1px solid var(--ah-line);
    background: var(--ah-surface);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    box-shadow: var(--ah-shadow-nav);
  }

  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-bottom-nav-item {
    color: var(--ah-muted);
    font-size: 11px;
    font-weight: 600;
  }

  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-bottom-nav-item.is-active,
  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-bottom-nav-more[aria-expanded="true"] {
    color: var(--ah-evergreen);
    font-weight: 800;
  }

  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-bottom-nav-item.is-active .mobile-bottom-nav-icon,
  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-bottom-nav-more[aria-expanded="true"] .mobile-bottom-nav-icon {
    background: var(--ah-accent-soft);
  }

  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-bottom-nav-item:active {
    opacity: 0.76;
  }
}

/* ==========================================================================
   D17-B - Shell de app em tablet (iPad em retrato e paisagem).
   No modo app o Gestao fica no shell de app em qualquer largura (ver o
   "tier de app" em assets/js/app-experience.js). Em telas largas: barra
   inferior com os itens agrupados no centro e conteudo do Dashboard e da
   Agenda com largura de leitura, sem esticar cards. Limites em "em" de
   proposito (ficam fora do tier de app). Desktop nao e afetado.
   ========================================================================== */
:root[data-app-experience="native"] .app-shell.has-mobile-app-shell .app-main:has(.dashboard-content),
:root[data-app-experience="native"] .app-shell.has-mobile-app-shell .app-main:has(.calendar-shell) {
  padding-right: calc(var(--ah-gutter) + env(safe-area-inset-right, 0px));
  padding-left: calc(var(--ah-gutter) + env(safe-area-inset-left, 0px));
}

@media (min-width: 40em) {
  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-bottom-nav {
    padding-right: max(env(safe-area-inset-right, 0px), calc((100% - 640px) / 2));
    padding-left: max(env(safe-area-inset-left, 0px), calc((100% - 640px) / 2));
  }
}

@media (min-width: 64em) {
  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .app-main:has(.dashboard-content),
  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .app-main:has(.calendar-shell) {
    padding-right: max(calc(var(--ah-gutter) + env(safe-area-inset-right, 0px)), calc((100% - 960px) / 2));
    padding-left: max(calc(var(--ah-gutter) + env(safe-area-inset-left, 0px)), calc((100% - 960px) / 2));
  }
}

/* ==========================================================================
   D17-E - "Trocar empresa" no modo app (html[data-app-experience="native"]):
   folha inferior do app (BottomSheet) com os cards da Selecao de empresa do
   app nativo (company-select-screen.tsx); iPad (>= 40em): dialogo central.
   A troca continua sendo a de sempre (bindCompanySwitch). Desktop: nada muda.
   ========================================================================== */
:root[data-app-experience="native"] .modal.app-company-switch.is-open {
  z-index: 1300;
  align-items: flex-end;
  justify-content: center;
  background: var(--ah-overlay);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  padding: 0;
  animation: appCompanySwitchFade 0.22s ease-out both;
}

:root[data-app-experience="native"] .app-company-switch-panel {
  display: flex;
  width: 100%;
  max-width: 640px;
  max-height: calc(100dvh - env(safe-area-inset-top, 0px) - 16px);
  min-height: 0;
  flex-direction: column;
  border-radius: 28px 28px 0 0;
  background: var(--ah-surface);
  box-shadow: var(--ah-shadow-sheet);
  color: var(--ah-ink);
  padding: 10px 0 0;
  animation: appCompanySwitchUp 0.22s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

:root[data-app-experience="native"] .app-company-switch-panel:focus {
  outline: none;
}

:root[data-app-experience="native"] .app-company-switch-panel :is(h2, p) {
  margin: 0;
}

:root[data-app-experience="native"] .app-company-switch-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 0 var(--ah-gutter);
}

:root[data-app-experience="native"] .app-company-switch-heading {
  display: grid;
  flex: 1 1 auto;
  min-width: 0;
  gap: 2px;
}

:root[data-app-experience="native"] .app-company-switch-heading h2 {
  color: var(--ah-ink);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.3px;
  line-height: 26px;
}

:root[data-app-experience="native"] .app-company-switch-heading p {
  color: var(--ah-muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 17px;
}

:root[data-app-experience="native"] .app-company-switch-close {
  position: relative;
  display: inline-grid;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--ah-line);
  border-radius: 999px;
  background: var(--ah-surface);
  color: var(--ah-evergreen);
  cursor: pointer;
  padding: 0;
}

:root[data-app-experience="native"] .app-company-switch-close::after {
  position: absolute;
  inset: -4px;
  content: "";
}

:root[data-app-experience="native"] .app-company-switch-close svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

:root[data-app-experience="native"] .app-company-switch-count {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ah-muted);
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
  padding: 16px var(--ah-gutter) 12px;
}

:root[data-app-experience="native"] .app-company-switch-count svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

:root[data-app-experience="native"] .app-company-switch-body {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 4px var(--ah-gutter) calc(16px + env(safe-area-inset-bottom, 0px));
}

:root[data-app-experience="native"] .app-company-switch-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

:root[data-app-experience="native"] .app-company-switch-card {
  display: flex;
  width: 100%;
  min-height: 84px;
  align-items: center;
  gap: 16px;
  border: 1px solid var(--ah-line);
  border-radius: 20px;
  background: var(--ah-surface);
  box-shadow: var(--ah-shadow-sm);
  color: var(--ah-ink);
  cursor: pointer;
  font: inherit;
  padding: 16px;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

:root[data-app-experience="native"] .app-company-switch-card.is-current {
  border-color: var(--ah-pacific);
  background: var(--ah-selected);
}

:root[data-app-experience="native"] .app-company-switch-card:not(:disabled):active {
  opacity: 0.76;
  transform: scale(0.98);
}

:root[data-app-experience="native"] .app-company-switch-card:disabled {
  cursor: default;
  opacity: 0.45;
}

:root[data-app-experience="native"] .app-company-switch-card.is-loading {
  border: 1.5px solid var(--ah-evergreen);
  opacity: 1;
}

:root[data-app-experience="native"] .app-company-switch-card:focus-visible,
:root[data-app-experience="native"] .app-company-switch-close:focus-visible {
  outline: 2px solid var(--ah-pacific);
  outline-offset: 2px;
}

:root[data-app-experience="native"] .app-company-switch-avatar {
  display: inline-grid;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 999px;
  background: var(--ah-accent-soft);
  color: var(--ah-evergreen);
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

:root[data-app-experience="native"] .app-company-switch-card:is(.is-current, .is-loading) .app-company-switch-avatar {
  background: var(--ah-evergreen);
  color: var(--ah-neon-ice);
}

:root[data-app-experience="native"] .app-company-switch-copy {
  display: grid;
  flex: 1 1 auto;
  min-width: 0;
  gap: 6px;
}

:root[data-app-experience="native"] .app-company-switch-name {
  display: -webkit-box;
  overflow: hidden;
  color: var(--ah-ink);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.2px;
  line-height: 22px;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

:root[data-app-experience="native"] .app-company-switch-meta {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

:root[data-app-experience="native"] .app-company-switch-role {
  display: inline-flex;
  min-width: 0;
  flex: 0 1 auto;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--ah-line);
  border-radius: 999px;
  background: var(--ah-surface-muted);
  color: var(--ah-evergreen-soft);
  font-size: 12px;
  font-weight: 700;
  line-height: 17px;
  padding: 2px 8px;
}

:root[data-app-experience="native"] .app-company-switch-role > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

:root[data-app-experience="native"] .app-company-switch-role svg {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

:root[data-app-experience="native"] .app-company-switch-segment {
  color: var(--ah-muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 17px;
}

:root[data-app-experience="native"] .app-company-switch-trailing {
  display: flex;
  min-width: 32px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: flex-end;
}

:root[data-app-experience="native"] .app-company-switch-badge {
  border-radius: 999px;
  background: var(--ah-success-bg);
  color: var(--ah-success-ink);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.2px;
  line-height: 15px;
  padding: 5px 10px;
}

:root[data-app-experience="native"] .app-company-switch-chevron {
  display: inline-grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 999px;
  background: var(--ah-accent-soft);
  color: var(--ah-evergreen);
}

:root[data-app-experience="native"] .app-company-switch-chevron svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

:root[data-app-experience="native"] .app-company-switch-spinner {
  width: 22px;
  height: 22px;
  border: 2.4px solid var(--ah-evergreen);
  border-right-color: transparent;
  border-radius: 50%;
  animation: appCompanySwitchSpin 0.8s linear infinite;
}

/* iPad e telas largas: dialogo central proporcional (em: fora do clamp de app). */
@media (min-width: 40em) {
  :root[data-app-experience="native"] .modal.app-company-switch.is-open {
    align-items: center;
    padding: max(24px, env(safe-area-inset-top, 0px)) 24px max(24px, env(safe-area-inset-bottom, 0px));
  }

  :root[data-app-experience="native"] .app-company-switch-panel {
    max-width: 560px;
    max-height: min(720px, calc(100dvh - 48px));
    border: 1px solid var(--ah-line);
    border-radius: 28px;
    box-shadow: 0 24px 64px rgba(4, 42, 43, 0.30), 0 2px 6px rgba(4, 42, 43, 0.08);
    padding-top: 24px;
    animation-name: appCompanySwitchIn;
  }

  :root[data-app-experience="native"] .app-company-switch-panel > .app-sheet-handle {
    display: none;
  }

  :root[data-app-experience="native"] .app-company-switch-body {
    padding-bottom: 24px;
  }
}

@keyframes appCompanySwitchFade {
  from {
    background-color: transparent;
  }
}

@keyframes appCompanySwitchUp {
  from {
    transform: translateY(100%);
  }
}

@keyframes appCompanySwitchIn {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
}

@keyframes appCompanySwitchSpin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  :root[data-app-experience="native"] :is(.modal.app-company-switch.is-open, .app-company-switch-panel) {
    animation: none;
  }
}

/* Etapa 4 (Saude): barra compacta para 6+ destinos (como a BottomNav nativa):
   rotulo 10, pilula 40 e metade do peso extra dos rotulos longos. Desde o
   ajuste de navegacao da Saude nenhuma barra chega a 6 (Relacionamento foi
   para Cadastros); a regra fica para o limite. Sem efeito com 5 destinos. */
@media (max-width: 860px) {
  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-bottom-nav.is-compact .mobile-bottom-nav-icon {
    width: 40px;
  }

  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-bottom-nav.is-compact .mobile-bottom-nav-label {
    font-size: 10px;
    letter-spacing: -0.2px;
  }

  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-bottom-nav.is-compact .mobile-bottom-nav-item[data-mobile-nav="relacionamento"] {
    flex-grow: 1.3;
  }

  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-bottom-nav.is-compact .mobile-bottom-nav-item[data-mobile-nav="prontuarios"] {
    flex-grow: 1.15;
  }
}

/* Saude no modo app: 5 destinos com o espacamento normal (Dashboard | Agenda |
   Prontuarios | Caixa | Cadastros). Prontuarios tem o peso 1.3 do app nativo e
   "Cadastros" e o botao do "Mais" com o icone de pasta (traco, nao pontos). */
@media (max-width: 860px) {
  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-bottom-nav:not(.is-compact) .mobile-bottom-nav-item[data-mobile-nav="prontuarios"] {
    flex-grow: 1.3;
  }

  :root[data-app-experience="native"] .app-shell.has-mobile-app-shell .mobile-bottom-nav-more[data-mobile-more-kind="cadastros"] .mobile-bottom-nav-icon svg {
    fill: none;
    stroke: currentColor;
  }
}
