/* --- CONFIGURATION & GRAPHISME --- */
:root {
    --primary-color: #004F9F;
    --primary-hover: #003366;
    --secondary-color: #2e7d32;
    --accent-color: #f59e0b;
    --danger-color: #d32f2f;
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -1px rgba(0,0,0,0.02);
}

/* --- REINITIALISATION --- */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
    padding: 15px;
}

.container {
    max-width: 1050px;
    margin: 0 auto;
}

h2, h3 { color: var(--primary-color); font-weight: 700; margin-bottom: 15px; }
h2 { font-size: 1.5rem; border-bottom: 2px solid var(--border-color); padding-bottom: 10px; }

/* --- COMPOSANT DE NAVIGATION RESPONSIVE --- */
.navbar-container {
    width: 100%;
    margin-bottom: 25px;
}

.navbar {
    background-color: var(--bg-card);
    padding: 6px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    display: grid;
    /* Par défaut sur mobile : 5 colonnes égales pour tout aligner proprement */
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
}

.navbar a {
    color: var(--text-main);
    text-decoration: none;
    font-weight: 600;
    padding: 10px 4px;
    border-radius: calc(var(--radius) - 4px);
    transition: all 0.2s ease;
    font-size: 0.85rem;
    display: flex;
    flex-direction: column; /* Icône au-dessus du texte sur mobile */
    align-items: center;
    justify-content: center;
    text-align: center;
}

.navbar a:hover {
    background-color: #f1f5f9;
    color: var(--primary-color);
}

.navbar a.active {
    background-color: var(--primary-color);
    color: #ffffff;
}

.nav-icon {
    font-size: 1.2rem;
    margin-bottom: 2px;
}

.nav-text {
    font-size: 0.75rem;
}

/* --- ADAPTATION POUR ÉCRANS PLUS GRANDS (PC / TABLETTES) --- */
@media (min-width: 640px) {
    .navbar {
        display: flex; /* Retour à un alignement en ligne classique */
        justify-content: flex-start;
        gap: 8px;
        padding: 8px;
    }

    .navbar a {
        flex-direction: row; /* Icône à côté du texte sur PC */
        padding: 10px 18px;
        font-size: 0.9rem;
    }

    .nav-icon {
        font-size: 1rem;
        margin-bottom: 0;
        margin-right: 8px; /* Espace entre l'icône et le texte */
    }

    .nav-text {
        font-size: 0.9rem;
    }
}


/* --- COMPOSANTS DE BASE --- */
.card {
    background: var(--bg-card);
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
}
.info-box {
    background-color: #e5f0fa;
    color: #003366;
    padding: 12px 15px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-weight: 500;
    font-size: 0.9rem;
    border-left: 4px solid var(--primary-color);
}

/* --- GRILLE KPI (S'ADAPTE AUTOMATIQUEMENT) --- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}
.kpi-card {
    background: var(--bg-card);
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    border: 1px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
}
.kpi-card h4 { margin: 0; color: var(--text-muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-card p { margin-top: 8px; font-size: 1.5rem; font-weight: 700; }

/* --- FORMULAIRES COHÉRENTS --- */
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 0.85rem; color: #475569; }
input[type="number"], input[type="date"], select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius);
    font-size: 0.95rem;
    background-color: #fff;
    -webkit-appearance: none; /* Uniformise le style sur iOS */
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 79, 159, 0.12);
}
input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius);
    font-size: 0.95rem;
    size: 50;
    height: 40px;
    background-color: #fff;
    -webkit-appearance: none; /* Uniformise le style sur iOS */
}
button, .btn {
    background-color: var(--primary-color);
    color: #ffffff;
    border: none;
    padding: 12px 20px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    width: 100%; /* S'étend par défaut (idéal mobile), limitable sur PC */
    transition: background-color 0.2s;
}
button:hover { background-color: var(--primary-hover); }

/* --- TABLEAUX & COMPORTEMENT MOBILE --- */
.table-responsive {
    width: 100%;
    overflow-x: auto; /* Empêche le design de casser si le tableau est large */
}
table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 0.9rem; }
th { background-color: #f8fafc; color: #475569; padding: 12px; font-weight: 600; border-bottom: 2px solid var(--border-color); text-align: left; }
td { padding: 12px; border-bottom: 1px solid var(--border-color); }
tr:hover td { background-color: #f8fafc; }
.category-row td { background-color: #f1f5f9; font-weight: 700; }
.total-row td { font-size: 1rem; font-weight: 700; color: var(--primary-color); background-color: #f1f5f9; border-top: 2px solid var(--primary-color); }
.text-right { text-align: right; }

.alert { padding: 12px; margin-bottom: 20px; border-radius: var(--radius); font-weight: 500; font-size: 0.9rem; }
.success { background-color: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.error { background-color: #fef2f2; color: #991b1b; border: 1px solid #fca5a5; }
.warning { background-color: #fffbeb; color: #92400e; border: 1px solid #fef3c7; }

/* --- MEDIA QUERIES (ADAPTATION MOBILES ET ECRANS INTERMEDIAIRES) --- */
@media (max-width: 600px) {
    body { padding: 10px; }
    .card { padding: 15px; }
    
    /* Transformation des tableaux d'index (Saisie et Simulation) en mode liste empilée */
    .stack-mobile table, .stack-mobile thead, .stack-mobile tbody, .stack-mobile th, .stack-mobile td, .stack-mobile tr { 
        display: block; 
    }
    .stack-mobile thead { display: none; } /* Masque les entêtes de colonnes sur mobile */
    .stack-mobile tr { margin-bottom: 15px; border: 1px solid var(--border-color); border-radius: var(--radius); padding: 10px; background: #fafafa; }
    .stack-mobile td { text-align: right; border-bottom: 1px dashed var(--border-color); padding: 8px 5px; position: relative; display: flex; justify-content: space-between; }
    .stack-mobile td:last-child { border-bottom: none; }
    .stack-mobile td::before {
        content: attr(data-label); /* Récupère dynamiquement le nom de la colonne */
        float: left;
        font-weight: 600;
        color: var(--text-muted);
    }
    .stack-mobile .text-right { text-align: right; }
    
    /* Ajustement des filtres d'historique en colonne sur mobile */
    .filter-form { flex-direction: column; align-items: stretch !important; gap: 10px !important; }
}

@media (min-width: 601px) {
    body { padding: 30px 20px; }
    button { width: auto; } /* Sur grand écran, le bouton retrouve sa taille normale */
}
