/* CourtesyBox F55-R32 — design system transversal do Backoffice.
   Objetivo: o cabeçalho de cada menu deve parecer parte da mesma aplicação,
   sem alterar a lógica ou os conteúdos funcionais das páginas. */
:root{
  --cb-page-title-size:clamp(1.85rem,2.2vw,2.25rem);
  --cb-page-eyebrow-size:.66rem;
  --cb-page-subtitle-size:.86rem;
  --cb-page-action-height:2.5rem;
  --cb-page-radius:.7rem;
  --cb-page-gap:.75rem;
}

/* Título principal: uma única escala/peso em todos os menus. */
main h1.font-display,
main .cb-page-title{
  font-size:var(--cb-page-title-size)!important;
  line-height:.98!important;
  font-weight:800!important;
  letter-spacing:-.025em!important;
  text-transform:uppercase!important;
  margin:0!important;
}

/* Cabeçalho canónico. Funciona com as páginas já existentes e com as novas. */
main [data-testid$="-page"] > div:first-child:has(h1.font-display),
main .cb-page-header,
main .space-y-4 > div:first-child:has(h1.font-display),
main .space-y-5 > div:first-child:has(h1.font-display),
main .space-y-6 > div:first-child:has(h1.font-display){
  min-height:4.6rem;
  padding:.15rem 0 .4rem;
  align-items:flex-end!important;
  gap:1rem!important;
}

main .cb-page-heading{min-width:0;}

/* Eyebrow / secção. */
main [data-testid$="-page"] > div:first-child:has(h1.font-display) > div:first-child > .font-mono.uppercase.text-primary,
main .cb-page-eyebrow{
  display:block;
  margin:0 0 .42rem!important;
  font-size:var(--cb-page-eyebrow-size)!important;
  line-height:1.1!important;
  font-weight:700!important;
  letter-spacing:.28em!important;
  color:hsl(var(--primary))!important;
}

/* Texto de apoio imediatamente ligado ao título. */
main .cb-page-subtitle,
main h1.font-display + p,
main h1.font-display + .text-sm,
main h1.font-display ~ p.text-sm{
  margin-top:.45rem!important;
  font-size:var(--cb-page-subtitle-size)!important;
  line-height:1.35!important;
  color:#8fa4b8!important;
  max-width:76rem;
}

/* Ações de topo: mesma altura, raio e densidade. As cores/variantes existentes permanecem. */
main [data-testid$="-page"] > div:first-child:has(h1.font-display) > div:last-child > button,
main [data-testid$="-page"] > div:first-child:has(h1.font-display) > div:last-child > a,
main .cb-page-header > div:last-child > button,
main .cb-page-header > div:last-child > a,
main .space-y-4 > div:first-child:has(h1.font-display) > div:last-child > button,
main .space-y-4 > div:first-child:has(h1.font-display) > div:last-child > a,
main .space-y-5 > div:first-child:has(h1.font-display) > div:last-child > button,
main .space-y-5 > div:first-child:has(h1.font-display) > div:last-child > a{
  min-height:var(--cb-page-action-height)!important;
  border-radius:var(--cb-page-radius)!important;
  padding:.55rem .95rem!important;
  font-size:.78rem!important;
  line-height:1.05!important;
  font-weight:700!important;
  white-space:nowrap;
}

/* Tabs/filtros de topo: linguagem visual consistente e compacta. */
main [data-testid$="-page"] > div:nth-child(2) > button,
main [data-testid$="-page"] > div:nth-child(2) > a{
  border-radius:var(--cb-page-radius)!important;
}

/* Evita que o Dashboard seja visualmente de uma família tipográfica diferente. */
[data-testid="dashboard-page"] h1.font-display{font-size:var(--cb-page-title-size)!important;}
[data-testid="dashboard-page"] > div:first-child{min-height:4.6rem!important;}

/* Em resoluções desktop médias, não deixa o cabeçalho crescer desnecessariamente. */
@media (min-width:768px){
  main [data-testid$="-page"] > div:first-child:has(h1.font-display),
  main .cb-page-header{margin-bottom:.15rem;}
}

@media (max-width:767px){
  :root{--cb-page-title-size:1.75rem;--cb-page-action-height:2.35rem;}
  main [data-testid$="-page"] > div:first-child:has(h1.font-display),
  main .cb-page-header{min-height:0;align-items:flex-start!important;}
}


/* HF-TOPO5 2026-10-20 — O cabeçalho normalizado é identificado pelo próprio componente.
 * Corrige os nove módulos incluindo Folhas, Financeiro e Gestão Interna sem atingir modais, tabelas e App Cliente.
 * Este bloco tem precedência sobre as regras históricas de topografia por posição DOM.
 */
main [data-testid] .cbx-unified-header,
main [data-testid].cbx-unified-header {
  width: 100%;
  min-width: 0;
  min-height: 5.45rem;
  padding: .25rem 0 .55rem !important;
  margin: 0 0 .15rem !important;
  align-items: flex-end !important;
  gap: .75rem 1rem !important;
}
main [data-testid] .cbx-unified-heading {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  gap: .25rem;
  margin: 0 !important;
  padding: 0 !important;
}
main [data-testid] .cbx-unified-kicker {
  display: block;
  margin: 0 !important;
  font-family: Inter, system-ui, sans-serif !important;
  font-size: .625rem !important;
  line-height: 1.2 !important;
  font-weight: 750 !important;
  letter-spacing: .16em !important;
  text-transform: uppercase !important;
  color: #ef4444 !important;
}
main [data-testid] h1.cbx-unified-title {
  display: block;
  margin: 0 !important;
  padding: 0 !important;
  font-family: 'Barlow Condensed', 'Arial Narrow', sans-serif !important;
  font-size: clamp(1.65rem, 1.42rem + .53vw, 2.05rem) !important;
  line-height: 1.05 !important;
  font-weight: 800 !important;
  letter-spacing: 0 !important;
  text-transform: uppercase !important;
  color: #f8fafc !important;
  white-space: normal;
  overflow-wrap: normal;
}
main [data-testid] .cbx-unified-subtitle {
  margin: .1rem 0 0 !important;
  font-family: Inter, system-ui, sans-serif !important;
  font-size: .79rem !important;
  font-weight: 400 !important;
  line-height: 1.35 !important;
  letter-spacing: 0 !important;
  color: #8fa4b8 !important;
  max-width: 76rem;
}
/* O quadro de Folhas mantém os contadores e ações existentes no mesmo cabeçalho. */
main [data-testid="sheets-page"] > .cbx-unified-header {
  margin-top: 0 !important;
}
main [data-testid="sheets-page"] .cbx-unified-title-stack {
  align-items: flex-start !important;
  gap: .25rem !important;
}
/* Não alterar o alinhamento dos controlos da Agenda. */
main [data-testid="appointments-page"] .cb-agenda-nav {
  align-self: flex-end;
}
@media (max-width: 767px) {
  main [data-testid] .cbx-unified-header,
  main [data-testid].cbx-unified-header { min-height: 0; align-items: flex-start !important; }
  main [data-testid] h1.cbx-unified-title { font-size: clamp(1.5rem, 5.2vw, 1.75rem) !important; }
  main [data-testid="appointments-page"] .cb-agenda-nav { align-self: stretch; }
}
