/* =========================================
   1. VARIABLES & CONFIGURATION
   ========================================= */
:root {
    --brand-green: #1f7a5a;
    --brand-green-600: #186148;
    --brand-green-50: #eaf5ef;
    --brand-purple: #6b4ba1;
    --ink: #1f2937;
    --bg: #f7f7f8;
    --white: #fff;
}

/* =========================================
   2. BASES & RESET
   ========================================= */
* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px;
}

/* =========================================
   3. HEADER & LOGO
   ========================================= */
.site-header {
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    position: sticky;
    top: 0;
    z-index: 2000; /* Z-index de base pour le header */
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    height: 60px; /* Hauteur fixe pour alignement vertical propre */
    padding: 0 24px; /* Padding latéral */
    max-width: 1100px;
    margin: 0 auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--ink);
    font-weight: 700;
    font-size: 1.1rem;
}

.brand-logo {
    background: var(--brand-green);
    color: #fff;
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

/* =========================================
   4. NAVIGATION (MENU DÉROULANT CORRIGÉ)
   ========================================= */
.nav {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 100%;
}

/* Conteneur principal du menu */
.menu {
    position: relative;
    height: 100%; /* Prend toute la hauteur du header */
    display: flex;
    align-items: center;
}

/* Bouton du menu (ex: Gestion Recyclage ▾) */
.menu-btn {
    background: transparent;
    border: none;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--ink);
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
}

.menu-btn:hover,
.menu:hover .menu-btn {
    background-color: var(--brand-green-50);
    color: var(--brand-green);
}

/* Liste déroulante (Sous-menu) */
.menu-items {
    display: none; /* Caché par défaut */
    position: absolute;
    top: 100%; /* Se place juste sous le header */
    left: 0;
    background-color: var(--white);
    min-width: 220px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    z-index: 1000; /* Très haut pour passer par-dessus le contenu */
    padding: 6px 0;
    
    /* Espace visuel sous le header */
    margin-top: 5px; 
}

/* LE PONT INVISIBLE (Empêche le menu de disparaître) */
.menu-items::before {
    content: "";
    position: absolute;
    top: -20px; /* Remonte jusqu'au header */
    left: 0;
    width: 100%;
    height: 20px; /* Couvre l'espace vide */
    background: transparent;
}

/* Affichage au survol */
.menu:hover .menu-items {
    display: block;
    animation: slideDown 0.2s ease-out;
}

/* Liens dans le sous-menu */
.menu-items a {
    display: block;
    padding: 10px 16px;
    color: var(--ink);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.2s, color 0.2s;
    border-bottom: 1px solid transparent;
}

.menu-items a:hover {
    background-color: var(--brand-green-50);
    color: var(--brand-green-600);
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* =========================================
   5. COMPOSANTS (CARTES, BOUTONS, INPUTS)
   ========================================= */
h1 { font-size: 28px; margin: 18px 0; }
h2 { font-size: 20px; margin: 14px 0; color: var(--brand-green); }

.card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,.04);
    margin-bottom: 16px;
}

label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-weight: 600;
    margin-bottom: 12px;
}

input[type='text'], input[type='number'], input[type='date'], select {
    padding: 10px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    outline: none;
    font-family: inherit;
}

input:focus, select:focus {
    border-color: var(--brand-green);
    box-shadow: 0 0 0 2px var(--brand-green-50);
}

.btn {
    background: var(--brand-green);
    border: none;
    color: #fff;
    padding: 10px 14px;
    border-radius: 10px;
    font-weight: 700;
    text-decoration: none;
    display: inline-block;
    cursor: pointer;
}
.btn:hover { background: var(--brand-green-600); }
.btn.secondary { background: var(--brand-purple); }
.btn.small { padding: 6px 10px; font-size: 12px; }

.actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.span-2 { grid-column: 1 / span 2; }
.span-3 { grid-column: 1 / span 3; }

.pallet-rows { display: flex; flex-direction: column; gap: 8px; }
.pallet-row { display: grid; grid-template-columns: 1.2fr 1fr 1fr 1fr 70px; gap: 8px; }
.remove { background: #ef4444; }
.remove:hover { background: #b91c1c; }

/* =========================================
   6. TABLEAUX
   ========================================= */
.table-wrap {
    overflow: auto;
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
}

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid #eee; text-align: left; }
thead th { background: var(--brand-green); color: #fff; text-transform: uppercase; font-size: 0.9rem; letter-spacing: 0.02em; }
tfoot th { background: var(--brand-green-50); }
.right { text-align: right; }
tr.danger { background: #fff5f5; }

/* =========================================
   7. FOOTER & UTILITAIRES
   ========================================= */
.site-footer {
    margin-top: 24px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
    padding: 20px;
    text-align: center;
    color: #666;
}

.pagination {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 10px;
}

details > summary {
    cursor: pointer;
    list-style: none;
    font-weight: 600;
    margin-bottom: 10px;
}
details > summary::-webkit-details-marker { display: none; }

/* =========================================
   8. IMPRESSION
   ========================================= */
@media print {
    .site-header, .site-footer, .actions, .nav, .btn, .pagination, details > summary {
        display: none !important;
    }
    body { background: #fff; }
    .card, .table-wrap { box-shadow: none; border: none; }
    .container { padding: 0; max-width: 100%; }
}