/**
 * MOBILE HEADER & PAGE LAYOUT FIXES
 * Corrections pour les problèmes de dropdown, padding, boutons et layout
 * Date: 30 Novembre 2025
 */

/* ============================================
   1. FIX DROPDOWN PROFIL SUR MOBILE
   ============================================ */
@media (max-width: 991.98px) {
    
    /* Force Bootstrap dropdown à fonctionner sur mobile */
    .header-link.dropdown-toggle {
        cursor: pointer !important;
        pointer-events: auto !important;
        position: relative !important;
        z-index: 1042 !important;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1) !important;
    }
    
    /* Assurer que le dropdown toggle est cliquable */
    .header-element {
        position: relative !important;
    }
    
    /* Dropdown menu profil - NE PAS FORCER display:none CAR BOOTSTRAP GÈRE DÉJÀ */
    .header-profile-dropdown,
    .dropdown-menu {
        position: absolute !important;
        top: 100% !important;
        right: 0 !important;
        left: auto !important;
        margin-top: 0.5rem !important;
        min-width: 280px !important;
        max-width: 90vw !important;
        z-index: 1050 !important;
        /* NE PAS mettre display: none ici - Bootstrap le gère */
        background: #fff !important;
        border: 1px solid rgba(0, 0, 0, 0.15) !important;
        border-radius: 0.5rem !important;
        box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;
    }
    
    /* Améliorer l'apparence quand visible */
    .header-profile-dropdown.show,
    .dropdown-menu.show {
        display: block !important;
        animation: dropdownSlideIn 0.2s ease-out !important;
        opacity: 1 !important;
        visibility: visible !important;
    }
    
    @keyframes dropdownSlideIn {
        from {
            opacity: 0;
            transform: translateY(-10px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
    
    /* Notifications et messages dropdown - LAISSER BOOTSTRAP GÉRER display */
    .main-header-dropdown {
        position: absolute !important;
        z-index: 1050 !important;
        /* Bootstrap gère display:none par défaut */
        background: #fff !important;
        border: 1px solid rgba(0, 0, 0, 0.15) !important;
        border-radius: 0.5rem !important;
        box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;
    }
    
    .main-header-dropdown.show {
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
    }
    
    /* Backdrop pour dropdowns */
    .dropdown-backdrop {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        background: rgba(0, 0, 0, 0.3) !important;
        z-index: 1045 !important;
        opacity: 0 !important;
        visibility: hidden !important;
        transition: opacity 0.2s ease, visibility 0.2s ease !important;
    }
    
    .dropdown-backdrop.show {
        opacity: 1 !important;
        visibility: visible !important;
    }
    
    /* Items du dropdown - bien visibles */
    .dropdown-menu .dropdown-item {
        padding: 0.75rem 1rem !important;
        font-size: 0.9rem !important;
        color: #333 !important;
        display: flex !important;
        align-items: center !important;
        text-decoration: none !important;
        transition: background-color 0.15s ease !important;
    }
    
    .dropdown-menu .dropdown-item:hover,
    .dropdown-menu .dropdown-item:active {
        background-color: #f8f9fa !important;
        color: #0891b2 !important;
    }
    
    .dropdown-menu .dropdown-header {
        padding: 0.75rem 1rem !important;
        font-size: 0.85rem !important;
        border-bottom: 1px solid #e9ecef !important;
    }
    
    /* Icône flèche dropdown */
    .dropdown-toggle::after {
        display: inline-block !important;
        margin-left: 0.255em !important;
        vertical-align: 0.255em !important;
        content: "" !important;
        border-top: 0.3em solid !important;
        border-right: 0.3em solid transparent !important;
        border-bottom: 0 !important;
        border-left: 0.3em solid transparent !important;
    }
}

/* ============================================
   2. RÉDUIRE LE PADDING ENTRE HEADER ET CONTENU
   ============================================ */
@media (max-width: 991.98px) {
    
    /* Réduire padding top du main content */
    .main-content {
        padding-top: 70px !important; /* Au lieu de calc(var(--header-height-mobile) + 15px) */
    }
    
    /* Réduire padding du container-fluid */
    .main-content .container-fluid {
        padding-top: 0.5rem !important; /* Au lieu de valeur par défaut */
        padding-bottom: 0.5rem !important;
    }
    
    /* Page header plus compact */
    .page-header-breadcrumb {
        margin-top: 0.75rem !important;
        margin-bottom: 0.75rem !important;
        padding: 0 !important;
    }
    
    .my-4 {
        margin-top: 0.75rem !important;
        margin-bottom: 0.75rem !important;
    }
}

/* ============================================
   3. FIX BOUTONS TRANSPARENTS (COULEUR BLEUE)
   ============================================ */

/* Boutons primary-light - Rendre plus visibles */
.btn-primary-light,
.btn-outline-primary {
    background: #0891b2 !important;
    background-color: #0891b2 !important;
    border: 2px solid #0891b2 !important;
    border-color: #0891b2 !important;
    color: #ffffff !important;
    opacity: 1 !important;
}

.btn-primary-light:hover,
.btn-outline-primary:hover {
    background: #0e7490 !important;
    background-color: #0e7490 !important;
    border-color: #0e7490 !important;
    color: #ffffff !important;
}

.btn-primary-light:active,
.btn-outline-primary:active,
.btn-primary-light:focus,
.btn-outline-primary:focus {
    background: #155e75 !important;
    background-color: #155e75 !important;
    border-color: #155e75 !important;
    color: #ffffff !important;
    box-shadow: 0 0 0 0.2rem rgba(8, 145, 178, 0.25) !important;
}

/* Boutons secondary-light - Rendre plus visibles */
.btn-secondary-light,
.btn-outline-secondary {
    background: #64748b !important;
    background-color: #64748b !important;
    border: 2px solid #64748b !important;
    border-color: #64748b !important;
    color: #ffffff !important;
    opacity: 1 !important;
}

.btn-secondary-light:hover,
.btn-outline-secondary:hover {
    background: #475569 !important;
    background-color: #475569 !important;
    border-color: #475569 !important;
    color: #ffffff !important;
}

/* Boutons info, warning, success, danger - Rendre plus visibles */
.btn-info-light {
    background: #06b6d4 !important;
    border-color: #06b6d4 !important;
    color: #ffffff !important;
}

.btn-warning-light {
    background: #f59e0b !important;
    border-color: #f59e0b !important;
    color: #ffffff !important;
}

.btn-success-light {
    background: #10b981 !important;
    border-color: #10b981 !important;
    color: #ffffff !important;
}

.btn-danger-light {
    background: #ef4444 !important;
    border-color: #ef4444 !important;
    color: #ffffff !important;
}

/* ============================================
   4. LAYOUT PAGE PROFIL/CV - 2 COLONNES SUR MOBILE
   ============================================ */
@media (max-width: 767.98px) {
    
    /* Page header - Layout 2 colonnes */
    .page-header-breadcrumb {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 0.5rem !important;
    }
    
    /* Titre à gauche */
    .page-header-breadcrumb > div:first-child {
        flex: 1 !important;
        min-width: 0 !important;
    }
    
    .page-title {
        font-size: 1.1rem !important;
        margin-bottom: 0.25rem !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    
    /* Breadcrumb plus compact */
    .breadcrumb {
        font-size: 0.7rem !important;
        margin-bottom: 0 !important;
    }
    
    .breadcrumb-item {
        padding: 0 !important;
    }
    
    /* Boutons à droite */
    .pageheader-btn,
    .ms-auto.pageheader-btn {
        margin-left: auto !important;
        margin-top: 0 !important;
        flex-shrink: 0 !important;
    }
    
    .pageheader-btn .btn {
        font-size: 0.8rem !important;
        padding: 0.5rem 0.75rem !important;
        white-space: nowrap !important;
    }
    
    /* Si plusieurs boutons, les empiler verticalement */
    .pageheader-btn {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.25rem !important;
        align-items: flex-end !important;
    }
}

/* Entre 768px et 991px - Layout encore optimisé */
@media (min-width: 768px) and (max-width: 991.98px) {
    
    .page-header-breadcrumb {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
    }
    
    .page-title {
        font-size: 1.3rem !important;
    }
    
    .pageheader-btn .btn {
        font-size: 0.9rem !important;
        padding: 0.6rem 1rem !important;
    }
}

/* ============================================
   5. HEADER SPÉCIFIQUE CV BUILDER - 2 COLONNES
   ============================================ */
@media (max-width: 767.98px) {
    
    /* Layout du header CV */
    .d-flex.justify-content-between.align-items-center {
        display: flex !important;
        flex-direction: row !important;
        align-items: flex-start !important;
        justify-content: space-between !important;
        gap: 0.5rem !important;
    }
    
    /* Titre CV à gauche */
    .d-flex.justify-content-between.align-items-center > div:first-child {
        flex: 1 !important;
        min-width: 0 !important;
    }
    
    .d-flex.justify-content-between.align-items-center h4 {
        font-size: 1rem !important;
        margin-bottom: 0.25rem !important;
    }
    
    .d-flex.justify-content-between.align-items-center p {
        font-size: 0.75rem !important;
        margin-bottom: 0 !important;
    }
    
    /* Bouton Retour à droite */
    .d-flex.justify-content-between.align-items-center .btn {
        flex-shrink: 0 !important;
        font-size: 0.75rem !important;
        padding: 0.4rem 0.7rem !important;
        white-space: nowrap !important;
    }
}

/* ============================================
   6. UNIFORMISER LES TAILLES DE BOUTONS
   ============================================ */

/* Tailles de boutons standards */
.btn {
    font-size: 0.875rem !important;
    padding: 0.5rem 1rem !important;
    font-weight: 500 !important;
    border-radius: 0.375rem !important;
}

.btn-sm {
    font-size: 0.75rem !important;
    padding: 0.375rem 0.75rem !important;
}

.btn-lg {
    font-size: 1rem !important;
    padding: 0.75rem 1.5rem !important;
}

/* Sur mobile, boutons légèrement plus petits */
@media (max-width: 767.98px) {
    .btn {
        font-size: 0.8rem !important;
        padding: 0.45rem 0.85rem !important;
    }
    
    .btn-sm {
        font-size: 0.7rem !important;
        padding: 0.35rem 0.65rem !important;
    }
    
    .btn-lg {
        font-size: 0.9rem !important;
        padding: 0.6rem 1.2rem !important;
    }
    
    /* Boutons dans les cards */
    .card-header .btn {
        font-size: 0.75rem !important;
        padding: 0.4rem 0.7rem !important;
    }
}

/* Icons dans les boutons - Taille uniforme */
.btn i {
    font-size: 1em !important;
    vertical-align: middle !important;
}

.btn .bx,
.btn .ri-,
.btn .ti {
    margin-right: 0.25rem !important;
}

/* ============================================
   7. FIX LAYOUT DASHBOARD CANDIDATURES
   ============================================ */
@media (max-width: 767.98px) {
    
    /* Header candidatures - texte sur une ligne */
    .card-header.justify-content-between {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        flex-wrap: nowrap !important;
    }
    
    .card-header .card-title {
        font-size: 0.9rem !important;
        white-space: nowrap !important;
        margin-right: 0.5rem !important;
        flex-shrink: 1 !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    
    .card-header .btn {
        flex-shrink: 0 !important;
        font-size: 0.75rem !important;
        padding: 0.35rem 0.65rem !important;
    }
}

/* ============================================
   8. ESPACEMENT GÉNÉRAL MOBILE
   ============================================ */
@media (max-width: 767.98px) {
    
    /* Cards - Espacement réduit */
    .card {
        margin-bottom: 0.75rem !important;
    }
    
    .card-body {
        padding: 0.75rem !important;
    }
    
    .card-header {
        padding: 0.75rem !important;
    }
    
    /* Rows - Espacement réduit */
    .row {
        margin-bottom: 0.75rem !important;
    }
    
    /* Colonnes - Padding réduit */
    [class*="col-"] {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }
    
    /* Container fluid - Padding réduit */
    .container-fluid {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }
}

/* ============================================
   9. FIX BOUTONS DANS LES MODALS
   ============================================ */
.modal-footer .btn {
    min-width: 80px !important;
}

@media (max-width: 767.98px) {
    .modal-footer .btn {
        font-size: 0.8rem !important;
        padding: 0.5rem 1rem !important;
        min-width: 70px !important;
    }
}

/* ============================================
   10. FIX TOUCHES ACTIVES (DROPDOWN)
   ============================================ */

/* S'assurer que les dropdowns fonctionnent au touch */
@media (max-width: 991.98px) {
    .header-link {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1) !important;
        cursor: pointer !important;
    }
    
    .dropdown-toggle::after {
        display: inline-block !important;
        margin-left: 0.255em !important;
        vertical-align: 0.255em !important;
        content: "" !important;
        border-top: 0.3em solid !important;
        border-right: 0.3em solid transparent !important;
        border-bottom: 0 !important;
        border-left: 0.3em solid transparent !important;
    }
    
    /* Forcer l'affichage du dropdown au clic */
    .show > .dropdown-menu {
        display: block !important;
    }
}

/* ============================================
   11. FIX ALIGNEMENT TEXTES PAGES
   ============================================ */
@media (max-width: 767.98px) {
    
    /* Titres de section */
    h1, h2, h3, h4, h5, h6 {
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
    }
    
    .page-title {
        line-height: 1.2 !important;
    }
    
    /* Breadcrumb - Peut passer à la ligne si nécessaire */
    .breadcrumb {
        flex-wrap: wrap !important;
    }
}

/* ============================================
   12. FIX Z-INDEX POUR ÉVITER CONFLITS
   ============================================ */
@media (max-width: 991.98px) {
    .app-header {
        z-index: 1041 !important;
    }
    
    .app-sidebar {
        z-index: 1050 !important;
    }
    
    .mobile-sidebar-overlay {
        z-index: 1049 !important;
    }
    
    .dropdown-menu {
        z-index: 1051 !important;
    }
    
    .modal {
        z-index: 1055 !important;
    }
    
    .modal-backdrop {
        z-index: 1054 !important;
    }
}

/* ============================================
   13. AMÉLIORATION LISIBILITÉ TEXTES
   ============================================ */
@media (max-width: 767.98px) {
    
    /* Textes des cards */
    .card-body p,
    .card-body span,
    .card-body div {
        font-size: 0.85rem !important;
        line-height: 1.4 !important;
    }
    
    /* Textes muted */
    .text-muted {
        font-size: 0.75rem !important;
    }
    
    /* Badges */
    .badge {
        font-size: 0.7rem !important;
        padding: 0.25em 0.5em !important;
    }
}

/* ============================================
   14. FIX RESPONSIVE IMAGES
   ============================================ */
@media (max-width: 767.98px) {
    img {
        max-width: 100% !important;
        height: auto !important;
    }
    
    .avatar {
        width: 2rem !important;
        height: 2rem !important;
    }
    
    .avatar-sm {
        width: 1.75rem !important;
        height: 1.75rem !important;
    }
    
    .avatar-xl {
        width: 3rem !important;
        height: 3rem !important;
    }
}

/* ============================================
   15. FIX POUR LES FORMULAIRES
   ============================================ */
@media (max-width: 767.98px) {
    .form-control,
    .form-select {
        font-size: 0.9rem !important;
        padding: 0.5rem 0.75rem !important;
    }
    
    .form-label {
        font-size: 0.85rem !important;
        margin-bottom: 0.25rem !important;
    }
}
