/* Mantém o cabeçalho alinhado entre telas com e sem barra de rolagem clássica. */
:root:has(.sistema-header.has-profile) {
  scrollbar-gutter: stable;
}

/* A página não deve alterar a tipografia nem as medidas do menu compartilhado. */
.sistema-header.has-profile {
  font-family: system-ui, sans-serif;
  line-height: 1.25;
}

@media screen and (scripting: enabled) {
  /* Reserva o espaço do seletor desde a primeira renderização. */
  .sistema-header.has-profile .theme-selector.theme-selector[hidden] {
    display: block;
    visibility: hidden;
  }
}

.has-profile .profile-copy .profile-profession {
  display: block;
  max-width: 11rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .76rem;
  font-weight: 400;
}

.sistema-header.has-profile .profile-menu {
  box-sizing: border-box;
  width: min(23rem, calc(100vw - 2rem));
  max-width: calc(100vw - 2rem);
  padding: .7rem;
  border-radius: 1.2rem;
  background: linear-gradient(135deg, var(--color-surface-default, #fffcf5), var(--color-surface-soft, #f9f2e4));
  box-shadow: var(--shadow-surface, 0 8px 28px rgb(69 47 14 / 22%));
  color: var(--color-text-primary, #233833);
  text-align: start;
}

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

.has-profile .profile-menu .profile-menu-heading {
  padding: .3rem .25rem .85rem;
  grid-template-columns: 2.8rem minmax(0, 1fr);
  border: 0;
}

.has-profile .profile-menu-heading .profile-menu-avatar {
  width: 2.8rem;
  height: 2.8rem;
  font-size: 1.1rem;
}

.has-profile .profile-menu-heading > strong {
  font: 700 1rem/1.3 var(--font-body, sans-serif);
  white-space: normal;
  overflow-wrap: anywhere;
}

.has-profile .profile-menu-heading .menu-perfil-metadados {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .2rem .65rem;
  grid-column: 2;
  grid-row: 2;
  white-space: normal;
}

.menu-perfil-metadados span {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.menu-perfil-icone {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.menu-perfil-metadados .menu-perfil-icone {
  width: .85rem;
  height: .85rem;
}

.menu-perfil-contexto {
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: .65rem .8rem;
  margin-bottom: .6rem;
  border: 1px solid var(--color-border-default, #c9a55f);
  border-radius: .95rem;
  background: linear-gradient(110deg, var(--color-surface-default, #fffcf5), var(--color-warning-surface, #f8e9c9));
  font-size: .8rem;
}

.menu-perfil-contexto strong {
  display: block;
  font-size: 1.1rem;
  line-height: 1.35;
}

.menu-perfil-simbolo {
  display: grid;
  place-items: center;
  width: 2.65rem;
  height: 2.65rem;
  border-radius: .7rem;
  background: var(--color-button-background, #104d46);
  color: #fff5dd;
}

.menu-perfil-simbolo svg {
  width: 1.65rem;
  height: 1.65rem;
}

.has-profile [data-alternar-perfil] button {
  display: flex;
  align-items: center;
  gap: .7rem;
  width: 100%;
  padding: .65rem .9rem;
  min-height: 2.75rem;
  margin-bottom: .55rem;
  border: 1px solid var(--color-button-border, #bd9247);
  border-radius: 10px;
  background: var(--color-button-background, #104d46);
  color: var(--color-text-on-solid, #fffdf8);
  font: 650 .95rem/1.35 system-ui, sans-serif;
  text-align: start;
  white-space: normal;
  cursor: pointer;
}

.has-profile [data-alternar-perfil] button:hover:not([aria-disabled="true"]) {
  background: var(--color-button-hover, #19655a);
}

.has-profile [data-alternar-perfil] button[aria-disabled="true"] {
  cursor: wait;
  opacity: .68;
}

.has-profile [data-alternar-perfil] button svg {
  flex-shrink: 0;
}

.has-profile [data-alternar-perfil] button svg:last-child {
  margin-inline-start: auto;
  width: 1rem;
}

.has-profile .profile-menu a:not([hidden]),
.has-profile .profile-sign-out {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: .85rem;
  min-height: 2.6rem;
  padding: .5rem .8rem;
  color: var(--color-text-primary, #233833);
  font: 600 .93rem/1.3 var(--font-body, sans-serif);
}

.has-profile .profile-menu .menu-perfil-inicio {
  margin-top: .45rem;
  padding-top: .8rem;
  border-top: 1px solid var(--color-border-default, #c9a55f);
  border-radius: 0;
}

.has-profile .profile-sign-out svg {
  color: var(--color-error, #a53023);
}

.has-profile .profile-menu :is(a, button, summary):focus-visible {
  outline: 2px solid var(--color-focus, #8d621e);
  outline-offset: -2px;
}

@media screen {
  :root[data-theme="dark"] .sistema-header.has-profile .profile-menu {
    --color-surface-hover: var(--color-surface-elevated-soft, #323f4b);
    background: var(--color-surface-elevated, #28323d);
    border-color: var(--color-border-default);
    box-shadow: var(--shadow-elevated);
  }

  :root[data-theme="dark"] .has-profile .profile-menu-heading > strong {
    color: var(--color-text-primary);
  }

  :root[data-theme="dark"] .has-profile .menu-perfil-contexto {
    background: var(--color-surface-elevated-soft, #323f4b);
    color: var(--color-text-secondary);
  }

  :root[data-theme="dark"] .has-profile .menu-perfil-contexto strong {
    color: var(--color-text-primary);
  }

  :root[data-theme="dark"] .has-profile .menu-perfil-simbolo {
    color: var(--color-accent-control);
  }
}
