/* 1. Definições de Cores e Reset */
:root {
    --primary: #077AB3;
    --primary-hover: #056696;
    --bg-body: #f4f7f9;
    --text-main: #334155;
    --text-muted: #64748b;
    --white: #ffffff;
    --border: #e2e8f0;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #ed8936;
    --info: #004080;
    --loading: #64748b;
    --modal-overlay: rgba(15, 23, 42, 0.45);
}

/* IMPORTANTE: Altura total para o Sticky Footer */
html, body {
    height: 100%; /* html e body precisam ambos de height 100% */
}

body {
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column; /* Organiza os elementos em coluna (cima para baixo) */
}

/* 2. Tipografia e Links */
h1, h2, h3 { color: #1e293b; margin-top: 0; line-height: 1.2; }

a {
    color: var(--primary);
    text-decoration: none;
    transition: 0.2s ease-in-out;
}

a:hover { color: var(--primary-hover); text-decoration: none; }

/* ==========================================================================
   3. CONTAINERS E LAYOUT (STICKY FOOTER MAGIC)
   ========================================================================== */

/* A classe .main-content deve ser colocada no header.php (abrindo-a) e 
   fechada no footer.php. Ela é a "mola" que empurra o footer para baixo.
*/
.main-content {
    flex: 1 0 auto; /* Isto diz à div para "crescer" e ocupar todo o espaço vazio disponível */
    width: 100%;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    width: 100%;
    box-sizing: border-box;
}

footer {
    flex-shrink: 0; /* Impede que o browser tente esmagar o footer se o ecrã for pequeno */
    width: 100%;
}

/* 4. Cartões (Forms e Listas) */
.form-card {
    background: var(--white);
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    margin-bottom: 20px;
    border: 1px solid var(--border);
}

/* 5. Tabelas Modernas e Responsivas */
.table-responsive {
    overflow-x: auto; /* Permite scroll lateral no telemóvel */
    border-radius: 12px;
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--white);
}

th {
    background: #f8fafc;
    padding: 15px;
    text-align: left;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
}

td {
    padding: 15px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover { background-color: #f8fafc; }

/* 6. Inputs e Formulários */
.form-group { margin-bottom: 15px; }

label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-main);
}

input, select, textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    box-sizing: border-box;
    transition: all 0.2s;
    background-color: var(--white);
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(7, 122, 179, 0.15);
}

/* 7. Botões Utilitários - Blindados */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent; /* Adicionado para evitar saltos no hover com borda */
    transition: all 0.2s ease;
    font-size: 0.9rem;
    text-decoration: none !important; /* Garante que links não fiquem sublinhados */
    line-height: 1.2;
    white-space: nowrap; /* Impede que o texto quebre em duas linhas */
    user-select: none; /* Evita selecionar o texto ao clicar rápido */
}

/* Efeito de clique */
.btn:active { transform: scale(0.96); }

/* Primário (Azul BusWay) */
.btn-primary { 
    background-color: var(--primary); 
    color: var(--white) !important; 
}
.btn-primary:hover { 
    background-color: var(--primary-hover); 
    color: var(--white) !important; 
}

/* Perigo (Vermelho) */
.btn-danger { 
    background-color: var(--danger); 
    color: var(--white) !important; 
}
.btn-danger:hover { 
    background-color: #dc2626; 
    color: var(--white) !important; 
}

/* Secundário (Cinza Neutro) */
.btn-secondary { 
    background-color: #f1f5f9; 
    color: var(--text-main) !important; 
    border-color: var(--border); 
}
.btn-secondary:hover { 
    background-color: #e2e8f0; 
    color: var(--primary) !important; /* Dá um charme: texto fica azul no hover */
    border-color: var(--primary);
}

/* Ajuste para ícones dentro de botões */
.btn i {
    font-size: 1rem;
    color: inherit; /* O ícone terá sempre a mesma cor do texto do botão */
}

/* 8. Alertas Dinâmicos */
.alert {
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.alert-danger {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* ==========================================================================
   9. BW-MODAL SYSTEM (Popups Dinâmicos)
   ========================================================================== */

/* Overlay com efeito Glassmorphism */
.bw-modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--modal-overlay);
    backdrop-filter: blur(8px); /* Desfoca o fundo */
    -webkit-backdrop-filter: blur(8px);
    z-index: 9999;
    display: none; /* Ativado via JS */
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: bwFadeIn 0.3s ease;
}

/* Card da Popup */
/* Card da Popup - Ajustado para evitar cortes no topo */
.bw-modal-card {
    background: var(--white);
    width: 100%;
    max-width: 95vw;
    max-height: 90vh;
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    position: relative;
    overflow: hidden;
    border: none; /* Removemos bordas laterais se existirem */
    animation: bwScaleIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}


.bw-modal-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 10px; /* Um pouco mais grossa para dar destaque */
    z-index: 5;
    border-radius: 20px 20px 0 0; /* Acompanha o arredondamento da modal */
}

/* Variantes de Cor da Barra Superior (Usando background em vez de border) */
.bw-modal-card.success::before { background: var(--success); }
.bw-modal-card.error::before   { background: var(--danger); }
.bw-modal-card.warning::before { background: var(--warning); }
.bw-modal-card.info::before    { background: var(--info); }
.bw-modal-card.loading::before { background: var(--loading); }
.bw-modal-card.loading_details::before { background: var(--primary); }


.bw-progress-container {
    width: 100%; height: 8px; background: #e2e8f0; 
    border-radius: 4px; margin-top: 20px; overflow: hidden;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}
.bw-progress-bar {
    height: 100%; background: var(--primary); 
    width: 0%; transition: width 0.3s ease;
}
.bw-progress-text {
    font-size: 0.85rem; color: #64748b; margin-top: 8px; font-weight: 800;
}

/* Botão de Fechar (Canto Superior Direito) */
.bw-modal-close {
    position: absolute; /* ESSENCIAL para o right: 15px funcionar */
    top: 15px;
    right: 15px;
    background: #f1f5f9;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 20px;
    transition: 0.2s;
    z-index: 10;
}

.bw-modal-close:hover {
    background: #e2e8f0;
    color: var(--text-main);
    transform: rotate(90deg);
}

/* Conteúdo */
.bw-modal-body {
    padding: 45px 30px 30px; 
    text-align: center;
    position: relative;
}

.bw-modal-icon {
    width: 60px;
    height: 60px;
    margin: 0 auto 20px auto; 
    display: flex; 
    align-items: center;
    justify-content: center;
    border-radius: 50%; 
    font-size: 1.8rem;
    flex-shrink: 0; 
}




.bw-modal-title {
    font-weight: 800;
    font-size: 1.3rem;
    color: #1e293b;
    margin-bottom: 12px;
}

.bw-modal-text {
    color: var(--text-muted);
    line-height: 1.6;
    font-size: 0.95rem;
}

/* Rodapé com Botões */
.bw-modal-footer {
    padding: 20px 30px;
    background: #f8fafc;
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* Estilo do Spinner para Loading */
.bw-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid var(--primary);
    border-radius: 50%;
    animation: bwSpin 1s linear infinite;
    margin: 0 auto 20px;
}

/* Animações */
@keyframes bwFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes bwScaleIn {
    from { transform: scale(0.92); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes bwSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ==========================================================================
   10. RESPONSIVIDADE (MOBILE & TABLETS)
   ========================================================================== */

/* Ecrãs até 768px (Tablets pequenos e Smartphones) */
@media (max-width: 768px) {
    /* 1. Ajustes Globais (Redução de ~20% e Remoção de Margens Laterais) */
    body {
        font-size: 0.9rem; /* Reduz o tamanho base do texto */
    }

    .container {
        padding: 0; /* Remove a margem lateral desnecessária (Edge-to-Edge) */
    }

    /* Reduz títulos e dá-lhes uma margem mínima para não tocarem no ecrã se estiverem fora de cartões */
    h1 { font-size: 1.35rem; padding: 0 15px; } 
    h2 { font-size: 1.15rem; padding: 0 15px; }

    /* 2. Cartões Edge-to-Edge */
    .form-card {
        padding: 15px; /* Reduz o espaço interno (era 25px) */
        border-radius: 0; /* Remove os cantos redondos porque agora toca nas bordas */
        border-left: none; /* Remove a borda esquerda */
        border-right: none; /* Remove a borda direita */
        margin-bottom: 15px; /* Reduz a distância entre blocos */
    }

    /* 3. Inputs e Tabelas (Mais compactos) */
    input, select, textarea {
        padding: 10px; /* Reduz altura do input */
        font-size: 0.85rem; /* Texto mais pequeno no input */
    }

    th, td {
        padding: 10px 12px; /* Reduz espaço nas células da tabela (era 15px) */
        font-size: 0.8rem;
    }

    /* 4. Botões (Largura total, mas com respiro, e tamanho reduzido) */
    .btn {
        padding: 10px 16px; /* Botões ligeiramente mais finos */
        font-size: 0.85rem;
        width: calc(100% - 30px); /* 100% da largura menos 15px de cada lado */
        margin: 0 15px 10px 15px; /* Garante que os botões não batem no limite do ecrã */
        justify-content: center;
    }

    /* 5. Ajustes na BW-Modal (Popups mais proporcionais) */
    .bw-modal-overlay {
        padding: 20px; 
        align-items: center; /* MUDADO de flex-end para center */
        justify-content: center;
    }

    .bw-modal-card {
        border-radius: 20px; /* MUDADO para manter arredondado em todo o lado */
        max-height: 90vh;
        width: 100%;
        max-width: 400px; /* Garante que não fica demasiado larga no mobile */
        overflow-y: auto; 
    }
    
    /* Remove as margens negativas dos botões que tinhas no mobile para a modal */
    
    .bw-modal-body {
        padding: 25px 15px 15px; /* Reduz espaço branco dentro da popup */
    }

    .bw-modal-icon {
        width: 55px; /* Reduz o círculo do ícone (era 70px) */
        height: 55px;
        margin-bottom: 15px;
    }

    .bw-modal-title { 
        font-size: 1.15rem; /* Título mais pequeno */
    } 
    
    .bw-modal-text { 
        font-size: 0.85rem; /* Texto descritivo mais pequeno */
    }

    .bw-modal-footer {
        padding: 15px;
        flex-direction: column; /* Botões uns por cima dos outros */
        gap: 8px;
    }
    



    /* Os botões dentro da modal já têm as suas margens ajustadas pelo flex-direction */
    .bw-modal-footer .btn-pill, 
    .bw-modal-footer button {
        width: 100%; 
        padding: 12px;
        margin: 0; 
    }
}