*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* O atributo `hidden` deve sempre esconder, mesmo quando o elemento tem uma
   classe com display próprio (ex.: .btn-primary{display:inline-flex}). Sem isto,
   botões/elementos alternados via `el.hidden = true` continuavam visíveis. */
[hidden] { display: none !important; }

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: 'DM Sans', sans-serif;
  font-weight: 400;
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  /* Correção da faixa azul em ecrãs pequenos */
  max-width: 100vw;
  overflow-x: hidden; 
}

/* ---------- Variáveis globais ---------- */
:root {
  --primary:        #1a6fb5;
  --primary-hover:  #155d99;
  --primary-mid:    #3a9bd5;
  --primary-light:  #eaf5fc;

  --bg:             #eaf5fc;
  --surface:        #ffffff;
  --border:         #b8d9ef;
  --border-focus:   #3a9bd5;

  --text:           #1c2d3a;
  --text-muted:     #6b8fa8;
  --text-placeholder: #9cb8cf;

  --error:          #d64045;
  --error-bg:       #fdecea;
  --error-border:   #f5bcbc;

  --success:        #2a9d5c;
  --success-bg:     #e8f7ef;
  --success-border: #a8dfc1;

  --header-bg:      rgba(255,255,255,.72);
  --header-text:    #1c2d3a;

  --radius-sm:  8px;
  --radius-md:  14px;
  --radius-lg:  22px;

  --shadow-card: 0 20px 60px rgba(26,111,181,.14);
  --shadow-btn:  0 4px 20px rgba(26,111,181,.35);

  --transition: .25s cubic-bezier(.4,0,.2,1);
}

/* ---------- Background mesh ---------- */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(ellipse 70% 60% at 10% 20%, rgba(58,155,213,.18) 0%, transparent 70%),
    radial-gradient(ellipse 50% 50% at 90% 80%, rgba(26,111,181,.12) 0%, transparent 65%),
    linear-gradient(160deg, #daf0fb 0%, #eaf5fc 55%, #d6edf8 100%);
  pointer-events: none;
}

/* ---------- Header ---------- */
header {
  position: relative; 
  z-index: 10;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(180,220,245,.5);
  padding: 0 2.5rem;
  height: 64px;
  
  /* CSS Grid com 3 colunas para garantir o centro perfeito */
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
}

.header-left {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 1rem;
  min-width: 0;
}

.header-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-nav {
  width: 100%;
  display: flex;
  justify-content: center;
}

.header-nav ul {
  align-items: center;
  list-style: none;
  display: flex;
  gap: 0.75rem;
  padding: 0;
  margin: 0;
}

.header-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
  min-width: 0;
}

.btn-center {
  font-family: 'DM Sans', sans-serif;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  transition: var(--transition);
  background: var(--surface);
  color: var(--text-muted);
  justify-content: center; 
  text-decoration: none;
  white-space: nowrap;  
  align-items: center;
  padding: 0 1.2rem;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  height: 36px; 
}

.btn-center:hover {
  border-color: var(--border-focus);
  background: var(--primary-light);
  color: var(--primary);
}

.btn-center.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.btn-back-header {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  transition: var(--transition);
  background: var(--surface);
  color: var(--text-muted);
  justify-content: center;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  height: 36px;
  width: 36px;
}

.btn-back-header:hover {
  background: var(--primary-light);
  border-color: var(--border-focus);
  color: var(--primary);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: inherit;
}

.logo-mark {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--primary), var(--primary-mid));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.logo-mark svg { width: 18px; height: 18px; }

.logo-text {
  font-family: 'Playfair Display', serif;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--primary);
  letter-spacing: .04em;
}

.header-sub {
  font-size: .7rem;
  font-weight: 500;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ---------- Main ---------- */
main {
  flex: 1;
  position: relative; z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1rem;
}

/* ========================================================= */
/* RESPONSIVIDADE CORRIGIDA DO CABEÇALHO                     */
/* ========================================================= */

/* 1. Monitores HD (1360x768) até 1400px: Reduz botões e margens para não esconder elementos */
@media (max-width: 1400px) {
  header {
    padding: 0 1.5rem;
    gap: 0.5rem;
  }
  .header-left { gap: 0.5rem; }
  .header-right { gap: 0.5rem; }
  
  .header-nav ul { gap: 0.3rem; }
  .btn-center {
    padding: 0 0.6rem;
    font-size: 12px;
  }
}

/* 2. Tablets (1024px ou menos): Muda para Flexbox e joga menu para baixo */
@media (max-width: 1024px) {
  header {
    display: flex; /* Desliga o Grid nas telas menores para permitir a quebra de linha */
    height: auto;
    flex-wrap: wrap;
    padding: 1rem 1.5rem;
    justify-content: space-between;
  }
  .header-center {
    order: 3;
    width: 100%;
    margin-top: 0.75rem;
  }
  /* Menu na própria linha: centraliza e quebra em várias linhas se faltar espaço */
  .header-nav {
    justify-content: center;
  }
  .header-nav ul {
    flex-wrap: wrap;
    justify-content: center;
  }
  .header-sub {
    display: none;
  }
}

/* 3. Celulares (768px ou menos): chips do menu ocupam a largura e ajuste global */
@media (max-width: 768px) {
  header {
    padding: 1rem;
  }
  .btn-center {
    padding: 0 0.9rem;
    font-size: 13px;
  }
  .header-right .user-name,
  .header-right .user-role {
    display: none;
  }
}

@media (max-width: 480px) {
  main { padding: 1.5rem 1rem; }
}
