/* =====================================================================
   NAIDE — Núcleo de Apoio à Inclusão e Disciplina Escolar
   Agrupamento de Escolas Álvaro Velho
   Sistema de identidade: "o percurso do processo"
   — evoca o registo formal do Diário da República (serifa para títulos,
     numeração de artigos) cruzado com um painel de caso vivo e humano.
   ===================================================================== */

:root {
  /* Paleta */
  --ink:            #16233F;   /* azul-tinta institucional — sidebar, títulos */
  --ink-soft:       #2C3F63;
  --paper:          #F5F4EF;   /* papel — fundo geral, quente e calmo */
  --paper-raised:   #FFFFFF;
  --line:           #DDD9CC;
  --steel:          #2F5D8A;   /* ação primária */
  --steel-dark:     #234C72;
  --gold:           #A9782E;   /* destaque — mérito, equidade */
  --teal:           #1E6E63;   /* positivo, concluído */
  --clay:           #9B4A3A;   /* urgente / sancionatório — terroso, não o laranja-Claude */
  --amber:          #C08A1E;   /* aviso */
  --text:           #1D2430;
  --text-mute:      #5B6373;
  --text-faint:     #8890A0;

  --font-display: 'Newsreader', 'Iowan Old Style', Georgia, serif;
  --font-body: 'IBM Plex Sans', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  --radius: 6px;
  --shadow-card: 0 1px 2px rgba(22,35,63,.06), 0 4px 16px rgba(22,35,63,.05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  background-image: linear-gradient(180deg, var(--paper) 0%, var(--paper) 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
}
/* Gradiente subtil por fase — mesmo "papel" de fundo, com uma vinheta ligeiramente
   tingida no topo do ecrã (funde-se com --paper antes dos 380px), só para ajudar a
   orientação visual de em que fase do fluxo NAIDE se está. Os cartões continuam
   brancos/opacos por cima, sem perda de legibilidade. */
body.fase-1 { background-image: linear-gradient(180deg, #EAEFF6 0%, var(--paper) 380px); }
body.fase-2 { background-image: linear-gradient(180deg, #F5F0E1 0%, var(--paper) 380px); }
body.fase-3 { background-image: linear-gradient(180deg, #FBF2DB 0%, var(--paper) 380px); }
body.fase-4 { background-image: linear-gradient(180deg, #E6F2EE 0%, var(--paper) 380px); }
body.fase-5 { background-image: linear-gradient(180deg, #E8E8F0 0%, var(--paper) 380px); }
body.fase-6 { background-image: linear-gradient(180deg, #F1E8E2 0%, var(--paper) 380px); }
body.fase-7 { background-image: linear-gradient(180deg, #E7EDE6 0%, var(--paper) 380px); }
h1, h2, h3, h4 { font-family: var(--font-display); color: var(--ink); margin: 0 0 .4em; font-weight: 600; }
h1 { font-size: 1.9rem; letter-spacing: -.01em; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.12rem; }
a { color: var(--steel); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--font-mono); }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------------------------------------------------------------------
   Layout geral
   --------------------------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--ink);
  color: #EDEEF3;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  padding: 22px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  position: relative;
}
.sidebar-toggle {
  position: absolute; top: 20px; right: -13px;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--ink); border: 1px solid rgba(255,255,255,.25); color: #CDD3E2;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: .9rem; line-height: 1; z-index: 6;
}
.sidebar-toggle:hover { background: var(--steel); color: #fff; }
.sidebar-brand .naide-logo {
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: .03em;
  color: #fff;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.sidebar-brand .naide-logo .dot { color: var(--gold); }
.sidebar-brand .naide-sub { font-size: .72rem; color: #A9B1C6; margin-top: 4px; line-height: 1.35; }

.logo-agrupamento-wrap {
  display: inline-block;
  background: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  margin-bottom: 12px;
  line-height: 0;
}
.logo-agrupamento { display: block; height: 42px; width: auto; max-width: 190px; }

.sidebar-nav { padding: 14px 10px; flex: 1; overflow-y: auto; }
.sidebar-nav details { margin: 0; }
.sidebar-nav summary {
  cursor: pointer; list-style: none; user-select: none;
  margin: 18px 10px 6px; display: flex; align-items: center; gap: 6px;
}
.sidebar-nav summary::-webkit-details-marker { display: none; }
.sidebar-nav summary::before {
  content: '▸'; display: inline-block; font-size: .62rem; color: #7C87A3;
  transition: transform .15s ease; flex-shrink: 0;
}
.sidebar-nav details[open] > summary::before { transform: rotate(90deg); }
.sidebar-nav .grupo-titulo {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .09em;
  color: #7C87A3; font-weight: 600;
}
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  color: #CDD3E2; padding: 9px 12px; border-radius: var(--radius);
  font-size: .89rem; margin-bottom: 2px;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.sidebar-nav a.ativo { background: var(--steel); color: #fff; }
.sidebar-nav .badge-count {
  margin-left: auto; background: var(--clay); color: #fff; font-size: .68rem;
  border-radius: 999px; padding: 1px 7px; font-weight: 600;
}
.sidebar-foot { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.1); font-size: .78rem; color: #8B93AB; }

/* ------------------------------------------------------------
   Menu lateral recolhido — só ícones, com transição suave.
   Ativado com a classe naide-sb-recolhida no <html> (ver footer.php).
   ------------------------------------------------------------ */
.sidebar, .sidebar-nav a, .sidebar-brand .naide-sub, .sidebar-brand .logo-texto,
.sidebar-nav .grupo-titulo, .sidebar-nav a .rotulo, .sidebar-foot, .logo-agrupamento, .logo-agrupamento-wrap {
  transition: width .18s ease, opacity .15s ease, padding .18s ease, height .18s ease;
}
html.naide-sb-recolhida .sidebar { width: 68px; }
html.naide-sb-recolhida .sidebar-brand { padding: 22px 10px 16px; display: flex; justify-content: center; }
html.naide-sb-recolhida .sidebar-brand .naide-sub,
html.naide-sb-recolhida .sidebar-brand .logo-texto,
html.naide-sb-recolhida .sidebar-nav .grupo-titulo,
html.naide-sb-recolhida .sidebar-nav a .rotulo,
html.naide-sb-recolhida .sidebar-foot { display: none; }
html.naide-sb-recolhida .sidebar-nav summary { justify-content: center; margin: 14px 0 4px; }
html.naide-sb-recolhida .sidebar-nav summary::before { display: none; }
html.naide-sb-recolhida .naide-logo { justify-content: center; }
html.naide-sb-recolhida .logo-agrupamento-wrap { padding: 5px 7px; margin-bottom: 8px; }
html.naide-sb-recolhida .logo-agrupamento { height: 26px; max-width: 40px; }
html.naide-sb-recolhida .sidebar-nav { padding: 14px 8px; }
html.naide-sb-recolhida .sidebar-nav a { justify-content: center; padding: 10px 0; }
html.naide-sb-recolhida .sidebar-nav a .icone { font-size: 1.05rem; }
html.naide-sb-recolhida .sidebar-toggle { transform: rotate(180deg); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 60px; background: var(--paper-raised); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  position: sticky; top: 0; z-index: 5;
}
.topbar .pagina-titulo { font-family: var(--font-display); font-size: 1.15rem; color: var(--ink); font-weight: 600; }
.topbar-user { display: flex; align-items: center; gap: 12px; font-size: .86rem; }
.topbar-user .avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--steel); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .78rem;
}
.topbar-user .perfil-tag { color: var(--text-mute); font-size: .76rem; }

.content { padding: 26px 28px 60px; max-width: 1320px; }

/* ---------------------------------------------------------------------
   Componentes
   --------------------------------------------------------------------- */
.card {
  background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-card); padding: 20px 22px; margin-bottom: 20px;
}
.card-titulo { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-titulo h3 { margin: 0; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .grid-3, .grid-4 { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 720px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } .sidebar { position: fixed; left: -260px; z-index: 40; transition: left .2s; } .sidebar.aberta { left: 0; } }

.kpi { padding: 18px 20px; }
.kpi .valor { font-family: var(--font-display); font-size: 2.1rem; color: var(--ink); font-weight: 700; line-height: 1; }
.kpi .rotulo { font-size: .8rem; color: var(--text-mute); margin-top: 6px; }
.kpi .tendencia { font-size: .74rem; margin-top: 8px; }
.kpi .tendencia.up { color: var(--clay); }
.kpi .tendencia.down { color: var(--teal); }

/* Botões */
.btn {
  display: inline-flex; align-items: center; gap: 7px; font-family: var(--font-body);
  font-size: .87rem; font-weight: 600; padding: 9px 16px; border-radius: var(--radius);
  border: 1px solid transparent; cursor: pointer; background: var(--steel); color: #fff;
}
.btn:hover { background: #244c72; text-decoration: none; }
.btn.btn-outline { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.btn-outline:hover { background: var(--paper); }
.btn.btn-clay { background: var(--clay); }
.btn.btn-teal { background: var(--teal); }
.btn.btn-gold { background: var(--gold); }
.btn.btn-danger { background: var(--clay); }
.btn.btn-danger:hover { background: #7d3c2e; }
.btn.btn-sm { padding: 5px 11px; font-size: .78rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* Formulários */
label { display: block; font-size: .82rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }
.campo { margin-bottom: 16px; }
.ajuda { font-size: .76rem; color: var(--text-faint); margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=time],
input[type=number], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius);
  font-family: var(--font-body); font-size: .89rem; background: #fff; color: var(--text);
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--steel); }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; }
legend { font-family: var(--font-display); font-weight: 600; color: var(--ink); padding: 0 6px; }
.checklist { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.checklist label { display: flex; align-items: center; gap: 7px; font-weight: 400; font-size: .87rem; color: var(--text); }
.checklist input { width: auto; }

/* Tabelas */
table.tabela { width: 100%; border-collapse: collapse; font-size: .87rem; }
table.tabela th, table.tabela td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
table.tabela th { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-mute); font-weight: 600; }
table.tabela tr:hover td { background: #FAFAF6; }

/* Etiquetas de estado */
.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .72rem; font-weight: 600; }
.tag-aberto { background: #E4EBF3; color: var(--steel); }
.tag-instrucao { background: #F3E9D0; color: var(--amber); }
.tag-decidido { background: #E1EFEC; color: var(--teal); }
.tag-execucao { background: #EFE2DC; color: var(--clay); }
.tag-encerrado { background: #E9E9E4; color: var(--text-mute); }
.tag-recurso { background: #F3D9D5; color: var(--clay); }
.tag-corretiva { background: #E4EBF3; color: var(--steel); }
.tag-sancionatoria { background: #F3D9D5; color: var(--clay); }

/* Gravidade (fila da Fase II) */
.tag-grav-baixa { background: #E9E9E4; color: var(--text-mute); }
.tag-grav-media { background: #F3E9D0; color: var(--amber); }
.tag-grav-alta { background: #EFE2DC; color: var(--clay); }
.tag-grav-critica { background: #9B4A3A; color: #fff; }
.tag-cancelada { background: #E9E9E4; color: var(--text-faint); text-decoration: line-through; }
.ano-letivo-topbar { background: var(--paper); border: 1px solid var(--line); color: var(--ink-soft); font-weight: 600; }
.topbar-user a:hover .avatar { box-shadow: 0 0 0 2px var(--gold); }

/* Alertas / flash */
.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: .88rem; border-left: 4px solid; }
.alert-success { background: #E7F1EE; border-color: var(--teal); color: #164A41; }
.alert-error   { background: #F8E7E4; border-color: var(--clay); color: #6E2E22; }
.alert-warning { background: #FBF1DC; border-color: var(--amber); color: #6B4F0E; }
.alert-info    { background: #E7EEF6; border-color: var(--steel); color: #17395B; }

/* ---------------------------------------------------------------------
   Elemento-assinatura: corredor das 7 fases
   --------------------------------------------------------------------- */
.corredor-fases { display: flex; align-items: flex-start; gap: 0; margin: 6px 0 26px; overflow-x: auto; padding-bottom: 6px; }
.fase-etapa { flex: 1; min-width: 118px; text-align: center; position: relative; padding: 0 4px; }
.fase-etapa::before {
  content: ""; position: absolute; top: 17px; left: -50%; width: 100%; height: 2px; background: var(--line); z-index: 0;
}
.fase-etapa:first-child::before { display: none; }
.fase-etapa .num {
  width: 34px; height: 34px; border-radius: 50%; background: #fff; border: 2px solid var(--line);
  display: flex; align-items: center; justify-content: center; margin: 0 auto 8px; position: relative; z-index: 1;
  font-family: var(--font-display); font-weight: 700; color: var(--text-faint); font-size: .92rem;
}
.fase-etapa.concluida .num { background: var(--teal); border-color: var(--teal); color: #fff; }
.fase-etapa.concluida::before { background: var(--teal); }
.fase-etapa.atual .num { background: var(--steel); border-color: var(--steel); color: #fff; box-shadow: 0 0 0 4px #E4EBF3; }
.fase-etapa .rotulo { font-size: .72rem; color: var(--text-mute); line-height: 1.25; }
.fase-etapa.atual .rotulo { color: var(--ink); font-weight: 600; }

/* ---------------------------------------------------------------------
   Linha do tempo do aluno (histórico plurianual)
   --------------------------------------------------------------------- */
.timeline { position: relative; padding-left: 26px; }
.timeline::before { content:""; position: absolute; left: 7px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }
.timeline-item { position: relative; padding-bottom: 22px; }
.timeline-item::before {
  content: ""; position: absolute; left: -26px; top: 3px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--paper-raised); border: 2px solid var(--steel);
}
.timeline-item.sancionatoria::before { border-color: var(--clay); }
.timeline-item.encerrado::before { border-color: var(--teal); background: var(--teal); }
.timeline-item.cancelada { opacity: .55; }
.timeline-item.cancelada .titulo { text-decoration: line-through; }
.timeline-item.cancelada::before { border-color: var(--text-faint); }
.timeline-item.percurso-escolar { padding-bottom: 16px; opacity: .8; }
.timeline-item.percurso-escolar::before { border-style: dashed; border-color: var(--steel); background: transparent; width: 8px; height: 8px; }
.timeline-item.percurso-escolar .titulo { font-weight: 500; color: var(--steel); font-size: .88rem; }
.timeline-item.percurso-escolar .desc { font-size: .78rem; }
.timeline-item .data { font-size: .74rem; color: var(--text-faint); font-family: var(--font-mono); }
.timeline-item .titulo { font-weight: 600; color: var(--ink); margin: 2px 0; }
.timeline-item .desc { font-size: .85rem; color: var(--text-mute); }

/* Consulta da Lei 51/2012 */
.artigo-lei { border-left: 3px solid var(--gold); padding: 4px 0 4px 16px; margin-bottom: 18px; }
.artigo-lei .numero { font-family: var(--font-mono); color: var(--gold); font-size: .78rem; font-weight: 700; }
.artigo-lei h4 { margin: 2px 0 6px; }
.artigo-lei p { font-size: .87rem; color: var(--text); margin: 0; }

/* Login */
.login-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--ink) 0%, #1F3157 55%, var(--ink) 100%);
  padding: 20px;
}
.login-card { background: var(--paper-raised); border-radius: 10px; width: 100%; max-width: 400px; padding: 36px 34px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.logo-agrupamento-login { display: block; height: 56px; width: auto; margin: 0 auto 14px; }
.login-card .naide-logo { font-family: var(--font-display); font-size: 1.9rem; font-weight: 700; color: var(--ink); text-align: center; }
.login-card .naide-logo .dot { color: var(--gold); }
.login-card .subtitulo { text-align: center; color: var(--text-mute); font-size: .84rem; margin: 4px 0 26px; }
.divisor-ou { text-align: center; color: var(--text-faint); font-size: .78rem; margin: 16px 0; }

.print-only { display: none; }
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .content { padding: 0; max-width: none; }
  body { background: #fff; }
}
