:root {
    --bleu-nuit: #10275c;
    --bleu-vif: #1e40af;
    --or: #d4a017;
    --terracotta: #c1440e;
    --vert: #15803d;
    --rouge: #b91c1c;
    --gris-fond: #f4f5f7;
    --gris-bordure: #e2e4e9;
    --texte: #1f2430;
    --texte-clair: #6b7280;
    --blanc: #ffffff;
    --radius: 10px;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--gris-fond);
    color: var(--texte);
}

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 300px;
    flex-shrink: 0;
    background: var(--bleu-nuit);
    color: var(--blanc);
    display: flex;
    flex-direction: column;
    padding: 1.4rem 1rem;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 1.15rem; color: var(--or); padding: 0 0.5rem 1.4rem; }
.sidebar-nav { display: flex; flex-direction: column; gap: 0.1rem; flex: 1; overflow-y: auto; }
.sidebar-nav a {
    color: #c7cbe0;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.88rem;
    padding: 0.55rem 0.8rem;
    border-radius: 8px;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.06); color: var(--blanc); }
.sidebar-nav a.active { background: var(--bleu-vif); color: var(--blanc); }
.sidebar-nav a i { width: 17px; height: 17px; flex-shrink: 0; }
.sidebar-section { color: #8891b8; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; padding: 0.7rem 0.8rem 0.2rem; }

.topbar-user-area {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.8rem;
    padding: 0.8rem 1.75rem;
    background: var(--blanc);
    border-bottom: 1px solid var(--gris-bordure);
}
.topbar-user-area .user-info { display: flex; flex-direction: column; font-size: 0.82rem; line-height: 1.3; }
.topbar-user-area .user-info span { color: var(--texte-clair); }
.topbar-user-area .btn-logout { color: var(--bleu-nuit); background: var(--gris-fond); }

.sidebar-user { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; padding-top: 1rem; border-top: 1px solid rgba(255,255,255,0.1); }
.user-info { display: flex; flex-direction: column; font-size: 0.8rem; line-height: 1.35; }
.user-info span { color: #c7cbe0; }
.btn-logout { color: var(--blanc); background: rgba(255,255,255,0.1); border-radius: 50%; padding: 0.45rem; display: flex; flex-shrink: 0; }

.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.content { padding: 1.5rem 1.75rem; max-width: 1600px; margin: 0 auto; width: 100%; flex: 1; }

.page-title { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1.6rem; color: var(--bleu-nuit); }

.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.25rem; margin-bottom: 2rem; }
.stat-card {
    background: var(--blanc);
    border-radius: var(--radius);
    padding: 1.5rem 1.6rem;
    border-top: 4px solid var(--bleu-vif);
    border-left: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.stat-card > i[data-lucide] { display: block; width: 22px; height: 22px; margin-bottom: 0.9rem; }
.stat-card.or { border-color: var(--or); }
.stat-card.vert { border-color: var(--vert); }
.stat-card.rouge { border-color: var(--rouge); }
.stat-card.terracotta { border-color: var(--terracotta); }
.stat-card .label { font-size: 0.75rem; color: var(--texte-clair); margin-top: 0.6rem; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-card .valeur { font-size: 1.6rem; font-weight: 700; color: var(--bleu-nuit); }

.panel {
    background: var(--blanc);
    border-radius: var(--radius);
    padding: 1.6rem 1.7rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    margin-bottom: 1.75rem;
}
a.panel:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.1); transform: translateY(-2px); }
.panel h2 { display: flex; align-items: center; gap: 0.5rem; font-size: 1.05rem; color: var(--bleu-nuit); margin-top: 0; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--gris-bordure); }
th { color: var(--texte-clair); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }

.badge { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.25rem 0.6rem; border-radius: 20px; font-size: 0.78rem; font-weight: 600; }
.badge.soumis { background: #fef3c7; color: #92400e; }
.badge.en_validation { background: #dbeafe; color: #1e40af; }
.badge.valide_national { background: #dcfce7; color: #15803d; }
.badge.rejete { background: #fee2e2; color: #b91c1c; }

.btn { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.55rem 1.1rem; border-radius: 8px; border: none; font-weight: 600; cursor: pointer; text-decoration: none; font-size: 0.9rem; }
.btn-primary { background: var(--bleu-vif); color: var(--blanc); }
.btn-primary:hover { background: var(--bleu-nuit); }
.btn-valider { background: var(--vert); color: var(--blanc); }
.btn-rejeter { background: var(--rouge); color: var(--blanc); }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.4rem; font-weight: 600; font-size: 0.88rem; color: var(--texte); }
.form-group input, .form-group textarea { width: 100%; padding: 0.6rem 0.7rem; border: 1px solid var(--gris-bordure); border-radius: 8px; font-size: 0.92rem; }

.alert { padding: 0.8rem 1.1rem; border-radius: 8px; margin-bottom: 1.2rem; font-size: 0.9rem; }
.alert-erreur { background: #fee2e2; color: #b91c1c; }
.alert-succes { background: #dcfce7; color: #15803d; }

.login-wrapper { display: flex; align-items: center; justify-content: center; min-height: 80vh; }
.login-card { background: var(--blanc); border-radius: var(--radius); padding: 2.2rem; width: 100%; max-width: 380px; box-shadow: 0 4px 14px rgba(0,0,0,0.08); }
.login-card h1 { text-align: center; color: var(--bleu-nuit); font-size: 1.3rem; margin-bottom: 1.6rem; }

.footer { text-align: center; padding: 1.2rem; color: var(--texte-clair); font-size: 0.8rem; }
.print-only { display: none; }

/* ============================================================================
   RESPONSIVE — mobile et tablette
   ============================================================================ */

/* Voile derrière le menu mobile ouvert, pour le refermer d'un clic à l'extérieur */
.voile-sidebar { display: none; }

/* Barre de navigation basse (façon appli mobile) — masquée par défaut, visible seulement sur petit écran */
.nav-mobile-bas { display: none; }

@media (max-width: 900px) {
    #btn-menu-mobile { display: none !important; } /* remplacé par la barre basse */

    .app-shell { display: block; }

    .sidebar {
        position: fixed;
        left: 0; top: 0;
        z-index: 200;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        width: 82%;
        max-width: 300px;
        box-shadow: 4px 0 18px rgba(0,0,0,0.25);
        border-radius: 0 16px 16px 0;
    }
    .sidebar.ouverte { transform: translateX(0); }

    .voile-sidebar.visible {
        display: block;
        position: fixed; inset: 0;
        background: rgba(16, 39, 92, 0.45);
        z-index: 150;
        backdrop-filter: blur(1px);
    }

    .main-area { min-width: 0; width: 100%; }

    .content { padding: 0.9rem 0.9rem calc(1rem + 66px); } /* place pour la barre basse */

    /* En-tête du haut : épuré, l'essentiel visible, le reste dans la barre basse */
    .topbar-user-area { padding: 0.65rem 0.9rem; gap: 0.5rem; position: sticky; top: 0; z-index: 50; }
    .topbar-user-area form[action*="/recherche"] { display: none; } /* la recherche vit désormais dans la barre basse */
    .topbar-user-area .user-info { display: none; }
    .topbar-user-area a[title="Notifications"] { display: none; } /* idem, dans la barre basse */

    /* Barre de navigation basse, style application mobile native */
    .nav-mobile-bas {
        display: flex;
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: 180;
        background: var(--blanc);
        border-top: 1px solid var(--gris-bordure);
        box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
        padding: 0.35rem 0.2rem calc(0.35rem + env(safe-area-inset-bottom, 0px));
    }
    .nav-mobile-bas a, .nav-mobile-bas button {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.2rem;
        background: none;
        border: none;
        color: var(--texte-clair);
        text-decoration: none;
        font: inherit;
        font-size: 0.65rem;
        font-weight: 600;
        padding: 0.3rem 0.1rem;
        border-radius: 10px;
        position: relative;
    }
    .nav-mobile-bas i[data-lucide] { width: 21px; height: 21px; }
    .nav-mobile-bas a.actif { color: var(--bleu-vif); }
    .nav-mobile-bas a:active, .nav-mobile-bas button:active { background: var(--gris-fond); }
    .pastille-nav-bas {
        position: absolute; top: -2px; right: 18%;
        background: var(--rouge); color: #fff;
        font-size: 0.58rem; font-weight: 700;
        border-radius: 50%; min-width: 15px; height: 15px;
        display: flex; align-items: center; justify-content: center;
        padding: 0 2px;
    }

    /* Toute grille (tableaux de bord, statistiques) posée en style inline
       devient forcément 2 colonnes sur tablette, 1 sur téléphone — voir
       règle plus bas. Ça couvre tous les cards-grid à colonnes fixes
       construits avec un style="grid-template-columns:repeat(N,1fr)". */
    [style*="grid-template-columns"] { grid-template-columns: repeat(2, 1fr) !important; }
    .cards-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)) !important; }

    /* Cartes statistiques : disposition horizontale (icône à gauche, chiffre à droite) — plus compact et plus rapide à lire sur mobile qu'un empilement vertical */
    .stat-card {
        padding: 0.85rem 1rem;
        display: flex;
        align-items: center;
        gap: 0.7rem;
        border-top: none;
        border-left: 4px solid var(--bleu-vif);
        border-radius: 12px;
    }
    .stat-card.or { border-left-color: var(--or); }
    .stat-card.vert { border-left-color: var(--vert); }
    .stat-card.rouge { border-left-color: var(--rouge); }
    .stat-card.terracotta { border-left-color: var(--terracotta); }
    .stat-card > i[data-lucide] { margin-bottom: 0; flex-shrink: 0; width: 26px; height: 26px; }
    .stat-card .valeur { font-size: 1.25rem; line-height: 1.15; }
    .stat-card .label { margin-top: 0.15rem; font-size: 0.66rem; }

    .panel { border-radius: 14px; padding: 1.1rem 1.1rem; margin-bottom: 1.1rem; }
    a.panel:hover, a.panel:active { transform: none; }

    /* Tableaux : défilement horizontal avec indice visuel plutôt qu'un débordement cassé */
    .panel:has(table) { overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 0; }
    .panel:has(table) h2 { padding: 1rem 1.1rem 0; }
    .panel:has(table) > p { padding: 0 1.1rem; }
    table { min-width: 560px; }
    table thead th { position: sticky; top: 0; background: var(--blanc); }

    .page-title { font-size: 1.05rem; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1.1rem; }
    .page-title i[data-lucide] { width: 19px; height: 19px; }

    .btn { padding: 0.6rem 1rem; font-size: 0.86rem; border-radius: 10px; }
    .form-group input, .form-group textarea, .form-group select { padding: 0.65rem 0.75rem; font-size: 1rem; border-radius: 10px; } /* 1rem = pas de zoom auto iOS */

    .login-wrapper { min-height: auto; padding: 2.5rem 1.1rem; }
    .login-card { padding: 1.8rem 1.5rem; border-radius: 16px; }

    .footer { padding-bottom: calc(1.2rem + 66px); font-size: 0.72rem; }
}

@media (max-width: 560px) {
    [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
    .cards-grid { grid-template-columns: 1fr !important; }
    [style*="display:flex"] { flex-wrap: wrap !important; }

    .content { padding: 0.75rem 0.75rem calc(1rem + 66px); }
    .panel { padding: 1rem; }
    .btn { padding: 0.55rem 0.9rem; font-size: 0.84rem; }
    .nav-mobile-bas span { font-size: 0.62rem; }

    /* Les en-têtes de page "titre + bouton d'action" passent en colonne */
    .page-title + .btn, .page-title { width: 100%; }
}

@media print {
    .sidebar, .footer, .no-print, .topbar-user-area { display: none !important; }
    .main-area { margin: 0; }
    body { background: #fff; }
    .content { padding: 0; max-width: 100% !important; width: 100% !important; margin: 0; }
    .panel { box-shadow: none; border: 1px solid var(--gris-bordure); page-break-inside: avoid; max-width: 100% !important; }
    .rapport-section { page-break-inside: avoid; }
    .print-only { display: block !important; }
    table { width: 100% !important; max-width: 100% !important; table-layout: auto; font-size: 0.78rem; border-collapse: collapse; }
    th, td { word-break: break-word; padding: 0.28rem 0.4rem !important; }
    .panel { padding: 0.8rem 1rem !important; margin-bottom: 0.8rem !important; }
    .panel h2, .panel h3 { margin-top: 0.4rem !important; margin-bottom: 0.5rem !important; }
    h3 { padding: 0.3rem 0.6rem !important; margin-top: 0.6rem !important; }
    @page { size: auto; margin: 12mm; }
}
