/* ======================================= */
/* 1. RESET & GLOBALES */
/* ======================================= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: Arial, Helvetica, sans-serif;
}

html, body {
    background-color: #f5f5f5;
    overflow-x: hidden; /* Coupe tout ce qui dépasse de l'écran global */
    width: 100vw;
    max-width: 100%;
    /* CORRECTION MAJEURE : On utilise block au lieu de flex pour permettre le scroll */
    display: block; 
}

/* ======================================= */
/* 2. LAYOUT PRINCIPAL & SIDEBAR */
/* ======================================= */
.sidebar {
    width: 230px;
    height: 100vh;
    background-color: #b7c8ad;
    padding: 25px;
    position: fixed;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    z-index: 2000;
    transition: left 0.3s ease;
}

.sidebar.mobile-open {
    left: 0 !important;
}

.logo { margin-bottom: 40px; }
.logo h1 { font-size: 28px; font-weight: bold; }
.logo span { color: #8cc46b; }

.sidebar ul { list-style: none; }
.sidebar ul li a.nav-link,
.logout a.logout-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 5px;
    font-size: 17px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
    color: inherit;
    text-decoration: none;
    width: 100%;
}

.sidebar ul li a.nav-link:hover {
    background-color: #dce8d5;
    border-radius: 10px;
}

.sidebar ul li a.nav-link.active {
    color: #2e7d32;
}

.sidebar ul li i { color: #8cc46b; font-size: 20px; }

.logout { margin-top: auto; padding-top: 20px; }
.logout i { background-color: black; color: white; padding: 10px; border-radius: 50%; }

.main-content {
    margin-left: 230px;
    width: calc(100% - 230px);
    /* CORRECTION MAJEURE : Empêche la zone de s'étirer à l'infini à cause du tableau */
    min-width: 0; 
    padding: 25px;
    transition: margin 0.3s ease, width 0.3s ease;
}

.content-area {
    margin-top: 40px;
    min-height: 600px;
    width: 100%;
    min-width: 0; /* Autorise le contenu intérieur à scroller */
}

/* ======================================= */
/* 3. HEADER & RECHERCHE GLOBALE */
/* ======================================= */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#mobileMenuBtn {
    display: none;
    font-size: 24px;
    cursor: pointer;
    color: #8cc46b;
    margin-right: 15px;
}

.search-box { position: relative; }
.search-box input {
    width: 320px;
    padding: 12px 40px 12px 15px;
    border-radius: 20px;
    border: 1px solid #ccc;
    outline: none;
}
.search-box i { position: absolute; right: 15px; top: 13px; color: gray; }

.icons { display: flex; gap: 20px; align-items: center; }
.icons i { font-size: 18px; cursor: pointer; transition: 0.3s; position: relative; }
.icons i:hover { color: #8cc46b; }

/* ======================================= */
/* 4. COMPOSANTS (Cartes, Boutons, Titres) */
/* ======================================= */
.page-title h1 { font-size: 36px; margin-bottom: 5px; color: #333; }
.page-title p { color: gray; margin-bottom: 20px; font-size: 14px; }

.toolbar, .table-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.dashboard-cards, .cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-top: 20px;
    margin-bottom: 30px;
}

.card {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.card h3 { margin-bottom: 10px; font-size: 16px; color: #555; }
.card span, .card p { font-size: 24px; font-weight: bold; color: #8cc46b; }

.erp-btn, .btn-add, .btn-submit, .btn-save {
    background: #8cc46b;
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: 0.2s;
}
.erp-btn:hover, .btn-add:hover, .btn-submit:hover, .btn-save:hover { background: #75ae57; }

/* Filtres (Tous, En attente, etc.) */
.filter-btn, .filter-btn-periode {
    background: #f0f0f0;
    border: none;
    padding: 8px 14px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    color: #555;
    transition: 0.2s;
}
.filter-btn:hover, .filter-btn-periode:hover { background: #e0e0e0; }
.filter-btn.active, .filter-btn-periode.active { background: #8cc46b; color: #fff; }

/* ======================================= */
/* 5. TABLEAUX ERP (Optimisés & Défilants) */
/* ======================================= */
.search-table, .search-input {
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    width: 250px;
    font-size: 14px;
}

/* Le conteneur qui permet le défilement */
.table-responsive, 
.erp-table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto; /* Active le rail de défilement */
    -webkit-overflow-scrolling: touch;
    display: block; 
    margin-bottom: 20px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

/* Les tableaux à l'intérieur */
.erp-table, 
.erp-table-pro {
    width: 100%;
    /* S'adapte exactement au texte, permet aux petites colonnes de rester petites */
    min-width: max-content; 
    border-collapse: collapse;
    /* Interdit le retour à la ligne pour un tableau propre */
    white-space: nowrap; 
}

/* Cellules compactes */
.erp-table th, .erp-table td,
.erp-table-pro th, .erp-table-pro td {
    padding: 10px 14px; /* Espacement réduit pour gagner de la place */
    border-bottom: 1px solid #eee;
    text-align: left;
    font-size: 13px; /* Police légèrement plus petite */
}

.erp-table th, .erp-table-pro th {
    background: #f8f9fa;
    font-weight: 600;
    color: #444;
}

/* Lignes au survol */
.erp-table tbody tr, .erp-table-pro tbody tr { transition: background-color 0.2s ease; }
.erp-table tbody tr:hover, .erp-table-pro tbody tr:hover { background-color: #f4f8f2; }

/* Boutons d'actions dans les lignes */
.btn-row-edit, .btn-row-delete, .btn-row-valid, .btn-row-planning, .btn-action {
    background: #f0f0f0;
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
    color: #555;
}
.btn-row-edit:hover, .btn-action:hover { background: #e3f0fb; color: #2980b9; }
.btn-row-delete:hover { background: #fdecea; color: #e74c3c; }
.btn-row-valid:hover { background: #e8f5e2; color: #27ae60; }
.btn-row-planning:hover { background: #fff4e5; color: #f39c12; }

/* ======================================= */
/* 6. MODALES & FORMULAIRES */
/* ======================================= */
.modal-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    display: none; 
    align-items: center;
    justify-content: center;
    z-index: 3000;
}
.modal-overlay.active { display: flex; }

.modal-content, .modal-box {
    background: white;
    width: 90% !important;
    max-width: 500px;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    overflow: hidden;
    margin: 0 15px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: apparitionModal 0.2s ease-out;
}

@keyframes apparitionModal {
    from { transform: translateY(-15px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    background: #f9fdf7;
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 { color: #1b5e20; font-size: 16px; display: flex; gap: 8px; align-items: center; }
.modal-close, .close-modal { background: none; border: none; font-size: 14px; color: #888; cursor: pointer; }
.modal-close:hover, .close-modal:hover { color: #e74c3c; }

.modal-body { padding: 20px; overflow-y: auto; }
.form-group { margin-bottom: 14px; }
.form-row { display: flex; gap: 15px; }
.form-row .form-group { flex: 1; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: #555; margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea, .form-select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 13px;
    outline: none;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: #8cc46b; }

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: #fafafa;
}
.btn-cancel {
    background: white; border: 1px solid #ccc;
    padding: 8px 15px; border-radius: 6px;
    cursor: pointer; color: #555; font-size: 13px;
}
.btn-cancel:hover { background: #eee; }

/* ======================================= */
/* 7. BADGES DE STATUTS */
/* ======================================= */
.badge, .badge-statut {
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: bold;
    display: inline-block;
    white-space: nowrap;
    text-align: center;
}
.badge-success, .badge-statut-contacte { background: #e8f5e2; color: #27ae60; border: 1px solid #bce2a8; }
.badge-warning, .badge-statut-attente { background: #fff4e5; color: #f39c12; border: 1px solid #fcdfa6; }
.badge-danger, .badge-statut-suspendu { background: #fdecea; color: #e74c3c; border: 1px solid #f8b8b8; }
.badge-neutral, .badge-statut-defaut { background: #f0f0f0; color: #666; border: 1px solid #ccc; }
.badge-role { background: #e3f0fb; color: #2980b9; }

/* ======================================= */
/* 8. PARAMÈTRES */
/* ======================================= */
.settings-box {
    background: white; padding: 25px;
    border-radius: 12px; max-width: 700px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.settings-box label { display: block; margin-top: 15px; margin-bottom: 5px; font-weight: bold; font-size: 13px; }
.settings-box input, .settings-box textarea { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 6px; }

/* ======================================= */
/* 9. PANELS LATÉRAUX (Messages, Notifications, Profil) */
/* ======================================= */
.side-panel {
    position: fixed; top: 0; right: -380px;
    width: 380px; height: 100vh;
    background: #fff; box-shadow: -4px 0 20px rgba(0,0,0,0.15);
    z-index: 3100; display: flex; flex-direction: column;
    transition: right 0.3s ease;
}
.side-panel.open { right: 0; }
.side-panel-header { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid #eee; background: #f9f9f9; }
.side-panel-tabs { display: flex; gap: 8px; }
.side-panel-tab { padding: 8px 16px; border-radius: 20px; font-size: 13px; font-weight: 500; cursor: pointer; color: #888; transition: 0.2s; }
.side-panel-tab.active { background: #b7c8ad; color: #fff; }
.side-panel-close { background: none; border: none; cursor: pointer; font-size: 14px; color: #888; padding: 6px; }
.side-panel-section { display: none; flex-direction: column; flex: 1; overflow: hidden; }
.side-panel-section.active { display: flex; }
.side-panel-toolbar { padding: 12px 16px; border-bottom: 1px solid #f0f0f0; }

.messages-list, .notifs-list { flex: 1; overflow-y: auto; padding: 8px 0; }
.message-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 200px; color: #bbb; font-size: 13px; gap: 8px; }
.message-empty i { font-size: 36px; }

.panel-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 3000; }
.panel-overlay.active { display: block; }

/* Profil */
.profile-header { display: flex; flex-direction: column; align-items: center; padding: 24px 16px; border-bottom: 1px solid #f0f0f0; background: #f9fdf7; }
.profile-avatar { width: 72px; height: 72px; border-radius: 50%; background: #b7c8ad; color: #fff; font-size: 28px; font-weight: 700; display: flex; align-items: center; justify-content: center; margin-bottom: 12px; }
.profile-name { font-size: 16px; font-weight: 700; color: #333; margin-bottom: 4px; }
.profile-role { font-size: 12px; padding: 3px 12px; border-radius: 12px; background: #b7c8ad; color: #fff; font-weight: 500; }
.profile-info-item { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-bottom: 1px solid #f5f5f5; }
.profile-info-item > i { width: 32px; height: 32px; border-radius: 8px; background: #f0f7ec; color: #8cc46b; display: flex; align-items: center; justify-content: center; font-size: 14px; }
.profile-info-label { font-size: 11px; color: #aaa; margin-bottom: 2px; }
.profile-info-value { font-size: 13px; color: #333; font-weight: 500; }

/* ======================================= */
/* 10. PLANNING ACADÉMIQUE                 */
/* ======================================= */
.planning-header { background: #ffffff; padding: 15px; border-radius: 10px; margin-bottom: 15px; border-left: 5px solid #8cc46b; box-shadow: 0 2px 8px rgba(0,0,0,0.05); }
.planning-header h1 { color: #0b4f16; font-size: 22px; margin-bottom: 5px; }
.planning-week-wrapper { background: #dfead7; padding: 10px; border-radius: 10px; overflow-x: auto; max-height: 70vh; }
.planning-week-table { width: 100%; min-width: 1000px; border-collapse: collapse; table-layout: fixed; background: #ffffff; border-radius: 8px; overflow: hidden; }
.planning-week-table th { background: #eef6ea; color: #1b5e20; border: 1px solid #d7e6d0; height: 32px; font-size: 12px; }
.planning-week-table td { border: 1px dashed #e3eadf; height: 36px; padding: 0; text-align: center; vertical-align: middle; }
.planning-hour-head, .planning-hour { width: 70px; min-width: 70px; background: #eef6ea; color: #1b5e20; font-size: 12px; font-weight: bold; border-right: 2px solid #cddfc3 !important; position: sticky; left: 0; z-index: 20; }
.planning-week-course { color: #fff; font-weight: bold; border-radius: 4px; border: 2px solid #6ea652; }
.course-card { padding: 4px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 2px; line-height: 1.1; }
.cours-vert { background: #8cc46b; } .cours-bleu { background: #027b33; } .cours-orange { background: #a8c98d; color: #1f1f1f;} .cours-jaune { background: #dce8d5; color: #1f1f1f; }
.planning-actions button { border: 1px solid #8cc46b; background: white; border-radius: 4px; font-size: 10px; cursor: pointer; padding: 2px 4px; margin: 2px;}

/* ======================================= */
/* 11. RESPONSIVE DESIGN (Mobiles & Tablettes) */
/* ======================================= */
@media screen and (max-width: 1024px) {
    .dashboard-cards, .cards { grid-template-columns: repeat(2, 1fr); }
}

@media screen and (max-width: 768px) {
    #mobileMenuBtn { display: block; }
    
    .sidebar { left: -250px; box-shadow: 2px 0 10px rgba(0,0,0,0.2); width: 250px; }
    
    .main-content { margin-left: 0; width: 100%; padding: 15px; }

    .page-title h1 { font-size: 24px; }
    .search-box input { width: 180px; }
    
    .toolbar, .table-toolbar { flex-direction: column; align-items: stretch; }
    .search-table, .search-input { width: 100% !important; margin-bottom: 10px; }

    .dashboard-cards, .cards { grid-template-columns: 1fr; }
    
    .side-panel { width: 100%; right: -100%; }
    .form-row { flex-direction: column; gap: 0; }
}

@media screen and (max-width: 480px) {
    .page-title h1 { font-size: 22px; }
    .icons { gap: 12px; }
    .erp-btn, .btn-add { font-size: 12px; padding: 8px 12px; }
}