/*
 * FS-PGRE — feuille commune des écrans de gestion et d'authentification
 * (socle commun FAREMAK SERVICES §2 et §5). Chargée APRÈS AdminLTE par
 * resources/views/partials/favicon.blade.php, sur toutes les pages.
 *
 * Boutons : mêmes coins, mêmes hauteurs, icône alignée sur le texte, focus
 * toujours visible, états désactivés lisibles, contraste AA des variantes
 * « outline » (le gris et le jaune d'origine descendaient sous 3:1).
 */

:root {
    --pgre-focus: #1d4ed8;
    --pgre-radius: .375rem;
}

/* --- Boutons ------------------------------------------------------------ */
.btn {
    border-radius: var(--pgre-radius);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4em;
    font-weight: 500;
    line-height: 1.5;
    white-space: nowrap;
}
.btn.btn-block { display: flex; }
.btn-group > .btn { border-radius: 0; }
.btn-group > .btn:first-child { border-top-left-radius: var(--pgre-radius); border-bottom-left-radius: var(--pgre-radius); }
.btn-group > .btn:last-child { border-top-right-radius: var(--pgre-radius); border-bottom-right-radius: var(--pgre-radius); }
.input-group > .input-group-append > .btn { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.input-group > .input-group-prepend > .btn { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.btn-flat { border-radius: var(--pgre-radius) !important; }
.btn > i, .btn > .fas, .btn > .far, .btn > .fab { line-height: 1; }
.btn-sm { min-height: calc(1.5em + .5rem + 2px); }
.btn-xs { padding: .125rem .4rem; font-size: .75rem; }
.btn-link { font-weight: 500; }

.btn:focus-visible, .btn.focus, a:focus-visible, .form-control:focus-visible, .custom-select:focus-visible {
    outline: 3px solid var(--pgre-focus) !important;
    outline-offset: 2px;
    box-shadow: none;
}

.btn:disabled, .btn.disabled { opacity: .55; cursor: not-allowed; }

/* Le bleu primaire de Bootstrap (#007bff) n'offre que 3,98:1 avec le blanc :
   un bleu plus profond (#0b5ed7, 5,6:1) pour les boutons, liens et contours. */
.btn-primary { background-color: #0b5ed7; border-color: #0a58ca; color: #fff; }
.btn-primary:hover, .btn-primary:focus { background-color: #0a53be; border-color: #0a4fb3; color: #fff; }
.btn-primary:not(:disabled):not(.disabled):active, .btn-primary:not(:disabled):not(.disabled).active { background-color: #094aa8; border-color: #08439a; }
.btn-outline-primary { color: #0b5ed7; border-color: #0b5ed7; }
.btn-outline-primary:hover, .btn-outline-primary:not(:disabled):not(.disabled).active { background-color: #0b5ed7; border-color: #0b5ed7; color: #fff; }
.btn-link, a, .text-primary { color: #0b5ed7; }
.btn-link:hover, a:hover { color: #084298; }
.page-link { color: #0b5ed7; }
.form-control:focus-visible { outline-offset: 0; }

/* Contraste AA des variantes « outline » sur fond blanc. */
.btn-outline-secondary { color: #495057; border-color: #6c757d; }
.btn-outline-warning { color: #8a5a00; border-color: #c98a00; }
.btn-outline-warning:hover { color: #1f2d3d; }
.btn-outline-info { color: #0b6b7a; border-color: #138496; }
.btn-outline-success { color: #1e7e34; border-color: #28a745; }
.btn-outline-light { color: #343a40; border-color: #ced4da; }
.btn-warning, .btn-warning:hover { color: #1f2d3d; }
.btn-info { background-color: #138496; border-color: #117a8b; }
.btn-success { background-color: #1e7e34; border-color: #1c7430; }
.btn-secondary { background-color: #5a6268; border-color: #545b62; }

/* Boutons des tableaux : compacts et alignés. */
.table td .btn + .btn, .table td .btn + form, .table td form + .btn { margin-left: .25rem; }
.table td .btn-sm { padding: .2rem .45rem; }

/* La pagination garde la couleur primaire au même contraste. */
.page-item.active .page-link { background-color: #0b5ed7; border-color: #0b5ed7; }

/* --- Pages d'authentification ------------------------------------------- */
.login-page, .register-page { background: #eef1f5; }
.login-box, .register-box { width: 400px; max-width: calc(100vw - 32px); }
.login-box .card, .register-box .card { border-radius: .6rem; overflow: hidden; }
.card-header .pgre-auth-title { font-size: 1.15rem; font-weight: 600; }
.login-card-body .login-box-msg, .register-card-body .login-box-msg { padding: 0 0 15px; }
.pgre-auth-divider { display: flex; align-items: center; gap: .75rem; margin: 1rem 0; color: #5f6b77; font-size: .85rem; }
.pgre-auth-divider::before, .pgre-auth-divider::after { content: ''; flex: 1; border-top: 1px solid #d5dbe1; }
.btn-google { background: #fff; color: #1f1f1f; border: 1px solid #747775; font-weight: 500; }
.btn-google:hover, .btn-google:focus { background: #f2f2f2; color: #1f1f1f; }
.pgre-password-toggle { min-width: 2.75rem; background: #fff; }
.pgre-auth-links { display: flex; flex-direction: column; gap: .35rem; font-size: .9rem; }
.pgre-auth-links a { color: #0b5ed7; }
.pgre-auth-note { margin: .75rem 0 0; color: #5f6b77; font-size: .8rem; }
.pgre-auth-steps { padding-left: 1.2rem; margin-bottom: 0; }
.pgre-auth-steps li { margin-bottom: .4rem; }
.hp-field { position: absolute !important; left: -10000px !important; width: 1px; height: 1px; overflow: hidden; }

/* --- Typographie : pile système (pas de police externe). --------------- */
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; }

/* --- Mode sombre AdminLTE (si activé) ------------------------------------ */
.dark-mode .btn-outline-secondary { color: #ced4da; border-color: #adb5bd; }
.dark-mode .btn-google { background: #131314; color: #e3e3e3; border-color: #8e918f; }
.dark-mode .pgre-password-toggle { background: #343a40; color: #fff; }

/* --- Écrans mobiles (1.11.0, socle commun § 8) ---------------------------
 * Testés à 360 × 640 et 390 × 844 : aucun défilement horizontal de page,
 * cibles tactiles de 44 px, barre d'onglets en bas (partials/mobile-tabbar),
 * tableaux des listes en cartes empilées avec libellés (pgre-stack-table),
 * marges des zones sûres (encoche, barre de geste) en env(safe-area-inset-*).
 */
.pgre-tabbar, .pgre-tabbar-spacer { display: none; }
.user-menu .user-body:not(:has([data-pgre-install]:not([hidden]))) { display: none; }
.pgre-push-current-badge { display: none; }
.pgre-push-current .pgre-push-current-badge { display: inline-block; }

@media (max-width: 767.98px) {
    body:has(.pgre-tabbar) { --pgre-tabbar-height: 56px; }

    .pgre-tabbar {
        display: flex;
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
        background: #fff; border-top: 1px solid #dee2e6; box-shadow: 0 -2px 10px rgba(0, 0, 0, .06);
        padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    }
    .pgre-tab {
        flex: 1 1 0; min-width: 0; min-height: 56px; padding: 6px 2px;
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
        color: #495057; font-size: .72rem; line-height: 1.1; text-decoration: none;
    }
    .pgre-tab i { font-size: 1.2rem; }
    .pgre-tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .pgre-tab:hover { color: #0b5ed7; text-decoration: none; }
    .pgre-tab.active { color: #0b5ed7; font-weight: 600; box-shadow: inset 0 3px 0 #0b5ed7; }
    .pgre-tabbar-spacer { display: block; height: calc(64px + env(safe-area-inset-bottom)); }
    .dark-mode .pgre-tabbar { background: #343a40; border-color: #4b545c; }
    .dark-mode .pgre-tab { color: #ced4da; }

    /* Aucune largeur imposée ne fait défiler la page entière. */
    /* « clip » et non « hidden » (1.12.0) : hidden faisait de ces blocs des
       conteneurs de défilement, et les pieds d'enregistrement « sticky »
       ne collaient plus. */
    .wrapper, .content-wrapper { overflow-x: clip; }
    .content-wrapper { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
    .main-header { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
    .main-sidebar { padding-bottom: env(safe-area-inset-bottom); }
    img, canvas, video, iframe { max-width: 100%; }

    /* En-têtes compacts. */
    .content-header { padding: .5rem .75rem .25rem; }
    .content-header h1 { font-size: 1.25rem; }
    .content-wrapper > .content { padding: 0 .5rem; }
    .pgre-toolbar { gap: .5rem; }
    .card-header { padding: .6rem .75rem; }
    .card-header .card-tools { float: none; margin: .5rem 0 0; display: flex; flex-wrap: wrap; gap: .25rem; }
    .card-body { padding: .9rem .75rem; }
    .info-box { min-height: 70px; padding: .4rem; }
    .info-box .info-box-icon { width: 52px; font-size: 1.4rem; }

    /* Cibles tactiles de 44 px ; 16 px dans les champs (iOS n'agrandit plus la page). */
    .btn, .page-link, .main-header .navbar-nav .nav-link { min-height: 44px; }
    .btn-sm, .btn-group-sm > .btn, .table td .btn-sm { min-width: 44px; min-height: 44px; }
    .form-control, .custom-select, select.form-control { min-height: 44px; font-size: 16px; }
    .custom-control-label::before, .custom-control-label::after { top: .15rem; }
    .pagination { flex-wrap: wrap; }

    /* Formulaires pleine largeur, enregistrement toujours à portée. */
    .form-inline { display: block; }
    .form-inline .form-control, .form-inline .custom-select, .form-inline select { display: block; width: 100% !important; max-width: none !important; margin-right: 0 !important; }
    .modal-dialog { margin: .5rem; max-width: none; }
    .modal-footer { position: sticky; bottom: 0; z-index: 2; background: #fff; padding-bottom: calc(.75rem + env(safe-area-inset-bottom)); }
    .card-footer:has([type="submit"]), form > .card-footer {
        position: sticky; bottom: calc(var(--pgre-tabbar-height, 0px) + env(safe-area-inset-bottom)); z-index: 2; background: #fff;
    }

    /* Listes : chaque ligne devient une carte, chaque cellule porte son libellé. */
    .table-responsive:has(> .pgre-stack-table) { overflow-x: visible; }
    .pgre-stack-table thead { display: none; }
    .pgre-stack-table, .pgre-stack-table tbody { display: block; width: 100%; }
    .pgre-stack-table tr { display: block; padding: .6rem .75rem; border-top: 1px solid #dee2e6; }
    .pgre-stack-table tbody tr:first-child { border-top: 0; }
    .pgre-stack-table td { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .2rem 0; border: 0; text-align: right; }
    .pgre-stack-table td[data-label]::before { content: attr(data-label); flex: 0 0 auto; max-width: 50%; color: #5f6b77; font-size: .85rem; text-align: left; }
    .pgre-stack-table td.pgre-stack-title { display: block; text-align: left; font-size: 1.02rem; padding-bottom: .35rem; }
    .pgre-stack-table td.pgre-stack-photo { float: right; padding: 0 0 0 .5rem; }
    .pgre-stack-table td.pgre-stack-actions { justify-content: flex-start; flex-wrap: wrap; gap: .35rem; padding-top: .5rem; white-space: normal; }
    .pgre-stack-table td.pgre-stack-actions .btn + .btn, .pgre-stack-table td.pgre-stack-actions .btn + form { margin-left: 0; }
    .pgre-stack-table td.pgre-stack-empty { display: block; text-align: center; }
    .dark-mode .pgre-stack-table td[data-label]::before { color: #adb5bd; }

    /* Les autres tableaux défilent dans leur cadre, pas la page. */
    .table-responsive { -webkit-overflow-scrolling: touch; }
}

@media print {
    .pgre-tabbar, .pgre-tabbar-spacer, [data-pgre-install], .pgre-pwa-banner, .pgre-pwa-ios { display: none !important; }
}
