/* ==========================================================================
   Menu Âncoras Sticky — assets/menu-ancoras.css
  Versão 1.1.0
   ========================================================================== */

/* Reset de box-model no escopo do componente */
.mas-menu-ancoras,
.mas-menu-ancoras *,
.mas-menu-ancoras *::before,
.mas-menu-ancoras *::after {
  box-sizing: border-box;
}

/* --------------------------------------------------------------------------
   Container principal — sticky
   -------------------------------------------------------------------------- */
.mas-menu-ancoras {
  position: sticky;
  top: var(--mas-sticky-top, 80px);
  z-index: 100;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
  max-width: 100%;
  /* Garante que não sobreponha elementos de z-index muito alto (ex.: modais) */
}

/* Oculta quando JS define hidden (sem âncoras na página) */
.mas-menu-ancoras[hidden] {
  display: none !important;
}

/* --------------------------------------------------------------------------
   Título
   -------------------------------------------------------------------------- */
.mas-menu-ancoras__title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94a3b8;
  margin-bottom: 0.5rem;
  line-height: 1;
}

/* --------------------------------------------------------------------------
   Navegação de páginas/dias
   -------------------------------------------------------------------------- */
.mas-menu-ancoras__pages,
.mas-menu-ancoras__drawer-pages {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.mas-menu-ancoras__pages {
  margin-bottom: 0.625rem;
}

.mas-menu-ancoras__pages a,
.mas-menu-ancoras__drawer-pages a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.2;
  color: #334155;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.mas-menu-ancoras__pages a:hover,
.mas-menu-ancoras__drawer-pages a:hover {
  color: #1e293b;
  background-color: #e2e8f0;
}

.mas-menu-ancoras__pages a.is-current-page,
.mas-menu-ancoras__drawer-pages a.is-current-page {
  background: #111827;
  border-color: #111827;
  color: #ffffff;
}

.mas-menu-ancoras__pages a:focus-visible,
.mas-menu-ancoras__drawer-pages a:focus-visible {
  outline: 2px solid #1d4ed8;
  outline-offset: 2px;
}

.mas-menu-ancoras__pages a:focus:not(:focus-visible),
.mas-menu-ancoras__drawer-pages a:focus:not(:focus-visible) {
  outline: none;
}

/* --------------------------------------------------------------------------
   Lista de links
   -------------------------------------------------------------------------- */
.mas-menu-ancoras__list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.625rem;
  list-style: none;
  padding: 0;
  margin: 0;
}

.mas-menu-ancoras__list li {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  position: relative; /* âncora para o dropdown do filho */
}

/* --------------------------------------------------------------------------
   Links
   -------------------------------------------------------------------------- */
.mas-menu-ancoras__list a {
  display: inline-block;
  font-size: 0.875rem;
  line-height: 1.5;
  color: #475569;
  text-decoration: none;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}

.mas-menu-ancoras__list a:hover {
  color: #1e293b;
  background-color: #f1f5f9;
}

/* --------------------------------------------------------------------------
   Link ativo (definido pelo JS via IntersectionObserver ou scroll)
   -------------------------------------------------------------------------- */
.mas-menu-ancoras__list a.is-active {
  color: #1d4ed8;
  border-bottom-color: #1d4ed8;
  font-weight: 600;
  background-color: #eff6ff;
}

/* Pai de um item ativo */
.mas-menu-ancoras__list a.is-parent-active {
  color: #1d4ed8;
  font-weight: 600;
}

/* Indicador de dropdown no link pai */
.mas-menu-ancoras__list li.has-children > a::after {
  content: ' ▾';
  font-size: 0.7em;
  opacity: 0.6;
}

/* --------------------------------------------------------------------------
   Sub-lista hierárquica no nav (desktop) — dropdown suspenso abaixo do pai
   -------------------------------------------------------------------------- */
.mas-menu-ancoras__sublist {
  /* Oculta sem display:none para permitir transition + delay no fechamento */
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  /* Fecha com delay de 150ms — dá tempo de mover o mouse para dentro do dropdown */
  transition: opacity 0.12s ease, visibility 0s linear 0.15s;

  position: absolute;
  top: 100%;   /* sem gap; padding-top cria o afastamento visual mantendo hover contínuo */
  left: 0;
  z-index: 110;
  min-width: 180px;
  list-style: none;
  padding: 8px 0 0.375rem; /* 8px de padding-top = afastamento visual do pai */
  margin: 0;
  background: transparent; /* fundo transparente no padding-top para não cortar sombra */
  white-space: nowrap;
  max-height: min(65vh, 560px);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

/* Card visível separado do padding de hover */
.mas-menu-ancoras__sublist::after {
  content: '';
  position: absolute;
  top: 8px;
  left: 0;
  right: 0;
  bottom: 0;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  z-index: -1;
}

/* Seta decorativa apontando para o pai */
.mas-menu-ancoras__sublist::before {
  content: '';
  position: absolute;
  top: 4px;
  left: 14px;
  width: 8px;
  height: 8px;
  background: #ffffff;
  border-left: 1px solid #e2e8f0;
  border-top: 1px solid #e2e8f0;
  transform: rotate(45deg);
  z-index: 1;
}

/* Abre ao hover/foco — sem delay na abertura, com delay apenas no fechamento */
.mas-menu-ancoras__list li.has-children:hover > .mas-menu-ancoras__sublist,
.mas-menu-ancoras__list li.has-children:focus-within > .mas-menu-ancoras__sublist {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transition: opacity 0.12s ease, visibility 0s linear 0s;
}

/* Remove separador › inline (não se aplica mais) */
.mas-menu-ancoras__sublist li::before {
  content: none;
}

.mas-menu-ancoras__sublist li {
  display: block;
  position: relative;
  z-index: 1;
}

.mas-menu-ancoras__sublist a {
  display: block;
  font-size: 0.8125rem;
  padding: 0.35rem 0.875rem;
  color: #475569;
  background-color: #ffffff;
  text-decoration: none;
  border-bottom: none;
  border-radius: 0;
  transition: color 0.12s ease, background-color 0.12s ease;
  white-space: nowrap;
}

.mas-menu-ancoras__sublist li:last-child > a {
  border-radius: 0 0 6px 6px;
}

.mas-menu-ancoras__sublist a:hover {
  color: #1e293b;
  background-color: #f1f5f9;
}

.mas-menu-ancoras__sublist a.is-active {
  color: #1d4ed8;
  font-weight: 600;
  background-color: #eff6ff;
}

.mas-menu-ancoras__sublist a:focus-visible {
  outline: 2px solid #1d4ed8;
  outline-offset: -2px;
}

.mas-menu-ancoras__sublist a:focus:not(:focus-visible) {
  outline: none;
}

/* --------------------------------------------------------------------------
   Acessibilidade — foco visível
   Não remove o outline; substitui por estilo mais integrado ao design.
   -------------------------------------------------------------------------- */
.mas-menu-ancoras__list a:focus-visible {
  outline: 2px solid #1d4ed8;
  outline-offset: 2px;
  border-radius: 4px;
}

/* Remove o outline padrão apenas quando :focus-visible está disponível */
.mas-menu-ancoras__list a:focus:not(:focus-visible) {
  outline: none;
}

/* --------------------------------------------------------------------------
   Botão hamburguer — oculto no desktop, visível no mobile
   -------------------------------------------------------------------------- */
.mas-menu-ancoras__toggle {
  display: none; /* exibido via media query abaixo */
  align-items: center;
  gap: 0.5rem;
  background: none;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 0.35rem 0.75rem 0.35rem 0.5rem;
  cursor: pointer;
  color: #475569;
  font-size: 0.875rem;
  line-height: 1.5;
  font-family: inherit;
}

.mas-menu-ancoras__toggle:hover {
  background-color: #f1f5f9;
  color: #1e293b;
}

.mas-menu-ancoras__toggle:focus-visible {
  outline: 2px solid #1d4ed8;
  outline-offset: 2px;
}

.mas-menu-ancoras__toggle:focus:not(:focus-visible) {
  outline: none;
}

/* Ícone hamburguer feito com CSS puro */
.mas-menu-ancoras__toggle-icon {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  position: relative;
  flex-shrink: 0;
}

.mas-menu-ancoras__toggle-icon::before,
.mas-menu-ancoras__toggle-icon::after {
  content: '';
  display: block;
  width: 100%;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  position: absolute;
  left: 0;
}

.mas-menu-ancoras__toggle-icon::before { top: -5px; }
.mas-menu-ancoras__toggle-icon::after  { top:  5px; }

/* --------------------------------------------------------------------------
   Overlay — fundo escurecido ao abrir a gaveta
   -------------------------------------------------------------------------- */
.mas-menu-ancoras__overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 998;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.mas-menu-ancoras__overlay.is-open {
  opacity: 1;
}

.mas-menu-ancoras__overlay[hidden] {
  display: none !important;
}

/* --------------------------------------------------------------------------
   Gaveta lateral (drawer)
   -------------------------------------------------------------------------- */
.mas-menu-ancoras__drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(300px, 85vw);
  background: #ffffff;
  z-index: 999;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 16px rgba(0, 0, 0, 0.12);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.mas-menu-ancoras__drawer.is-open {
  transform: translateX(0);
}

/* Cabeçalho da gaveta */
.mas-menu-ancoras__drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
}

.mas-menu-ancoras__drawer-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94a3b8;
  line-height: 1;
}

.mas-menu-ancoras__drawer-pages {
  padding: 0.75rem 1rem 0;
}

.mas-menu-ancoras__drawer-pages a {
  width: 100%;
  justify-content: flex-start;
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
}

/* Botão de fechar */
.mas-menu-ancoras__drawer-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: none;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  cursor: pointer;
  color: #64748b;
  font-size: 1.25rem;
  line-height: 1;
  font-family: inherit;
  flex-shrink: 0;
}

.mas-menu-ancoras__drawer-close:hover {
  background-color: #f1f5f9;
  color: #1e293b;
}

.mas-menu-ancoras__drawer-close:focus-visible {
  outline: 2px solid #1d4ed8;
  outline-offset: 2px;
}

.mas-menu-ancoras__drawer-close:focus:not(:focus-visible) {
  outline: none;
}

/* Lista de links na gaveta */
.mas-menu-ancoras__drawer-list {
  list-style: none;
  padding: 0.75rem 0;
  margin: 0;
  display: flex;
  flex-direction: column;
}

.mas-menu-ancoras__drawer-list li {
  display: block;
}

.mas-menu-ancoras__drawer-list a {
  display: block;
  padding: 0.625rem 1rem;
  font-size: 0.9375rem;
  color: #475569;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.mas-menu-ancoras__drawer-list a:hover {
  background-color: #f8fafc;
  color: #1e293b;
}

.mas-menu-ancoras__drawer-list a.is-active {
  color: #1d4ed8;
  border-left-color: #1d4ed8;
  font-weight: 600;
  background-color: #eff6ff;
}

/* Pai de um item ativo no drawer */
.mas-menu-ancoras__drawer-list a.is-parent-active {
  color: #1d4ed8;
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   Sub-lista hierárquica no drawer
   -------------------------------------------------------------------------- */
.mas-menu-ancoras__drawer-sublist {
  list-style: none;
  padding: 0;
  margin: 0;
}

.mas-menu-ancoras__drawer-sublist a {
  padding-left: 2rem; /* indentação visual de filho */
  font-size: 0.875rem;
  color: #64748b;
  border-left-color: transparent;
}

.mas-menu-ancoras__drawer-sublist a:hover {
  background-color: #f8fafc;
  color: #1e293b;
}

.mas-menu-ancoras__drawer-sublist a.is-active {
  color: #1d4ed8;
  border-left-color: #1d4ed8;
  font-weight: 600;
  background-color: #eff6ff;
}

/* Separador sutil antes do primeiro filho */
.mas-menu-ancoras__drawer-list li.has-children > a {
  border-bottom: 1px solid #f1f5f9;
}

.mas-menu-ancoras__drawer-list a:focus-visible {
  outline: 2px solid #1d4ed8;
  outline-offset: -2px;
}

.mas-menu-ancoras__drawer-list a:focus:not(:focus-visible) {
  outline: none;
}

/* --------------------------------------------------------------------------
   Mobile — hamburguer visível, lista inline oculta
   -------------------------------------------------------------------------- */
@media (max-width: 767px) {
  .mas-menu-ancoras {
    padding: 0;
    border: none;
    background: none;
    display: flex;
    align-items: center;
  }

  /* Oculta título e lista inline no mobile */
  .mas-menu-ancoras__title,
  .mas-menu-ancoras__list {
    display: none;
  }

  .mas-menu-ancoras__pages {
    display: none;
  }

  /* Exibe o botão hamburguer */
  .mas-menu-ancoras__toggle {
    display: flex;
  }
}

/* --------------------------------------------------------------------------
   Sem animação para quem prefere movimento reduzido
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .mas-menu-ancoras__drawer,
  .mas-menu-ancoras__overlay {
    transition: none;
  }
}
