/* ===========================================================================
   PORTAL DO ESTUDANTE — sistema de design
   ---------------------------------------------------------------------------
   Mobile-first: o estilo base é o do telemóvel (é por aí que a maioria dos
   estudantes entra) e as media queries só acrescentam à medida que o ecrã
   cresce. Sem dependências externas — nada de CDN, nada de fontes remotas:
   o servidor pode não ter saída para a internet e os dados móveis são caros.
   Cores iguais às do SIGA (siga/principal.php).
   =========================================================================== */

:root {
    --primary: #1a3a5c;
    --primary-light: #2c5f8a;
    --primary-dark: #0f2440;
    --accent: #c9a84c;
    --accent-light: #e0c56a;

    --bg-body: #f0f2f5;
    --bg-card: #ffffff;
    --bg-suave: #f7f9fb;

    --text-primary: #2c3e50;
    --text-secondary: #6c757d;
    --border-color: #e0e4e8;

    --ok: #1e7a46;
    --ok-bg: #eaf7ef;
    --ok-borda: #b7e4c7;
    --erro: #a3282b;
    --erro-bg: #fdecea;
    --erro-borda: #f5c6cb;
    --aviso: #8a6d3b;
    --aviso-bg: #fcf8e3;
    --aviso-borda: #faebcc;
    --info: #1e5079;
    --info-bg: #eef4fa;
    --info-borda: #cfe0ef;

    --radius: 8px;
    --radius-sm: 5px;
    --sombra-sm: 0 1px 3px rgba(0, 0, 0, .08);
    --sombra-md: 0 4px 12px rgba(0, 0, 0, .10);
    --fonte: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--fonte);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-body);
}

a { color: var(--primary-light); }
a:hover { color: var(--primary); }

h1, h2, h3, h4 { margin: 0 0 12px; line-height: 1.3; color: var(--primary); }
h1 { font-size: 22px; }
h2 { font-size: 19px; }
h3 { font-size: 17px; }
h4 { font-size: 15px; }

p { margin: 0 0 12px; }

/* --------------------------------------------------------------- cabeçalho */

.topo {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: #fff;
    box-shadow: var(--sombra-md);
    position: sticky;
    top: 0;
    z-index: 40;
}

.topo__barra {
    max-width: 1100px;
    margin: 0 auto;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.topo__marca {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    font-size: 15px;
    min-width: 0;
}

.topo__logo {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid var(--accent);
    object-fit: cover;
    flex: 0 0 auto;
    background: #fff;
}

.topo__titulo { display: flex; flex-direction: column; min-width: 0; }
.topo__titulo strong { font-size: 15px; font-weight: 600; }
.topo__titulo span {
    font-size: 11px;
    font-weight: 400;
    opacity: .8;
    letter-spacing: .5px;
    text-transform: uppercase;
}

.topo__utilizador {
    margin-left: auto;
    text-align: right;
    font-size: 12px;
    line-height: 1.35;
    max-width: 45%;
    overflow: hidden;
}
.topo__utilizador strong { display: block; font-size: 13px; }
.topo__utilizador span { opacity: .8; }

/* Menu hamburguer sem JavaScript: checkbox escondido + label. */
.menu__interruptor { position: absolute; opacity: 0; pointer-events: none; }

.menu__botao {
    margin-left: auto;
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 40px;
    height: 36px;
    padding: 8px;
    border: 1px solid rgba(255, 255, 255, .35);
    border-radius: var(--radius-sm);
    cursor: pointer;
    flex: 0 0 auto;
}
.menu__botao span {
    display: block;
    height: 2px;
    background: #fff;
    border-radius: 2px;
}

.menu {
    display: none;
    background: var(--primary-dark);
    border-top: 1px solid rgba(255, 255, 255, .12);
}
.menu__interruptor:checked ~ .menu { display: block; }

.menu__lista {
    list-style: none;
    margin: 0;
    padding: 6px 0;
    max-width: 1100px;
    margin: 0 auto;
}

.menu__lista a {
    display: block;
    padding: 12px 18px;
    color: rgba(255, 255, 255, .88);
    text-decoration: none;
    font-size: 15px;
    border-left: 3px solid transparent;
}
.menu__lista a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.menu__lista a.activo {
    color: #fff;
    font-weight: 600;
    border-left-color: var(--accent);
    background: rgba(255, 255, 255, .07);
}
.menu__lista a.sair { color: var(--accent-light); }

/* ------------------------------------------------------------------ layout */

.conteudo {
    max-width: 1100px;
    margin: 0 auto;
    padding: 16px 14px 40px;
}

.pagina__cabecalho { margin-bottom: 16px; }
.pagina__cabecalho h1 { margin-bottom: 4px; }
.pagina__cabecalho p { color: var(--text-secondary); margin: 0; font-size: 14px; }

.rodape {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px 14px 30px;
    color: var(--text-secondary);
    font-size: 12px;
    text-align: center;
    border-top: 1px solid var(--border-color);
}

/* ------------------------------------------------------------------ cartões */

.cartao {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--sombra-sm);
    margin-bottom: 16px;
    overflow: hidden;
}

.cartao__cabecalho {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}
.cartao__cabecalho h2,
.cartao__cabecalho h3 { margin: 0; font-size: 16px; }

.cartao__corpo { padding: 16px; }
.cartao__rodape {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-suave);
}

/* Faixa de indicadores */

.indicadores {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.indicador {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--sombra-sm);
    padding: 14px 16px;
    border-left: 4px solid var(--primary);
    display: block;
    color: inherit;
    text-decoration: none;
}
a.indicador:hover { box-shadow: var(--sombra-md); }
.indicador--ok { border-left-color: var(--ok); }
.indicador--erro { border-left-color: var(--erro); }
.indicador--aviso { border-left-color: var(--accent); }

.indicador__rotulo {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}
.indicador__valor {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.15;
    word-break: break-word;
}
.indicador--ok .indicador__valor { color: var(--ok); }
.indicador--erro .indicador__valor { color: var(--erro); }
.indicador__nota { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

/* ------------------------------------------------------------------ tabelas */

/* Em telemóvel cada linha vira um cartão: o cabeçalho de cada célula vem do
   atributo data-rotulo, que as páginas preenchem. */
.tabela-envolvente { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table.tabela {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
table.tabela th,
table.tabela td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
}
table.tabela th {
    background: var(--bg-suave);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--text-secondary);
    white-space: nowrap;
}
table.tabela tbody tr:last-child td { border-bottom: none; }
table.tabela .num { text-align: right; white-space: nowrap; }
table.tabela tfoot td {
    font-weight: 700;
    background: var(--bg-suave);
    border-top: 2px solid var(--border-color);
}

@media (max-width: 720px) {
    table.tabela thead { display: none; }
    table.tabela, table.tabela tbody, table.tabela tr, table.tabela td { display: block; width: 100%; }
    table.tabela tr {
        border: 1px solid var(--border-color);
        border-radius: var(--radius-sm);
        margin-bottom: 10px;
        padding: 4px 0;
    }
    table.tabela td {
        border-bottom: 1px dashed var(--border-color);
        display: flex;
        justify-content: space-between;
        gap: 12px;
        text-align: right;
    }
    table.tabela td:last-child { border-bottom: none; }
    table.tabela td::before {
        content: attr(data-rotulo);
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: .4px;
        color: var(--text-secondary);
        text-align: left;
        flex: 0 0 45%;
    }
    table.tabela td.num { text-align: right; }
    table.tabela tfoot td { display: flex; }

    /* Em cartão, a linha de selecção passa a ocupar a largura toda e mostra o
       texto: o estudante toca em qualquer ponto da faixa, não num quadradinho. */
    table.tabela td.celula-escolha { display: block; }
    table.tabela td.celula-escolha::before { content: none; }
    .celula-escolha .escolha {
        justify-content: flex-start;
        gap: 10px;
        width: 100%;
        text-align: left;
        font-weight: 600;
        background: var(--bg-suave);
        border-radius: var(--radius-sm);
    }
    .celula-escolha .escolha__texto {
        position: static;
        width: auto;
        height: auto;
        margin: 0;
        overflow: visible;
        clip: auto;
        white-space: normal;
        font-size: 14px;
    }
}

/* Lista de pares rótulo/valor (dados pessoais, detalhes) */

.dados { margin: 0; }
.dados div {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border-color);
}
.dados div:last-child { border-bottom: none; }
.dados dt { color: var(--text-secondary); font-size: 13px; flex: 0 0 42%; }
.dados dd { margin: 0; font-weight: 600; text-align: right; word-break: break-word; }

@media (max-width: 520px) {
    .dados div { flex-direction: column; gap: 2px; padding: 8px 0; }
    .dados dd { text-align: left; }
}

/* -------------------------------------------------------------- distintivos */

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    white-space: nowrap;
    background: #e9ecef;
    color: #495057;
}
.badge--ok { background: var(--ok-bg); color: var(--ok); }
.badge--erro { background: var(--erro-bg); color: var(--erro); }
.badge--aviso { background: var(--aviso-bg); color: var(--aviso); }
.badge--info { background: var(--info-bg); color: var(--info); }

/* ----------------------------------------------------------------- alertas */

.alerta {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid;
    margin-bottom: 14px;
    font-size: 14px;
}
.alerta strong { display: inline; }
.alerta--sucesso { background: var(--ok-bg); border-color: var(--ok-borda); color: var(--ok); }
.alerta--erro { background: var(--erro-bg); border-color: var(--erro-borda); color: var(--erro); }
.alerta--aviso { background: var(--aviso-bg); border-color: var(--aviso-borda); color: var(--aviso); }
.alerta--info { background: var(--info-bg); border-color: var(--info-borda); color: var(--info); }

/* Aviso compacto e dispensável (senha inicial) */
.alerta--compacto {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 10px;
    font-size: 13px;
    line-height: 1.45;
    margin-bottom: 10px;
}
.alerta--compacto[hidden] { display: none !important; }
.alerta__fechar {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    margin: -3px -4px 0 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font-size: 20px;
    line-height: 1;
    opacity: .65;
    cursor: pointer;
}
.alerta__fechar:hover, .alerta__fechar:focus { opacity: 1; }

/* Barra de acção de formulários longos.
   Em ecrã pequeno o botão de submeter ficava no fim de uma lista longa e
   obrigava a percorrê-la toda outra vez (issue #146). Aqui cola-se ao fundo do
   ecrã, com o total sempre à vista. Em ecrã largo é uma linha normal. */
.barra-accao {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
}
.barra-accao__resumo { margin: 0; font-size: 14px; flex: 1 1 100%; }

@media (max-width: 720px) {
    .barra-accao {
        position: sticky;
        bottom: 0;
        z-index: 20;
        margin: 16px -16px 0;
        padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
        background: var(--bg-card);
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -4px 14px rgba(0, 0, 0, .08);
    }
    .barra-accao .btn { flex: 1 1 auto; }
    .barra-accao__resumo { font-size: 13px; }
}

@media print {
    .barra-accao { position: static; box-shadow: none; border-top: 0; }
}

/* Botão a aguardar resposta do servidor */
.btn--ocupado { opacity: .75; pointer-events: none; }
.girador {
    display: inline-block;
    width: 13px;
    height: 13px;
    margin-right: 6px;
    vertical-align: -2px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: girar .7s linear infinite;
}
@keyframes girar { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .girador { animation-duration: 2.4s; }
}

.vazio {
    padding: 26px 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
}
.vazio strong { display: block; color: var(--text-primary); margin-bottom: 4px; font-size: 15px; }

/* ------------------------------------------------------------------ botões */

.btn {
    display: inline-block;
    padding: 11px 18px;
    border: 1px solid var(--primary);
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: #fff;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}
.btn:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.btn:disabled, .btn.desactivado { opacity: .55; cursor: not-allowed; }

.btn--secundario { background: #fff; color: var(--primary); }
.btn--secundario:hover { background: var(--info-bg); color: var(--primary); }
.btn--destaque { background: var(--accent); border-color: var(--accent); color: var(--primary-dark); }
.btn--destaque:hover { background: var(--accent-light); border-color: var(--accent-light); color: var(--primary-dark); }
.btn--pequeno { padding: 6px 12px; font-size: 13px; }
.btn--largo { display: block; width: 100%; }

.botoes { display: flex; flex-wrap: wrap; gap: 10px; }
@media (max-width: 520px) {
    .botoes { flex-direction: column; }
    .botoes .btn { width: 100%; }
}

/* Atalhos do painel */

.atalhos {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.atalho {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px 14px;
    text-align: center;
    text-decoration: none;
    color: var(--text-primary);
    box-shadow: var(--sombra-sm);
}
.atalho:hover { border-color: var(--primary-light); box-shadow: var(--sombra-md); color: var(--primary); }
.atalho__icone { font-size: 26px; line-height: 1; display: block; margin-bottom: 8px; }
.atalho__nome { font-weight: 600; font-size: 14px; display: block; }
.atalho__nota { font-size: 12px; color: var(--text-secondary); display: block; margin-top: 2px; }

/* ------------------------------------------------------------- formulários */

.campo { margin-bottom: 14px; }
.campo > label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 5px;
    color: var(--text-primary);
}
.campo__ajuda { display: block; font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.campo__obrigatorio { color: var(--erro); }

input[type="text"], input[type="number"], input[type="email"], input[type="tel"],
input[type="date"], input[type="password"], input[type="file"], select, textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 15px; /* 16px ou mais evita o zoom automático no iOS */
    color: var(--text-primary);
    background: #fff;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(44, 95, 138, .12);
}
textarea { min-height: 88px; resize: vertical; }

/* Caixas de selecção com alvo de toque a sério.
   O checkbox nativo dá 13x13px de área clicável — impossível de acertar num
   telemóvel (issue #140). O <label> à volta leva o alvo aos 44x44px mínimos
   recomendados e o texto fica só para leitores de ecrã. */
.celula-escolha { padding: 0 !important; }
.escolha {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    margin: 0;
    padding: 11px;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(44, 95, 138, .18);
}
.escolha input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin: 0;
    accent-color: var(--primary);
    cursor: pointer;
}
.escolha__texto {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}
.escolha:focus-within { background: rgba(44, 95, 138, .08); border-radius: var(--radius-sm); }

.grelha { display: grid; grid-template-columns: 1fr; gap: 0 14px; }

.valores-rapidos { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* Separadores (links, sem JavaScript) */

.separadores {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.separadores a {
    padding: 10px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}
.separadores a.activo { color: var(--primary); border-bottom-color: var(--primary); }

/* Barra de progresso */

.progresso {
    height: 10px;
    background: var(--border-color);
    border-radius: 6px;
    overflow: hidden;
    margin: 8px 0 4px;
}
.progresso__barra { height: 100%; background: var(--primary-light); border-radius: 6px; }

/* Linha de movimento (crédito/débito) */

.credito { color: var(--ok); font-weight: 600; }
.debito { color: var(--erro); font-weight: 600; }

.filtros {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
}
.filtros .campo { margin-bottom: 0; flex: 1 1 150px; }

.paginacao {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding-top: 12px;
    font-size: 14px;
    color: var(--text-secondary);
}

/* --------------------------------------------------------- ecrã de entrada */

.entrada {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary) 60%, var(--primary-light));
}

.entrada__caixa {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border-top: 4px solid var(--accent);
    box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
    overflow: hidden;
}
.entrada__voltar { padding: 14px 20px 0; font-size: 13px; }
.entrada__voltar a { color: var(--text-secondary); text-decoration: none; }
.entrada__voltar a:hover { color: var(--primary); text-decoration: underline; }
.entrada__cabecalho { padding: 26px 24px 18px; text-align: center; }
.entrada__logo {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    border: 2px solid var(--accent);
    object-fit: cover;
    margin-bottom: 12px;
    background: #fff;
}
.entrada__cabecalho h1 { font-size: 19px; margin-bottom: 2px; }
.entrada__cabecalho p { color: var(--text-secondary); font-size: 13px; margin: 0; }
.entrada__corpo { padding: 0 24px 24px; }
.entrada__ajuda {
    padding: 14px 24px 20px;
    background: var(--bg-suave);
    border-top: 1px solid var(--border-color);
    font-size: 12.5px;
    color: var(--text-secondary);
}
.entrada__ajuda p { margin: 0 0 6px; }
.entrada__ajuda p:last-child { margin-bottom: 0; }

/* ------------------------------------------------------------- ecrãs largos */

@media (min-width: 640px) {
    body { font-size: 15px; }
    .indicadores { grid-template-columns: repeat(2, 1fr); }
    .atalhos { grid-template-columns: repeat(3, 1fr); }
    .grelha--2 { grid-template-columns: 1fr 1fr; }
    .conteudo { padding: 22px 20px 48px; }
}

@media (min-width: 900px) {
    .indicadores { grid-template-columns: repeat(4, 1fr); }
    .atalhos { grid-template-columns: repeat(4, 1fr); }
    .grelha--3 { grid-template-columns: repeat(3, 1fr); }

    /* Em ecrã grande o menu está sempre aberto, na horizontal. */
    .menu__botao { display: none; }
    .menu { display: block; background: transparent; border-top: none; }
    .topo__barra { padding-bottom: 0; }
    .menu__lista {
        display: flex;
        flex-wrap: wrap;
        padding: 0 16px;
        gap: 2px;
    }
    .menu__lista a {
        padding: 12px 14px;
        border-left: none;
        border-bottom: 3px solid transparent;
        font-size: 14px;
    }
    .menu__lista a.activo { border-left: none; border-bottom-color: var(--accent); background: transparent; }
    .menu__lista li.espaco { margin-left: auto; }
}

/* --------------------------------------------------------------- impressão */

@media print {
    .topo, .menu, .rodape, .botoes, .filtros, .paginacao, .sem-impressao { display: none !important; }
    body { background: #fff; font-size: 12px; }
    .conteudo { max-width: none; padding: 0; }
    .cartao { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
    table.tabela { font-size: 11px; }
    table.tabela thead { display: table-header-group; }
    a[href]::after { content: ""; }
}
