/*
 * Version mobile (socle commun FAREMAK, § 8) - feuille commune à tous les
 * gabarits, posée par resources/views/partials/pwa.blade.php.
 *
 * Bandeaux (mise à jour, aide d'installation iPhone), barre d'onglets de
 * l'espace de gestion sous 768 px, tableaux qui défilent dans leur cadre,
 * cibles tactiles de 44 px, marges des zones sûres (encoche, barre d'accueil).
 * Aucune règle n'agit au-dessus de 768 px, sauf les bandeaux.
 */

/* --- Bandeaux ------------------------------------------------------------- */

.pwa-banner {
    position: fixed;
    left: max(.75rem, env(safe-area-inset-left));
    right: max(.75rem, env(safe-area-inset-right));
    bottom: calc(.75rem + env(safe-area-inset-bottom));
    z-index: 1090;
    display: flex;
    align-items: center;
    gap: .75rem;
    max-width: 34rem;
    margin: 0 auto;
    padding: .75rem .75rem .75rem 1rem;
    border-radius: .75rem;
    background: #111827;
    color: #fff;
    box-shadow: 0 .75rem 2rem rgba(0, 0, 0, .3);
    font-size: .95rem;
    line-height: 1.4;
}

.pwa-banner-text { flex: 1 1 auto; }

.pwa-banner-action,
.pwa-banner-close {
    min-height: 44px;
    min-width: 44px;
    border: 0;
    border-radius: .5rem;
    font: inherit;
    cursor: pointer;
}

.pwa-banner-action {
    padding: .5rem 1rem;
    background: #fff;
    color: #111827;
    font-weight: 600;
}

.pwa-banner-close {
    background: transparent;
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
}

.pwa-banner-action:focus-visible,
.pwa-banner-close:focus-visible {
    outline: 3px solid #93c5fd;
    outline-offset: 2px;
}

/* Au-dessus de la barre d'onglets quand elle est là. */
body:has(.pgssu-tabbar) .pwa-banner {
    bottom: calc(4.25rem + env(safe-area-inset-bottom));
}

/* Installée : le bouton « Installer » n'a plus d'objet. */
@media (display-mode: standalone) {
    [data-pwa-install] { display: none !important; }
}

/* --- Tableaux : défilement dans leur cadre -------------------------------- */

.pwa-table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

.pwa-table-scroll > table { margin-bottom: 0; }

/* --- Barre d'onglets de l'espace de gestion ------------------------------- */

.pgssu-tabbar { display: none; }

@media (max-width: 767.98px) {
    .pgssu-tabbar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1035;
        display: flex;
        justify-content: space-around;
        align-items: stretch;
        padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
        background: var(--bs-body-bg, #fff);
        border-top: 1px solid var(--bs-border-color, rgba(0, 0, 0, .1));
        box-shadow: 0 -.25rem 1rem rgba(0, 0, 0, .08);
    }

    .pgssu-tabbar a,
    .pgssu-tabbar button {
        flex: 1 1 0;
        min-width: 0;
        min-height: 56px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: .1rem;
        padding: .35rem .15rem;
        border: 0;
        background: transparent;
        color: var(--bs-secondary-color, #6c757d);
        font-size: .7rem;
        line-height: 1.1;
        text-decoration: none;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .pgssu-tabbar i { font-size: 1.3rem; line-height: 1; }

    .pgssu-tabbar .active,
    .pgssu-tabbar a[aria-current="page"] {
        color: var(--pgssu-primary, var(--bs-primary));
        font-weight: 600;
    }

    .pgssu-tabbar a:focus-visible,
    .pgssu-tabbar button:focus-visible {
        outline: 3px solid var(--pgssu-primary, var(--bs-primary));
        outline-offset: -3px;
    }

    /* Place réservée sous le contenu et le pied de page. */
    body:has(.pgssu-tabbar) .app-wrapper {
        padding-bottom: calc(56px + env(safe-area-inset-bottom));
    }

    /* La barre latérale ouverte passe au-dessus de la barre d'onglets. */
    body.sidebar-open .app-sidebar { z-index: 1040; }

    /* --- Espace de gestion : en-têtes compacts, zones sûres ------------- */

    .app-header {
        padding-top: env(safe-area-inset-top);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }

    .app-content-header { padding-top: .5rem; padding-bottom: .25rem; }
    .app-content-header h1,
    .app-content-header .h1 { font-size: 1.25rem; }
    .app-content-header .breadcrumb { display: none; }

    .app-content,
    .app-content-header,
    .app-footer {
        padding-left: max(.5rem, env(safe-area-inset-left));
        padding-right: max(.5rem, env(safe-area-inset-right));
    }

    .app-content .container-fluid,
    .app-content-header .container-fluid { padding-left: .25rem; padding-right: .25rem; }

    .app-content .card-body { padding: .85rem; }

    /* Barres d'outils et filtres : ils passent à la ligne. */
    .app-content-header .d-flex:not(.flex-nowrap),
    .app-content .card-header.d-flex:not(.flex-nowrap),
    .app-content .card-header > .d-flex:not(.flex-nowrap),
    .app-content form.d-flex:not(.flex-nowrap),
    .app-content .card-tools { flex-wrap: wrap; gap: .5rem; }
    .app-content .btn-toolbar,
    .app-content .btn-group:not(.btn-group-sm) { flex-wrap: wrap; }

    /* Formulaires pleine largeur, champs lisibles sans zoom (iOS : 16 px). */
    .app-content .form-control,
    .app-content .form-select { width: 100%; max-width: 100%; font-size: 16px; }
    .app-content .input-group { flex-wrap: nowrap; }
    .app-content form .row > [class*="col-"] { flex: 0 0 100%; max-width: 100%; }
    .app-content form .row > [class*="col-6"],
    .app-content form .row > .col-auto { flex: 1 1 auto; max-width: none; }

    /* Le bouton d'enregistrement reste sous le pouce. */
    .app-content form .card-footer:last-child {
        position: sticky;
        bottom: calc(56px + env(safe-area-inset-bottom));
        z-index: 2;
        background: var(--bs-body-bg, #fff);
        box-shadow: 0 -.25rem .75rem rgba(0, 0, 0, .06);
    }

    /* Tableaux : texte serré, colonnes d'actions sur une ligne. */
    .app-content .table { font-size: .875rem; }
    .app-content .table td,
    .app-content .table th { padding: .45rem .5rem; }
    .app-content .table td.text-end,
    .app-content .table td:last-child { white-space: nowrap; }

    /* Aucune page ne déborde horizontalement. */
    .app-main,
    .app-content { overflow-x: clip; }
    .app-content img { max-width: 100%; height: auto; }
}

/* Cibles tactiles de 44 px au moins sur les écrans au doigt. */
@media (pointer: coarse) {
    .btn,
    .page-link,
    .nav-link,
    .dropdown-item,
    .form-select,
    .form-control:not(textarea) {
        min-height: 44px;
    }

    .btn.btn-sm,
    .btn-group-sm > .btn {
        min-height: 44px;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .form-check-input { width: 1.35em; height: 1.35em; }
}

/* Menu du compte : la case du bouton « Installer » disparaît avec lui. */
.user-menu .user-body:has(> [data-pwa-install][hidden]) { display: none; }
