/*
 * Responsive (tickets 14137 / 14138)
 * Chargé après style.css et custom.css, sur l'espace bénéficiaire, l'espace admin et les pages publiques.
 * Objectif : aucun débordement horizontal, de 320px au desktop.
 */

/* ===================== Garde-fous globaux ===================== */
html,
body {
    max-width: 100%;
}

body {
    overflow-x: hidden;
}

/* style.css passe body.app (flex en colonne) en flex-wrap: wrap : chaque ligne prend alors la largeur
   max-content de son contenu et un tableau large élargit toute la page. Une seule ligne suffit. */
.app,
.app.flex-row {
    flex-wrap: nowrap;
}

.app > .app-body {
    width: 100%;
    min-width: 0;
}

@supports (overflow-x: clip) {
    body {
        overflow-x: clip;
    }
}

.main img,
main.container img {
    max-width: 100%;
    height: auto;
}

.main pre,
.main code {
    white-space: pre-wrap;
    word-break: break-word;
}

/* Les contenus longs (emails, liens, identifiants) ne doivent pas élargir la page */
.main .card-body,
.main .alert,
.main p {
    overflow-wrap: break-word;
}

/* ===================== Sidebar + footer (layout connecté) ===================== */
/* La sidebar vit dans .wrap_sidebar_footer : c'est ce conteneur qui gère l'affichage,
   la sidebar CoreUI elle-même reste toujours en place à l'intérieur. */
.wrap_sidebar_footer {
    flex: 0 0 236px;
    width: 236px;
    margin-left: -236px;
}

.sidebar-lg-show .wrap_sidebar_footer {
    margin-left: 0;
}

.wrap_sidebar_footer .sidebar {
    margin-left: 0 !important;
    margin-right: 0 !important;
    width: 100%;
}

.wrap_sidebar_footer .sidebar .sidebar-nav {
    width: 100%;
}

@media (max-width: 991.98px) {
    /* En-tête collant de 60px (Bootstrap le remettait dans le flux, avec une marge CoreUI de 55px en trop) */
    .aside-menu-fixed .app-header {
        position: sticky;
        top: 0;
        z-index: 1020;
        height: 60px;
        min-height: 60px;
        margin-bottom: 0;
        box-shadow: 0 1px 0 #C1E8EB;
    }

    .aside-menu-fixed .app-header + .app-body {
        margin-top: 16px;
    }

    /* Sidebar hors-canvas : masquée par défaut, ouverte via le bouton burger (body.sidebar-show) */
    .wrap_sidebar_footer,
    .sidebar-lg-show .wrap_sidebar_footer {
        position: fixed;
        top: 60px;
        bottom: 0;
        left: 0;
        z-index: 1019;
        width: 300px;
        max-width: 85vw;
        margin-left: 0;
        flex-wrap: nowrap;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        transform: translateX(-100%);
        transition: transform .25s ease-in-out;
        box-shadow: none;
    }

    .sidebar-show .wrap_sidebar_footer {
        transform: translateX(0);
        box-shadow: 0 0 24px rgba(0, 0, 0, .2);
    }

    .wrap_sidebar_footer .sidebar {
        position: static;
        height: auto;
        flex: 1 0 auto;
    }

    .sidebar-pills {
        width: 100%;
    }

    .app-footer,
    .sidebar-show .app-footer {
        margin-left: 0;
    }

    /* Voile sombre derrière la sidebar ouverte (CoreUI ne le fait que < 576px) */
    .sidebar-show .app-body .main {
        position: relative;
    }

    .sidebar-show .app-body .main::before {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, .5);
        z-index: 1018;
    }
}

/* ===================== En-tête : icônes notifications / messages ===================== */
.app-header .navbar-nav .nav-item.header-icon {
    min-width: 0;
    margin: 0 10px;
    padding-right: 0 !important;
}

.app-header .navbar-nav .nav-item.header-icon > .nav-link {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
    font-size: 22px;
    line-height: 1;
}

.app-header .navbar-nav .nav-item.header-icon > .nav-link:hover,
.app-header .navbar-nav .nav-item.header-icon > .nav-link:focus {
    background-color: #EAF5FB;
}

.app-header .navbar-nav .nav-item.header-icon > .nav-link .badge {
    top: 2px;
    left: auto;
    right: 0;
    margin: 0;
    min-width: 18px;
    padding: 3px 5px;
    font-size: 10px;
    line-height: 1;
}

.app-header .navbar-nav .nav-item.header-icon + .nav-item.header-icon {
    margin-left: 14px;
}

/* Popup des notifications / messages */
.notifications-dropdown {
    padding-top: 0;
}

.notifications-dropdown .dropdown-header {
    position: sticky;
    top: 0;
    z-index: 1;
    background-color: #fff;
    border-bottom: 1px solid #C1E8EB;
    color: #244272;
    font-weight: 600;
}

@media (max-width: 991.98px) {
    .app-header .navbar-nav .nav-item.header-icon {
        margin: 0 4px;
    }

    .app-header .navbar-nav .nav-item.header-icon + .nav-item.header-icon {
        margin-left: 10px;
    }

    .app-header .navbar-nav > .nav-item.dropdown:last-child {
        padding-right: 8px !important;
    }

    /* Dans la navbar Bootstrap n'utilise pas Popper : on place le popup par rapport à l'écran */
    .app-header .navbar-nav .dropdown-menu.notifications-dropdown {
        position: fixed;
        top: 60px;
        left: 8px;
        right: 8px;
        width: auto;
        max-width: none;
        max-height: calc(100vh - 80px);
        margin: 0;
        text-align: left;
        box-shadow: 0 8px 24px rgba(0, 0, 0, .15);
    }

    .app-header .navbar-nav .dropdown-menu.notifications-dropdown .dropdown-item {
        padding: 12px 16px;
    }
}

/* ===================== En-tête public (accueil, connexion, inscription) ===================== */
@media (max-width: 991.98px) {
    .app.flex-row > .app-header {
        position: relative;
        height: auto;
        padding: 8px 0;
    }

    .app.flex-row > .app-header .navbar-brand {
        display: block;
        position: static;
        margin: 0;
    }

    .wrap-navbar-brand {
        flex-wrap: wrap;
        align-items: center;
        gap: 12px;
    }
}

@media (max-width: 575.98px) {
    .wrap-navbar-brand {
        justify-content: center;
    }

    .app-header.bg-light .wrap-navbar-brand .navbar-brand img {
        width: 140px;
    }

    .logos-partenaires-header {
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
    }

    .logos-partenaires-header img {
        width: auto;
        height: 40px;
    }
}

/* ===================== Tableaux ===================== */
.table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.dataTables_wrapper {
    max-width: 100%;
}

@media (max-width: 991.98px) {
    .table td,
    .table thead > tr > th,
    .table tfoot > tr > th,
    table.dataTable thead > tr > th,
    table.dataTable tfoot > tr > th {
        padding: 12px 14px;
        font-size: 14px;
    }

    .table td a,
    .table td .btn-default {
        padding: 5px 12px;
    }

    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        float: none;
        text-align: left;
    }

    .dataTables_wrapper .dataTables_filter label,
    .dataTables_wrapper .dataTables_filter input {
        width: 100%;
        margin-left: 0;
    }

    .dataTables_wrapper .dataTables_paginate .pagination {
        flex-wrap: wrap;
        justify-content: center;
        row-gap: 6px;
    }

    .page-link {
        width: 40px;
        height: 40px;
        padding: 8px 4px;
    }
}

/* ===================== Page historique des actions ===================== */
.history-page h1 {
    margin-bottom: 32px;
    font-size: 1.75rem;
}

.history-page .history-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px 24px;
    margin-bottom: 24px;
}

.history-page .history-toolbar .dt-buttons,
.history-page .history-toolbar .dataTables_length,
.history-page .history-toolbar .dataTables_filter {
    float: none;
    margin: 0;
    padding: 0;
}

.history-page .history-toolbar .dt-buttons {
    flex: 0 0 auto;
}

.history-page .history-toolbar .dataTables_filter {
    margin-left: auto;
}

.history-page .history-toolbar label {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 8px;
    margin: 0;
    font-size: 15px;
    white-space: nowrap;
}

.history-page .history-toolbar .dataTables_length,
.history-page .history-toolbar .dataTables_filter {
    text-align: left;
}

.history-page .history-toolbar .dataTables_length select {
    flex: 0 0 auto;
    width: auto !important;
    min-width: 80px;
    height: 44px;
    margin: 0;
}

.history-page .history-toolbar .dataTables_filter input {
    height: 44px !important;
    margin-left: 8px;
    border-radius: 8px;
}

.history-page .history-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 24px;
}

.history-page .history-footer .dataTables_info,
.history-page .history-footer .dataTables_paginate {
    float: none;
    padding-top: 0;
}

.history-page .table-responsive {
    border: 1px solid #C1E8EB;
    border-radius: 8px;
}

.history-page table.history-table {
    margin: 0 !important;
    border-collapse: collapse;
}

.history-page table.history-table thead > tr > th,
.history-page table.history-table tfoot > tr > th {
    padding: 14px 16px;
    font-size: 15px;
    /* Les en-têtes peuvent passer à la ligne : en nowrap, un tableau de 7 colonnes déborde de la colonne centrale. */
    white-space: normal;
}

.history-page table.history-table td {
    padding: 14px 16px;
    font-size: 14px;
    vertical-align: middle;
    border-bottom: 1px solid rgba(116, 204, 211, 0.30);
    overflow-wrap: break-word;
}

/* Un email (ou un identifiant dans un titre) n'a pas d'espace : sans coupure libre, il impose sa largeur au tableau.
   Réservé à ces colonnes : sur les colonnes courtes, le navigateur couperait les mots en plein milieu. */
.history-page table.history-table td.history-email,
.history-page table.history-table td.history-text {
    overflow-wrap: anywhere;
}

.history-page table.history-table td.history-actions {
    white-space: nowrap;
}

/* Desktop moyen (1280-1440px) : la colonne centrale fait ~620px, on resserre les cellules */
@media (max-width: 1439.98px) {
    .history-page table.history-table td,
    .history-page table.history-table tfoot > tr > th {
        padding: 12px 10px;
    }

    /* 26px à droite : place des flèches de tri DataTables */
    .history-page table.history-table thead > tr > th {
        padding: 12px 26px 12px 10px;
    }
}

.history-page table.history-table tbody tr:nth-of-type(2n) {
    background-color: #F6FAFF;
}

.history-page table.history-table tbody tr:hover {
    background-color: #EAF5FB;
}

.history-page table.history-table td.history-date {
    white-space: nowrap;
}

.history-page table.history-table td a {
    padding: 0;
}

@media (max-width: 767.98px) {
    .history-page h1 {
        font-size: 1.4rem;
        margin-bottom: 24px;
    }

    .history-page .history-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .history-page .history-toolbar .dataTables_filter {
        margin-left: 0;
    }

    .history-page .history-toolbar .dataTables_filter label {
        flex-wrap: wrap;
    }

    .history-page .history-toolbar .dataTables_filter input {
        flex: 1 1 100%;
        width: 100%;
        margin-left: 0;
    }

    .history-page .history-toolbar .dt-buttons .btn {
        width: 100%;
    }

    .history-page .history-footer {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }
}

/* ===================== Formulaires, boutons, composants ===================== */
@media (max-width: 767.98px) {
    .btn,
    .btn-primary,
    .btn-success,
    .btn-default {
        padding: 12px 20px;
        white-space: normal;
    }

    .bg-administration .card-body a.btn-light,
    .bg-params .card-body a.btn-light,
    .bg-folders .card-body a.btn-light,
    .bg-reporting .card-body a.btn-light {
        padding: 12px 24px;
    }

    .info-bull-infos .help-block,
    .info-bull-infos-admin .help-block-admin {
        width: 260px;
        max-width: calc(100vw - 48px);
    }

    .grid-item {
        width: 100%;
        margin-left: 0;
        margin-right: 0;
    }

    .ugp-form {
        padding: 12px;
    }

    .breadcrumb {
        margin: 10px 0 24px 0;
    }

    .h1, h1 {
        font-size: 1.6rem;
    }

    .h2, h2 {
        font-size: 1.4rem;
        margin-bottom: 20px;
    }

    /* Menus horizontaux du dossier (plan d'investissement, etc.) */
    .investment-plan-menus.navbar {
        flex-direction: column;
        align-items: stretch;
        padding: 0;
    }

    .investment-plan-menus.navbar a,
    .subnav,
    .subnav .subnavbtn {
        float: none;
        display: block;
        width: 100%;
        text-align: left;
    }

    .subnav-content {
        position: static;
    }

    .subnav-content a {
        float: none;
        display: block;
    }

    .quality-assurance-items ul {
        flex-wrap: wrap;
        padding-left: 0;
    }

    .box-actions,
    .card-body.box-title,
    .flex-div {
        flex-wrap: wrap;
        gap: 8px;
    }

    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .nav-tabs .nav-item {
        flex: 0 0 auto;
    }

    /* Le wizard d'étapes garde son propre comportement (pastilles) */
    .wizard .nav-tabs,
    .wizard-small .nav-tabs {
        overflow: visible;
    }

    .wizard .nav-tabs .nav-item,
    .wizard-small .nav-tabs .nav-item {
        flex: initial;
    }
}

@media (max-width: 575.98px) {
    .container-fluid {
        padding-left: 10px;
        padding-right: 10px;
    }

    .wizard {
        padding: 30px 0 50px 0;
    }

    span.round-tab {
        width: 36px;
        height: 36px;
        line-height: 34px;
        font-size: 16px;
        bottom: -15px;
    }

    .bg-administration .card-header,
    .bg-params .card-header,
    .bg-folders .card-header,
    .bg-reporting .card-header {
        font-size: 18px;
    }

    .modal-dialog {
        margin: 8px;
    }
}
